SonOff without flashing firmware

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!
gerardwr
Posts: 76
Joined: Saturday 28 January 2017 12:30
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by gerardwr » Wednesday 20 December 2017 22:18

Anyone interested in testing a Domoticz Python plugin for Sonoff switches?

In a previous message on this topic I reported that:
1 - I got the local Sonoff server created by “mdopp” running on an RPi
2 - I used my Mac to configure a Sonoff to use this local server i.o. the cloud server
3 - I can switch the Sonoff switch ON and OFF by sending commands to the local server
4 - I created a dummy switch in Domoticz with the corresponding ON and OFF action

Triggered by a message on this topic I created my first Domoticz Python plugin to “automate” step 4. I used the HTTP example in the Domoticz distribution as foundation.
- The plugin is added to Domoticz the standard way, configuration as this:

Schermafbeelding 2017-12-20 om 21.06.20.png
Schermafbeelding 2017-12-20 om 21.06.20.png (43.98 KiB) Viewed 2387 times
- After the plugin is added, it automatically creates Domoticz Switches for all Sonoff switches that are known to the local server. I tested with 3 Sonoff switches (S20 + Basic), those are the only types I own.

Schermafbeelding 2017-12-20 om 21.10.02.png
Schermafbeelding 2017-12-20 om 21.10.02.png (47.06 KiB) Viewed 2387 times
- Clicking the Domoticz switch ON/OFF sends commands to the local server that switches the Sonoff’s ON/OFF.
- If the hardware button on the Sonoff switch is used for ON/OFF the new status in Domoticz is updated (this takes max 10 secs).

That’s it, do we need more!?

Leave a reply if you’re interested in testing the plugin, I'll send you a copy.

NOTE 1 : The plugin works for me but is “under construction”. Consider the code as “proof of concept” and “alpha” software. I created the plugin "for fun", not sure if I'm going to really use it.

NOTE 2 : Would have been better if the Plugin would also contain the local server, but this is my 1st plugin, so I wanted to start simple.

gerardwr
Posts: 76
Joined: Saturday 28 January 2017 12:30
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by gerardwr » Wednesday 20 December 2017 22:29

jalbat wrote:
Wednesday 20 December 2017 20:16
I have some S20 and Touch SonOff, the code works ok in Windows pc and Domoticz, but i have a problem, if i touch manually on S20 or in touch panel Domoticz don't update the status.. anyone have this problem? or any light on this??
If you use the hardware switch on a Sonoff this is registered OK in the local server. But the server does not report this to Domoticz, so the Domoticz status is not updated.

To change this you would have to change the server software from mdopp. Or add some feature to Domoticz that gets a regular update from the server.

Both requires some serious programming.

jalbat
Posts: 5
Joined: Wednesday 20 December 2017 19:35
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by jalbat » Wednesday 20 December 2017 22:48

gerardwr wrote:
Wednesday 20 December 2017 22:18


Leave a reply if you’re interested in testing the plugin, I'll send you a copy.

NOTE 1 : The plugin works for me but is “under construction”. Consider the code as “proof of concept” and “alpha” software. I created the plugin "for fun", not sure if I'm going to really use it.

NOTE 2 : Would have been better if the Plugin would also contain the local server, but this is my 1st plugin, so I wanted to start simple.
can you send me to test,,,

vodor
Posts: 29
Joined: Friday 19 February 2016 15:47
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by vodor » Friday 22 December 2017 8:03

I had a sonoff lying around for about a year but never bothered flashing it.
Suddenly it became useful again for a desk lamp. Maybe I can get a few more now :)

Thanks mdopp. This was super quick and easy to setup.

@gerardwr Nice job with the plugin. I wouldn't mind testing it.

On a side note. Has anybody figured out howto change the switches default state to ON instead of OFF? I wanna still be able to use a manual switch to turn the lights on and off if I don't switch it on via domoticz.

gerardwr
Posts: 76
Joined: Saturday 28 January 2017 12:30
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by gerardwr » Friday 22 December 2017 11:26

@vodor and @jalbat
I sent you a PM re. the plugin.

jalbat
Posts: 5
Joined: Wednesday 20 December 2017 19:35
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by jalbat » Friday 22 December 2017 18:17

@gerardwr ...
I receive de plugin but in windows i copy it to domotiz plugins, rename it to .py and install phynton and i can't see the plugin in Domoticz...

Another question, the first time i register the sonoff, everything works ok...i shutdown the server .. and now my sonoff don´t connect to the wireless network,,, always blink.... any cloud on it???

gerardwr
Posts: 76
Joined: Saturday 28 January 2017 12:30
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by gerardwr » Friday 22 December 2017 21:23

jalbat wrote:
Friday 22 December 2017 18:17
@gerardwr ...
I receive de plugin but in windows i copy it to domotiz plugins, rename it to .py and install phynton and i can't see the plugin in Domoticz...
I’m on a Mac So I can’t help you with Windows specifics, sorry.
General procedure is :
- create a new subdirectory in the Domoticz/plugins directory
- copy plugin file in this new Directory and name it plugin.py
- restart Domoticz so the new plugin is registered
- Add the plugin in Domoticz in Setup/Hardware
[/quote]
Another question, the first time i register the sonoff, everything works ok...i shutdown the server .. and now my sonoff don´t connect to the wireless network,,, always blink.... any cloud on it???
The sonoff.server.js communicates with the Sonoff switches, So it must always be running. Otherwise the switches keep blinking the led.

jalbat
Posts: 5
Joined: Wednesday 20 December 2017 19:35
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by jalbat » Friday 22 December 2017 23:24

[/quote]
The sonoff.server.js communicates with the Sonoff switches, So it must always be running. Otherwise the switches keep blinking the led.
[/quote]

Yes... after shutdown the server is up but sonoff always blink, i can see the sonoff in router, but server can't connect .. take a look at the images..

The first time when i start the server it shows all sonoff now nothing...
Attachments
SONOFF.jpg
SONOFF.jpg (14.66 KiB) Viewed 2276 times
sonoffserver.jpg
sonoffserver.jpg (13.46 KiB) Viewed 2276 times
sonoff_register.jpg
sonoff_register.jpg (162.47 KiB) Viewed 2276 times

gerardwr
Posts: 76
Joined: Saturday 28 January 2017 12:30
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by gerardwr » Saturday 23 December 2017 1:38

@jalbat
I seems that the Sonoff is being configured using sonoff.setupdevice.py. Your ouput looks similar to mine.

But the Sonoff does not get a connection to the server (sonoff.server.js).

Could it be that the config information is incorrect? You did change sonoff.config.json, right?
- setup SSID and password of your WLAN
- setup IP of the machine your server is running on
- I had to change "websocketPort" from 433 to 1433 (433 was probably in use already)

Code: Select all

{
    "router": {
        "SSID": ".....",
        "password": "......." 
        
    },
    "server": {
        "IP": "192.168.0.28",
        "httpPort": 1081,
        "httpsPort": 1080,
        "websocketPort": 1443
    }
}

vodor
Posts: 29
Joined: Friday 19 February 2016 15:47
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by vodor » Saturday 23 December 2017 9:46

@gerardwr

Thanks your plugin works perfectly.
The process I followed as you recommended per the standard plugins install

sudo apt-get install -y python3
sudo apt-get install -y python3-dev
sudo systemctl restart domoticz.service

mkdir /home/pi/domoticz/plugins/sonoff
mv plugin.pdf /home/pi/domoticz/plugins/sonoff/plugin.py
chmod 755 /home/pi/domoticz/plugins/sonoff/plugin.py

gerardwr
Posts: 76
Joined: Saturday 28 January 2017 12:30
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by gerardwr » Saturday 23 December 2017 11:29

vodor wrote:
Saturday 23 December 2017 9:46
@gerardwr

Thanks your plugin works perfectly.
Nice!
The process I followed as you recommended per the standard plugins install

sudo apt-get install -y python3
sudo apt-get install -y python3-dev
sudo systemctl restart domoticz.service
I'm not completely sure but I believe that Domoticz already comes with python3, so manually installing may not be neccessary.
mkdir /home/pi/domoticz/plugins/sonoff
mv plugin.pdf /home/pi/domoticz/plugins/sonoff/plugin.py
chmod 755 /home/pi/domoticz/plugins/sonoff/plugin.py
Did not do the chmod myself, but it can't hurt.

BTW : you can change the deafult Sonoffxxxxxx name of the Domoticz switch to anything you want.

Spitfire
Posts: 26
Joined: Thursday 29 December 2016 10:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

SonOff without flashing firmware

Post by Spitfire » Saturday 23 December 2017 12:34

@Gerardwr, Wouldn’t mind testing your plugin.

Merry Christmas!

vodor
Posts: 29
Joined: Friday 19 February 2016 15:47
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by vodor » Sunday 24 December 2017 16:46

@gerardwr

I decided to play around a bit today. Did a fresh install of domoticz first on Debian Jessie then on Stretch
Both times as soon as I enabled your plugin it seems to crash domoticz with fatal signal 11. Strange thing is my actual production device im using does not have the issue that one worked first time.
Not a train smash just thought I would share in-case somebody else runs into this.
Unless of course I did something really stupid with both installations.

Just to be sure I renamed the plugin and then restart domoticz then domoticz loads fine again without crash.
I will mess around a bit later again to see if I can determine the cause.


2017-12-24 14:42:28.983 TCPServer: shared server started...
2017-12-24 14:42:28.985 RxQueue: queue worker started...
2017-12-24 14:42:30.987 EventSystem: reset all events...
2017-12-24 14:42:30.990 EventSystem: reset all device statuses...
2017-12-24 14:42:31.324 PluginSystem: Entering work loop.
2017-12-24 14:42:31.430 Python EventSystem: Module not found - Trying to initialize.
2017-12-24 14:42:31.436 Python EventSystem: Initalizing event module.
2017-12-24 14:42:31.445 EventSystem: Started
2017-12-24 14:42:33.411 (SonOff Probe) Initialized version 0.0.1, author 'gwr'
2017-12-24 14:42:33.473 PluginSystem: Starting I/O service thread.
2017-12-24 14:42:33.525 Error: (SonOff Probe) failed to parse parameters, Message or Message,Verb,URL,Headers,Delay expected.
2017-12-24 14:42:33.527 Error: (SonOff Probe) 'CConnection_send' failed 'TypeError':''dict' does not support the buffer interface'.
2017-12-24 14:42:33.528 Error: Domoticz received fatal signal 11 !...
2017-12-24 14:42:33.540 Error: /home/pi/domoticz/domoticz() [0x1cdc48]
2017-12-24 14:42:33.542 Error: /home/pi/domoticz/domoticz(_Z14signal_handleri+0x58) [0x1cdd00]
2017-12-24 14:42:33.543 Error: /lib/arm-linux-gnueabihf/libc.so.6(__default_sa_restorer_v2+0) [0xb6a81180]
2017-12-24 14:42:33.545 Error: /home/pi/domoticz/domoticz(_ZN7Plugins16CConnection_sendEPNS_11CConnectionEP7_objectS3_+0xd8) [0x4ab0dc]

gerardwr
Posts: 76
Joined: Saturday 28 January 2017 12:30
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by gerardwr » Sunday 24 December 2017 17:08

vodor wrote:
Sunday 24 December 2017 16:46
@gerardwr

I decided to play around a bit today. Did a fresh install of domoticz first on Debian Jessie then on Stretch
Both times as soon as I enabled your plugin it seems to crash domoticz with fatal signal 11. Strange thing is my actual production device im using does not have the issue that one worked first time.
Hmmmmmmmm....... no idea what's happening here.

Did you install the Domoticz Beta version? I'm not sure but I think I read the stable version does not support plugins?

jalbat
Posts: 5
Joined: Wednesday 20 December 2017 19:35
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by jalbat » Sunday 24 December 2017 19:03

gerardwr wrote:
Friday 22 December 2017 21:23
jalbat wrote:
Friday 22 December 2017 18:17
@gerardwr ...
I receive de plugin but in windows i copy it to domotiz plugins, rename it to .py and install phynton and i can't see the plugin in Domoticz...
I’m on a Mac So I can’t help you with Windows specifics, sorry.
General procedure is :
- create a new subdirectory in the Domoticz/plugins directory
- copy plugin file in this new Directory and name it plugin.py
- restart Domoticz so the new plugin is registered
- Add the plugin in Domoticz in Setup/Hardware
@gerardwr
for the registers.. your plugin works on domoticz and W10, the fisrt time i rename the plugin to "sonoff.py", now i rename it to "plugin.py" and voilá... it work's..

But i have some problems with the sonoff server, like i say in later post... sometimes the server discover the sonoff's sometimes no... and they are connected to the wireless network.. with the change of websocket port the problem remains. The 1433 port is not a good choice, is the sql server default port, and a lot of windows people have it installed.

Merry Christmas for all.

gerardwr
Posts: 76
Joined: Saturday 28 January 2017 12:30
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by gerardwr » Sunday 24 December 2017 23:47

jalbat wrote:
Sunday 24 December 2017 19:03
But i have some problems with the sonoff server, like i say in later post... sometimes the server discover the sonoff's sometimes no... and they are connected to the wireless network.. with the change of websocket port the problem remains. The 1433 port is not a good choice, is the sql server default port, and a lot of windows people have it installed.
Yes, the server stops sometimes, also for me. Sometime it runs OK for a day, but then the Sonoff switches have lost contact to the server and "blink". Then I have to restart the server, and the Sonoff's autotically connect again to the server and are available to the plugin.

I am not sure yet why the server sometimes suddenly stops, because I use the server "as is". I see no errors when I log the output of the server to disk.

irongarment
Posts: 18
Joined: Friday 24 November 2017 22:42
Target OS: Raspberry Pi
Domoticz version:
Location: New Zealand
Contact:

Re: SonOff without flashing firmware

Post by irongarment » Monday 25 December 2017 0:17

I have noticed the server will stop if I un-power the Sonoff device. There is an error reported. I should probably post an Issue on mdopp's GitHub.

But not today. It's Christmas Day. :)

gerardwr
Posts: 76
Joined: Saturday 28 January 2017 12:30
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by gerardwr » Monday 25 December 2017 0:20

irongarment wrote:
Monday 25 December 2017 0:17
I have noticed the server will stop if I un-power the Sonoff device. There is an error reported. I should probably post an Issue on mdopp's GitHub.

But not today. It's Christmas Day. :)
Yep, I remember this happening to me too :(

And yes, peace on earth, Merry Christmas.

gerardwr
Posts: 76
Joined: Saturday 28 January 2017 12:30
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by gerardwr » Monday 25 December 2017 12:18

Some users experience stability issues with Python plugins:
https://www.domoticz.com/forum/viewtopi ... 65&t=20747

@noudje reports that a problem might be in connections:
https://www.domoticz.com/forum/viewtopi ... 7#p162769

Following @noudje 's lead I revised the Sonfoff plugin. I removed the Domoticz way of "connections" and now use urllib.requests. All "work" is moved in onHeartBeat and onCommand, the other Domoticz callbacks are now virtually "empty". Looks a lot cleaner and more understandable (to me :D )

Has been running OK overnight, so no real long term experience.

Let me know if you want to test the updated plugin.

vodor
Posts: 29
Joined: Friday 19 February 2016 15:47
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by vodor » Monday 25 December 2017 16:25

gerardwr wrote:
Sunday 24 December 2017 17:08
vodor wrote:
Sunday 24 December 2017 16:46
@gerardwr

I decided to play around a bit today. Did a fresh install of domoticz first on Debian Jessie then on Stretch
Both times as soon as I enabled your plugin it seems to crash domoticz with fatal signal 11. Strange thing is my actual production device im using does not have the issue that one worked first time.
Hmmmmmmmm....... no idea what's happening here.

Did you install the Domoticz Beta version? I'm not sure but I think I read the stable version does not support plugins?
Thanks for the tip. Turns out it was just me being stupid after all. So I did checkout the beta from command line however never set it to use beta release via the domoticz interface. I did that again and it started working. So now I have 2 confirmed working setups with the plugins. Later the week I will be installing a few more switches.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests