Build a 2log Switch
The 2log Switch is a smart wireless socket that can switch power and measure energy consumption. It communicates via WiFi with the 2log server and ensures that only authorized users can use the machines. By measuring the power consumption, the system knows exactly how long the machine has been in use.
Shelly Plus Plug S and Shelly PLus 1 PM (recommended)
The new generation of Shelly devices comes with Shelly OS, which is fortunately very open and comes with well-documented APIs. In addition, the Shelly smart meters already support outgoing websocket connections out of the box, making them perfect for use with 2log.
Before you start, make sure that your 2log instance is up to date. The endpoint for Shelly sockets waits on port 4712 for incoming websocket connections. If you are using Docker, make sure that docker-compose.yaml is configured accordingly.
- Log in to the web portal of the Shelly device and carry out a firmware update.
- Connect the Shelly socket to the Wifi network via which the 2log server is accessible.
- Configure an “outbound websocket” connection. Enter the IP address of the 2log server. Do not forget to enter the port 4712. The address then looks something like this:
ws://<2log IP>:4712
. - Log in to the 2log admin interface, go to the device explorer in the settings area.
- The switch should appear here in the “Unregistered Devices” area. Make a note of the short ID. You will need it later to assign the switch to a machine.
- Go to the settings of your 2log resource. Click on “Set up now” for the switch. You can answer the question as to whether the device is already connected to the network with “Yes”. Now use the short ID to assign the new Shelly to the machine.
- Now configure the switch via the web interface so that it is not publicly accessible. For example, by assigning a password and deactivating the public access point if necessary.
Shelly Plug S and Shelly 1PM (deprecated)
To use an Shelly Plug S or a Shelly 1 PM (the older models, not the PLUS version!) as a 2log switch, the 2log firmware must be flashed manually. This process is a little fiddly, not entirely trivial and fortunately no longer necessary thanks to the new generation of Shelly devices. However, if you have this hardware available and are not afraid of the effort, you can get started right away. The only thing you need is an FTDI / Serial Programmer and possibly a soldering iron with a fine tip.
Danger!
If your device connects to mains electricity (AC power) there is danger of electrocution if not installed properly. If you don’t know how to install it, please call an electrician (Beware: certain countries prohibit installation without a licensed electrician present). Remember: SAFETY FIRST. It is not worth the risk to yourself, your family and your home if you don’t know exactly what you are doing. Never tinker or try to flash a device using the serial programming interface while it is connected to MAINS ELECTRICITY (AC power).Flashing the Firmware
Officially supported are currently the models “Shelly Plug S” and “Shelly 1PM”. Regarding the 1PM, you have to be careful not to accidentally buy the plus version with the square case. We need the version with the ESP8266 and the round case.
To flash a Shelly Plug S socket you have to do the following steps:
- Download the firmware binaries from our CI Pipeline
- Connect the serial programmer
- PlugS:
- Open the housing of the socket by loosening the screw on the back.
- Faulty wrote a blogpost that shows how to connect the pins: https://faulty.cloud/blog/shelly-plug-s-pinout
- 1PM:
- Remove the rubber cap
- Connect the Serial Programmer as described in the manual.
- PlugS:
- Flash the firmware with esptool
esptool.py \ --chip esp8266 \ --port /dev/tty.usbserial-UUT1 \ --baud 230400 \ --before default_reset \ --after hard_reset write_flash \ -z \ --flash_mode dio \ --flash_freq 40m \ --flash_size 4MB \ 0x0 build/bootloader/bootloader.bin \ 0x10000 build/2log-switch.bin \ 0x8000 build/partitions-OTA-2MB.bin
Connect the Switch with your 2log instance
You can set up the devices either with the 2log app or manually with a Linux Shell. Using the app is straight forward and will be explained in the corresponding chapters.
Provisioning without mobile app
Here we explain how to provision a Switch via a direct SSH connection. You only need a command line for the manual setup.
You can also use this protocol to create your own program code for provisioning.
-
Press the button of the Switch for several seconds. Once the Dot is in pairing mode, it will start blinking slowly and open a WiFi hotspot.
-
Connect your laptop to the WiFi with the SSID
I'm a Switch
. -
Enter the following command into your linux console:
openssl s_client -connect 192.168.4.1:8443
After a few console outputs, a connection to the Switch should be established.
- Send the following JSON command to the device by typing it into the console and confirming with return:
{"cmd": "hi"}
The device will respond with something similar to
{
"cmd": "welcome",
"device": {
"sid": "I5O2",
"uuid": "3C:61:05:DE:8A:A4"
}
}
Write down the short id (sid) somewhere. You will need it later to assign the device. In the example here the device has the sid I502
- Now we can send the configuration to the device with the following JSON command
{
"cmd":"setconfig",
"ssid":"<YOUR_SSID>",
"pass":"<YOUR_PASSWORD>",
"extconfig":{
"server":"<YOUR_2LOG_SERVER>",
"testconfig":false
}
}
- The device will respond with
{ "cmd":"setconfig","status":1}
Which means that the device has received the data.
- The device will now reboot and try to connect to the server. The Switch will stop blinking and glow continuously once it is successfully connected to the 2log instance. Now you can assign a function to the Dot using the four-digit short ID.