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.
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).Supported smart sockets
Theoretically, any tasmota compatible, ESP8266 based WiFi socket is suitable. Depending on the type, the software from our repository has to be adapted a bit.
To turn a smart socket into a 2log Switch, the 2log Switch firmware must be flashed to the device. For this purpose a USB Serial Adapter (FTDI) is required.
Shelly Plug S
Officially supported is currently the model “Shelly Plug S”. By the way, this is also one of the few models for which correct CE certificates could be provided.
To flash a Shelly Plug S socket you have to do the following steps:
- Download the firmware binaries from our CI Pipeline
- Open the housing of the socket by loosening the screw on the back.
- Connect the serial programmer (This blogpost shows how to connect the pins)
- 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.