I’ve had a couple of the Sonoff Basic devices for quite some time. It’s fairly easy to solder some header pins onto these which makes flashing the firmware somewhat of a non event, but it’s still a bit of a pain.
The other thing I bought (again, some time ago, but a bit after the Sonoff Basic) is a Sonoff Touch. This is an in-wall light switch replacement, which means you can replace your existing light switches with something that you can control over WiFi. They actually look pretty nice, too.
#2 - most likely won't be able to get an internet connection directly wiring to Ethernet or wifi because requires login. You can get what is called a travel router which allows you to login the homepage of the college service and create a new wifi that utilizes the school internet (some schools frown on students setting up their own wifi router. MAC address is forbidden. For security reasons, your MAC address may be filtered and blocked. In this case you should remove it from the list of forbidden addresses. MAC address conflict. Turn off all other connected devices for this router and try again. DHCP Leasing Conditions. Disable DHCP or extend the DHCP lease if DHCP is enabled. In the text box above in middle of URL.need to enter Event name created i.e Applet event name. In our casse witch is placed in 'index.html' file is 'sonoffoff' and 'sonoffon'. You can first check if we are able to switch on and off the actual device/bulb by clicking 'Test it' button in above screen shot. Jun 19, 2017 The SSID will match the device type followed by a period and then some characters representing the devices MAC address. For example, the Sonoff TH would look like SonoffTH.3d8883d0f90f and the SmartLife H801 would look like esprgbw.5d7d404fe294.
I wasn’t so keen on mucking around with soldering them, partly because you need to use a 90° header. However, the other day I learned that there is a way to control them (and the Basic) without having to connect to the iTead servers.
When the devices are unable to connect to a remote server (yes, they basically keep a connection to this remote server open 100% of the time, which was part of the rationalé behind flashing the firmware), the go into LAN mode.
When they are in LAN mode, they will respond to WebSocket connections over port 8081, making it easy to control them directly.
In my router (running LEDE), I can set a specific range of IP addresses to be unable to connect out to the internet, and then all I need to do is make sure the devices get one of these IP addresses.
The configuration process is something like:
Touch the switch toggle for 7 seconds. This puts it into pairing mode, where it acts as an Access Point (AP).
Connect to the new WiFi network ITEAD_100000xxxxxx.
Get the MAC address of the device at 10.10.7.1
Tell the router to reserve an IP address in the required range for this MAC address.
POST data to the device (10.10.7.1) with a JSON object that contains the WiFi credentials. This will trigger the device to disconnect the AP, and connect to the WiFi network. It’s also possible at this time to tell it to connect to a different server (which I may do instead at some point, but this method was quicker for now).
Connected to your WiFi, send JSON messages over a WebSocket connection to the device (at it’s fixed IP address).
I’m hoping at some point to automate this, but it’s meaningless to do so until I get a bunch more devices.
So, on to the software.
Ultimately, the plan is to control these devices using HomeKit. I started writing a direct bridge (similar to my MQTT HomeKit bridge), but then decided it would be simpler to just bridge to MQTT - I could then use the correct topic names and values to allow it to interact with that MQTT HomeKit bridge.
How To Get The Mac Address For Sonoff X
There’s really only two things to do:
Connect to the Sonoff device, and wait for events from there as to the switch state. Push these changes to our MQTT topic.
Connect to the MQTT broker, and subscribe to our topic. When we get events, push these to the Sonoff device.
I attempted to play around with asyncio to get this to work, but I can’t remember enough about how to use it, so I went for an easier (for me) solution.
At this stage, it’s just a single Sonoff being controlled.
I’m still not totally happy with the State stuff: I think I’ll use a simpler mapping there. But this works, and integrates nicely with my MQTT HomeKit bridge.
Normally the Sonoff switches don’t support MQTT but you can buy flashed devices that run the Tasmota firmware that does.
The Sonoff-Tasmota firmware provides three interfaces: MQTT, web and serial that can be used for controlling the switch.
In this tutorial I will cover basic setup of the Sonoff Tasmota MQTT Basic Switch and how to use MQTT to control and configure the switch.
Control Button
There is just a single button that is used to control the switch.
It can be used to manually toggle the switch on/off or to place into various configuration mode depending on how often it is pressed.
This link here has an overview of the button options.
Switch Configuration
There are two steps to the configuration:
Wi-fi Setup
MQTT Client configuration
Wi-Fi Setup
To configure the Tasmota switch you need to connect it to a Wi-Fi network.
The switch connects to a Wi-Fi network just like you mobile does and so s you will need to configure the SSID and password of that network.
There are several ways of doing this and the configuration methods are covered here under button usage
The easiest method is to use WPS followed by the android App.
If you use the manual method 4 short presses then note the following:
With this option the switch starts as a Wireless Access point. The SSID on mine was sonoffbasic-1122.
You then need to connect a computer to this access point and go to the IP address 192.168.4.1.
Note corrected from 192.168.1.4
You can then enter the SSID and password of the Wi-Fi network you will be connecting the device to.
When you enter this information into the webpage the switch will restart, connect to the Wi-Fi network and acquire an IP address.
Now in order to configure it further you will need to know the IP address it has acquired.
This isn’t as easy as it sounds but the device name on the network seems to be set to the same as the access point.
So you could try to ping this network name which should give you the IP address.
On my network the BT Home Hub displays all connected devices and was able to find the device IP address there. (screenshot below).
Configuring MQTT
The switch will start as an MQTT client and also a web server.
Initial device configuration is done via the web server. To access the configuration page go to
http://Device-IP/cn e.g
Click on configure MQTT button and you should see the screen similar to the one below:
You need to enter:
The IP address or domain name of the MQTT broker
The Port (default 1883)
Client – This is used as the client -id and needs to be unique
Username – Optional
Password – Optional
Topic – The client will publish and subscribe on this topic. The name should be meaningful.
Full Topic -Defaults to topic/prefix -prefix is stat,cmnd or tele see below under MQTT default topics.
Note: You can use an external broker like test.mosquitto.org but it is better to use a local one. See installing mosquitto or installing mosca on node-red
When finished save the configuration and the switch should restart.
Sonoff MQTT Topics
Sonoff will subscribe to topics to receive control commands . It will also publish status information to topics.
Deciding on the topic structure is an important part of the configuration.
Each Sonoff device has a unique name which you configure in the topic section ( shown above).
This name will reflect the use of the device and should be meaningful e.g
main-light, outside-light etc
The prefix is either cmnd, stat or tele and the choice is usually
prefix +topic (%prefix%/%topic%/) or topic+prefix (%topic%/%prefix%/).
examples:
tele/main-light/ or main-light/tele
Using the prefix as the first part of the topic makes it easier to subscribe to multiple sonoff devices using:
tele/#, stat/# and cmnd/# options
Another option and my preferred option is to add your own prefix.
So if all the Sonoffs were used in your house you could use the topic hierarchy
house/prefix/topic or house/topic/prefix
now you can subscribe to all Sonoff devices using house/#
In this case I prefer house/topic/prefix.
To configure that use:
house/%topic%/%prefix%/
How To Get The Mac Address For Sonoff Free
Starting Sonoff
On start the Sonoff device will subscribe to several topics. The exact topics depend on how you have structured the topic hierarchy. Here we are using the structure house/topic/prefix:
house/main-light/cmnd/#
house/main-light-1/cmnd/#
house/sonoffs/cmnd/#
where
main-light=topic name
main-light-1= the client name or fallback topic
sonoffs is the group name.
It also publishes its status and a Last will message wth the retained message flag set.
house/main-light/stat/POWER ON
house/main-light/tele/LWT online
Below is a screen shot showing the messages sent by a sonoff device starting up.
Controlling the Switch
You can control the switch i.e turn it on/off using either http or MQTT.
This is important to note as some systems may require http and if you have an existing control system that uses http then it might be easier to use that rather than going to MQTT.
This tutorial will mainly cover MQTT but I will also be covering http in another tutorial.
Turning on/off using mqtt
To turn it on/off you publish to the cmnd topic
The exact topic will depend on how you have set the topic structure. Below I use topic/prefix structure so to turn the device sonoff-light on and off I use the topic:
sonoff-light/cmnd/POWER1
With message on or off (case insensitive)
For Mass Effect 2 on the PC, a GameFAQs message board topic titled 'UNLOCK ALL research/guns instantly & permanently via Coalesced'. Prequel bonuses. Have a saved game file from the original Mass Effect on your hard drive, and use that profile in Mass Effect 2 to get the following bonuses. 100,000 credits: Mass Effect character with the 'Rich' achievement 30,000 credits: Level 50 Mass Effect character 2,000 experience points: Level 50 Mass Effect character 5,000 of each resource: Level 50 Mass Effect character. Mass effect 2 unlock all armor. In Mass Effect 2, Commander Shepard's armor can be customized by swapping out pieces of the default N7 Armor for pieces purchased from merchants, or made available as downloadable content, by using the Armor Locker aboard the Normandy SR-2.Besides augmenting the armor's physical appearance, these pieces also have varying effects on Shepard's combat effectiveness. For Mass Effect 2 on the PC, a GameFAQs message board topic titled 'unlocking all weapon and armor and shield research'.
In the example below show how to so it using the mosquitto_pub client.
Turning on/off using http
You can use the curl command or easier still a web browser.
Enter the following
http://sonoff ip address/cm?cmnd=Power%20On
my ip address is 192.168.1.134 so I enter
http://192.168.1.134/cm?cmnd=Power%20On
Note: %20 is a space.
MQTT Default Topic Prefixes
The switch publishes and receives information on several topic prefixes, they are:
Topic
Sent by
Use
cmnd
PC,Smart Phone using an MQTT client
To control the Sonoff,set configuration and get status information
stat
Sent by the Sonoff
Sent in response to a command
tele
Status information
Report status information at set intervals
The above topics are prefixed with the switch topic e.g.
topicbase/stat/
MQTT Commands and Responses
Besides turning the switch on and off, commands can be used to set various settings like the MQTT broker, port retain flag etc and the get information about the switch.
The switch uses a command response structure. Each command is acknowledged with a response.
MQTT commands use the topic structure:
topicbase/cmnd/COMMAND
the result of the command uses the topic
topicbase/stat/RESULT
The result is contained in the message payload.
The screen shot below shows the command response messages for setting the MQTT retain flag on the mqtt client.
Gravograph m20 driver download. The screen shot below show the status messages that the Sonoff sends at regular intervals,
How To Get Sonoff Mac Address
Setting the Group Topic
A collection of devices can be controlled by setting them to use the same group topic.
If our devices used the group topic housesonoffs for example we could turn a device on or off using:
How To Get The Mac Address For Sonoff Driver
house/housesonoffs/cmnd/POWER1 with message on or off
To set the group topic for a device use:
topic house/sonoff-light/cmnd/grouptopic with message group name. As shown below:
You should note that setting a group topic causes the switch to restart as it needs to subscribe to the new topic.
Controlling Using Python Demo Script
If you use python I have written a short demo script that you might find useful. You can download it below
Notes
Ip Address
Because changing certain parameters results in a reboot you can change several parameters in one command using the backlog topic see MQTT Features for more details.