Arduino open source firmware for Shelly devices
GPL-3.0 License
This firmware is an open-source replacement for the stock firmware of the Shelly Plug S.
Features:
Roadmap:
This smart plug is particularly interesting because thanks to its factory firmware it can be reflashed wirelessly without any soldering or wiring. Just use this precompiled firmware and you'll be up and running in minutes.
No soldering or wiring is needed for this! The following procedure is completely wireless and uses a precompiled binary.
Warning This procedure was tested, but should something go wrong in the OTA process there's the possibility that your device may become bricked (recovery will require the physical procedure described below). Do this at your own risk.
Plug the Shelly device into a power socket.
Connect your smartphone or PC to the "shellyplug-s-XXXXXX" WiFi network
Open http://192.168.33.1/ in a web browser to access the Shelly configuration interface, and navigate to the "Internet & Security" section.
Configure your WiFi credentials in the "WIFI MODE - CLIENT" and save.
After the Shelly device reboots you'll need to check that it's reachable on your main WiFi network. This time, since it was assigned an IP address dynamicaly, you'll need to figure out that address using one of these methods:
arp -a
if you're on Mac or Linux to see a list of devices in your network.After you checked that the Shelly device connected successfully to your WiFi network and that you know its hostname/IP, it's time to launch the actual OTA. Put the Shelly hostname/IP in this long URL and open it with your web browser:
http://shellyplug-s-XXXXXX/ota?url=http://arduino-precompiled-sketches.s3.amazonaws.com/Shelly_Plug_S.mgos.zip
The response page should contain "status":"updating"
. The red LED will blink for a while, then will turn off. Be patient, because your Shelly is rebooting twice.
Now that you have installed this Arduino firmware on your Shelly device, connect to the "Arduino-XX:XX:XX:XX:XX" WiFi network exposed by the new firmware.
Open http://192.168.4.1/ with your browser and enter the "Configure WiFi" page.
Configure WiFi and cloud credentials, then save. If you don't have the cloud credentials, see this tutorial first.
The device will restart and it should be magically connected to Arduino Cloud!
Configure Arduino Cloud by adding the following variables:
relay
(type: string)active_power
(type: float)voltage
(type: float)current
(type: float)Now create a dashboard and have fun!
During normal operation, the red LED reflects the relay status (on/off), while the blue LED reflects the cloud connection status (blinking: connecting; steady: connected).
If the device fails to connect to WiFi on boot, it will switch to access point mode exposing the configuration web portal. In order to activate such mode manually, keep the button pressed for at least 5 seconds when powering the device.
This firmware provides a remote console feature that lets you do some advanced tasks through Arduino Cloud, such as calibration and OTA.
To use it, follow this steps:
cmd
(type: string).cmd
variable.That's it! Now you can communicate with your Shelly. Here's an overview of the available commands:
version
- Get a build timestamp of the firmware running on your Shelly.ota <URL>
- Retrieve a remote firmware and install it on the Shelly (replace "<URL>" with the actual URL). Note that only HTTP addresses (no HTTPS) are supported.
ota http://myserver/myfirmware.bin
calibrate <P> <V>
Request automatic power monitoring calibration based on the provided values for active power (P, expressed in Watt) and voltage (V, expressed in Volts).
calibrate 60 220
get_power_multiplier
, get_voltage_multiplier
, get_current_multiplier
- Get the current calibration parameters.set_power_multiplier <X>
, set_voltage_multiplier <X>
, set_current_multiplier <X>
- Set the calibration parameters manually.reset_power_monitoring
- Restore the default calibration parameters.How does this wireless reflashing work?
We're providing two precompiled binaries:
The intermediate firmware is based on the mgos-to-tasmota tool, whose only job is to take control of the Shelly and download the final firmware (whose sources are locaetd in this repo). We need such intermediate firmware because in order to be accepted by the Shelly OTA it's written using the same framework used by the Shelly firmware (MongooseOS).
If you want to recompile the intermediate firmware yourself in order to make it point to a different URL for the final firmware, just clone the mgos-to-tasmota repo and change the mos.yml file with the desired final URL, then compile it with the mos
tool.
How can I compile this firmware?
If you want to make changes or compile it yourself, just compile it as follows:
arduino-cli compile --profile generic -e
If you use the above OTA flashing procedure you don't need to compile this firmware youself as you can rely on the precompiled binary!
How can I flash this firmware to the Shelly using the USB-serial procedure?
This method is mostly useful when testing firmware customizations.
GND
→ GND
GPIO0
→ GND
3.3V
→ VCC
RXD
→ TXD
TXD
→ RXD
GPIO0
from GND
and reboot the device.How to restore the original Shelly firmware?
Get the original firmware from this site.
Convert it to a full image using this tool.
Connect your Shelly device via USB and upload it using:
arduino-cli upload -i fw.bin --fqbn esp8266:esp8266:generic -p /dev/cu.usbserial-AQ027S3I
This firmware was written by Alessandro Ranellucci and is licensed under the terms of the GNU General Public License v3 or later.
It is based on the following components: