Skip to content

Instantly share code, notes, and snippets.

@TheGroundZero
Created April 15, 2021 13:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheGroundZero/4ea90aa9788ac91c3193d6fbe03b23c3 to your computer and use it in GitHub Desktop.
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
# 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
@bartgrefte
Copy link

@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