This project describes a step-by-step procedure to set up a smart plug and control it remotely through an Arduino Cloud dashboard. This means turning it on and off, as well as collecting power monitoring data.
There are many options on the market. In this tutorial we're going to use a Shelly Plug S device because of:
- ESP8266 microcontroller, supported by Arduino Cloud
- good price and availability
- support for up to 2500W loads
- support for the wireless flashing procedure described in this tutorial, with no need for wiring or soldering
Of course these devices come with their original firmware (and cloud), but that's a bit limited and we really want to use Arduino Cloud to:
- Customize our dashboard, access it from web and IoT Remote mobile app
- Share the dashboard with other users
- Store historical data that can be downloaded at any time
- Control all our Arduino and non-Arduino devices from a single place
- Automate our smart plug by controlling it from other Arduino devices (using the device-to-device communication feature)
1. Create a free account in Arduino Cloud
2. Create a new device, selecting "Generic 8266 Module" as board type. You'll get a a Device ID and a Secret Key: copy-paste them somewhere. Follow this tutorial if you need guidance.
3. Create a new thing, and configure it with the following properties:
- relay (type: string)
- active_power (type: float)
- voltage (type: float)
- current (type: float)
4. Create a new dashboard and add widgets linked to these variables. You will want to use a switch widget for the relay property, and gauges or charts for the other ones.
1. Plug the Shelly device into a power socket.
2. Connect your smartphone or PC to the "shellyplug-s-XXXXXX" WiFi network. Note down the exact network name, as you'll use it later.
3. Open http://192.168.33.1/ in a web browser to access the Shelly configuration interface, and navigate to the "Internet & Security" section.
4. Configure your WiFi credentials in the "WIFI MODE - CLIENT" section and save.
5. After the Shelly device reboots you'll need to check that it's reachable on your main WiFi network and you can open its configuration interface again. This time, since it was assigned an IP address dynamically, you'll need to figure out that address using one of these methods:
- Try connecting to http://shellyplug-s-XXXXXX replacing this with the network name you saw in step 2.
- If it doesn't work, try to run the "arp -a" command in a shell if you're on Mac or Linux to see a list of devices in your network.
- As last resort, you can open your router interface to see the connected devices and their IP addresses.
6. 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
This will start the download of a precompiled version of the firmware. 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 while the firmware gets installed.
Step 3: configure the device1. Now that you have installed this Arduino firmware on your Shelly device, use your PC or laptop to connect to the "Arduino-XX:XX:XX:XX:XX" WiFi network exposed by the new firmware.
2. Open http://192.168.4.1/ with your browser and enter the "Configure WiFi" page.
3. Enter your WiFi and cloud credentials, then save.
The device will restart and it should be magically connected to Arduino Cloud!
The red LED reflects the relay status (on/off), while the blue LED reflects the cloud connection status (blinking: connecting; steady: connected).
Advanced controlFor power monitoring calibration or firmware updates, this firmware provides a remote console functionality:
See the GitHub repository for the source code of this firmware and more details.
Comments
Please log in or sign up to comment.