Created
April 15, 2021 13:14
-
-
Save TheGroundZero/4ea90aa9788ac91c3193d6fbe03b23c3 to your computer and use it in GitHub Desktop.
Simple loop using cURL to change the config of all Shellys in a network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See docs on HTTP API | |
# https://shelly-api-docs.shelly.cloud/#settings | |
# Linux / Mac | |
for i in {2..254}; do curl -m 1 http://192.168.1.$i/settings?<setting parameters>; done | |
# Windows | |
# Note: use %% instead of % when saving this in a BATCH script (.bat) | |
FOR /L %I IN (2,1,254) DO curl -m 1 http://192.168.1.%I/settings?<setting parameters> | |
# --- EXAMPLES --- | |
# -- Installing FW upgrade -- | |
# MQTT | |
# See https://shelly-api-docs.shelly.cloud/#common-mqtt-commands | |
Send `update_fw` to `shellies/command` | |
# HTTP API | |
# See https://shelly-api-docs.shelly.cloud/#ota | |
# Linux / Mac | |
for i in {2..254}; do curl -m 1 http://192.168.1.$i/ota?update=true; done | |
# Windows | |
FOR /L %I IN (2,1,254) DO curl -m 1 http://192.168.1.%I/ota?update=true | |
# -- Enabling CoIoT -- | |
# Linux/Mac | |
for i in {2..254}; do curl -m 1 http://192.168.1.$i/settings?coiot_enable=true&coiot_peer=192.168.x.x; done | |
# Windows in CMD (in a .bat use %% instead of %) | |
FOR /L %I IN (2,1,254) DO curl -m 1 http://192.168.1.%I/settings?coiot_enable=true&coiot_peer=192.168.x.x | |
# -- Disable MQTT update period -- | |
# Linux/Mac | |
for i in {2..254}; do curl -m 1 http://192.168.1.$i/settings?mqtt_update_period=0; done | |
# Windows in CMD (in a .bat use %% instead of %) | |
FOR /L %I IN (2,1,254) DO curl -m 1 http://192.168.1.%I/settings?mqtt_update_period=0 |
@TheGroundZero I know about the JSON-response, that part was obvious and is as easy as using
response = requests.get("http://IP-address/settings", timeout=0.500)
hostname = response.json()["device"]["hostname"]
but having to use _ instead of . for the configuring part (from Python) was not. But now that I know, I can continue with writing a script that will config future Shelly's with a single command :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Be wary of the difference between the response attributes and request parameteres.
A request to e.g.
http://192.168.x.x/settings
will return a JSON object containing e.g.So you can extract the key-value pairs
device.type
=SHSW-21
andsntp.server
=time.google.com
.To modify e.g. the SNTP server, you need to look at the HTTP Parameters section and send a GET request to
http://192.168.x.x/settings?sntp_server=my_timeserver.domain.tld