SonOff without flashing firmware

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!
maximus
Posts: 12
Joined: Wednesday 15 November 2017 23:40
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by maximus » Thursday 16 November 2017 17:26

Hi

i tried that yesterday too, but it doesn't work. Maybe we should try give back an array?

Code: Select all

server.get('/devices/:deviceId/:switchId/:state', function (req, res) {
    console.log('GET | %s | %s ', req.method, req.url);
    var d = state.getDeviceById(req.params.deviceId);
    if (!d) {
        res.status(404).send('Sonoff device ' + req.params.deviceId + ' not found');
    } else {
        res.sendStatus(200);
	
        state.pushMessage({ action: 'update', value: { switch: req.params.state , outlet:parseInt(req.params.switchId)}, target: d.id });
    }
});

r3wt3d
Posts: 28
Joined: Friday 10 November 2017 5:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by r3wt3d » Friday 17 November 2017 7:55

yeah maybe send
value: {"switches": [{switch":"off","outlet":0}] }
or like that?

maximus
Posts: 12
Joined: Wednesday 15 November 2017 23:40
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by maximus » Friday 17 November 2017 17:03

No doesnt work, I already tried that.

The serverstart give back an Error .... unexspected "{"

maybe we have to declare a variable as Array with all possible parts of the light switch:

Code: Select all

server.get('/devices/:deviceId/:statusID/', function (req, res) {
    console.log('GET | %s | %s ', req.method, req.url);
    var d = state.getDeviceById(req.params.deviceId);
    var valueArray = [];
  	  valueArray [0] = "{"switches":[{"switch":off","outlet":0},{"switch":off","outlet":1},{"switch":off","outlet":2},{"switch":off","outlet":3}]}";
  	  valueArray [1] = "{"switches":[{"switch":on","outlet":0},{"switch":off","outlet":1},{"switch":off","outlet":2},{"switch":off","outlet":3}]}";
  	  valueArray [2] = "{"switches":[{"switch":on","outlet":0},{"switch":on","outlet":1},{"switch":off","outlet":2},{"switch":off","outlet":3}]}";
  	  valueArray [3] = "{"switches":[{"switch":off","outlet":0},{"switch":on","outlet":1},{"switch":off","outlet":2},{"switch":off","outlet":3}]}";
    	
    if (!d) {
        res.status(404).send('Sonoff device ' + req.params.deviceId + ' not found');
    } else {
        res.sendStatus(200);
	
        state.pushMessage({ action: 'update', value: {valueArray[parseInt(req.params.statusID)]}, target: d.id });
    }
});
i hope there are other people with this light switch who can test this.

This is the switch:

https://www.amazon.de/dp/B075JCN3YQ/ref ... &sr=3&th=1

r3wt3d
Posts: 28
Joined: Friday 10 November 2017 5:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by r3wt3d » Friday 17 November 2017 18:29

maybe its easier to bump SSL and see original protocol

maximus
Posts: 12
Joined: Wednesday 15 November 2017 23:40
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by maximus » Friday 17 November 2017 19:55

mmmh how can i do that? i never do that.

can you give me a short example?

r3wt3d
Posts: 28
Joined: Friday 10 November 2017 5:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by r3wt3d » Saturday 18 November 2017 8:05


maximus
Posts: 12
Joined: Wednesday 15 November 2017 23:40
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by maximus » Saturday 18 November 2017 20:12

So i have it:

simple sonoff server :

Code: Select all

server.get('/devices/:deviceId/:switchID0/:switchStatus0/:switchID1/:switchStatus1/:switchID2/:switchStatus2/:switchID3/:switchStatus3', function (req, res) {
    console.log('GET | %s | %s ', req.method, req.url);
    var d = state.getDeviceById(req.params.deviceId);

    if (!d) {
        res.status(404).send('Sonoff device ' + req.params.deviceId + ' not found');
    } else {
        res.sendStatus(200);
	
        state.pushMessage({ action: 'update', value: {switches: [ {"switch":"" + req.params.switchStatus0 +"","outlet":parseInt(req.params.switchID0)},{"switch":"" + req.params.switchStatus1 +"","outlet":parseInt(req.params.switchID1)},{"switch":"" + req.params.switchStatus2 +"","outlet":parseInt(req.params.switchID2)},{"switch":"" + req.params.switchStatus3 +"","outlet":parseInt(req.params.switchID3)}]}, target: d.id });
    }
});
Switch in Browser:

http://<<IP-Adress>>:1081/devices/10001xxxxx/0/off/1/on/2/off/3/off

the number is here the switchnumber and after that the switchstatus :D :D :D

thasts cool

now its time to integrate it in domotics or iobroker :D

Sonoff without flashing

r3wt3d
Posts: 28
Joined: Friday 10 November 2017 5:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by r3wt3d » Saturday 18 November 2017 20:30

great! :)

DomoticaRob
Posts: 32
Joined: Sunday 29 November 2015 15:03
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: Halle, the Netherland
Contact:

Re: SonOff without flashing firmware

Post by DomoticaRob » Monday 20 November 2017 22:27

Hello guys,

I have Domoticz V3.8153 on a Raspberry Pi 3b and I am interested in connecting a Sonoff TH-16 to read the temperature and to switch.
When I read all the topics above I get dizzy.
Is it possible that the one who fixed it can write down a step by step tutorial in Yip and Janneke language, (monkey proof)?
I think that a whole lot of user will be pleased with such a tutorial. That tutorial can become part of the Wiki.

In advance: many thanks.

r3wt3d
Posts: 28
Joined: Friday 10 November 2017 5:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by r3wt3d » Tuesday 21 November 2017 8:13

Hi DomoticaRob

Please install nodejs and simple-sonoff-server first as below described.

Node.js installation guide:
http://thisdavej.com/beginners-guide-to ... stall-node

r3wt3d wrote:
Friday 10 November 2017 7:11

I did something like this:

cd /var/lib/ #(or /usr/local or where ever you want it)
git clone https://github.com/mdopp/simple-sonoff-server.git
cd simple-sonoff-server
npm install # this will install all necessary modules it seems

vi sonoff.config.json
Edit the line you need:
"router" part is the WiFi Access Point information. "SSID" is your home SSID you want the SonOff to connect to.
"password" is the pre shared password for your Wifi network.

"server" part is where the dummy cloud server for SonOff is running. IP is normally a machine that runs sonoff.server.js like RaspberryPi.
httpPort: leave it as default value if it is not in use
httpsPort: leave it as default value if it is not in use
websocketPort: I changed to 1443 because 443 is normal https port and I already use it.

Once done save it.

This program has a server script and SonOff setup script.

starting the server:
you can just run with "node sonoff.server.js". However If you want it to run in background I recommend to use pm2.
if you don't have it installed yet install it with npm install pm2.
now run the sonoff.server.js with pm2:
pm2 start sonoff.server.js
pm2 startup (this will create a script to run the server at server bootup)

this will run sonoff.server in background.
you can use pm2 log sonoff.server to check the log, pm2 show sonoff.server to check the status etc.
once server is running register client (SonOff switch) to the server you just created (running on raspberry pi)
r3wt3d wrote:
Friday 10 November 2017 13:21

For pi users, I had to enable NetworkManager to get the setupdevice.js to work.
Install NetworkManager with apt-get install network-manager.
Comment out the iface wlan part of /etc/network/interfaces, change managed=true in /etc/NetworkManager/NetworkManager.conf
reboot
then
node sonoff.setupdevice.js
Long press the button on SonOff until it blinks fast.
When it works well the setupdevice script will quit and show something like Success. Read the output carefully.

Try this and check if SonOff is connected to your server
curl http://localhost:1081/devices

Once this are done you can add it to domoticz using Virtual Hardware and Virtual Switch.

DomoticaRob
Posts: 32
Joined: Sunday 29 November 2015 15:03
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: Halle, the Netherland
Contact:

Re: SonOff without flashing firmware

Post by DomoticaRob » Tuesday 21 November 2017 20:32

Hello r3wt3d,

Thanks for your reply. This week I hope to find some time to try-out what you wrote.

ufnec
Posts: 6
Joined: Thursday 23 November 2017 3:55
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by ufnec » Thursday 23 November 2017 4:03

Thanks for the great work, got it working with sonoff basic, but unable to do the same with the Dual or 4CH
It seems like the Dual and 4CH not able to connect to my wifi, below is the log from setupdevice.js

WiFiControl: Successfully connected to "ITEAD-100018b068"
OK | Sonoff paired. { success: true,
msg: 'Successfully connected to "ITEAD-100018b068"' }
device: {"deviceid":"100018b068","apikey":"4f18138a-50f9-4172-ac53-de21ce18bbb4"}
{"statusCode":200,"body":{"deviceid":"100018b068","apikey":"4f18138a-50f9-4172-ac53-de21ce18bbb4","accept":"post"},"headers":{"content-type":"application/json","connection":"keep-alive","content-length":"93"},"request":{"uri":{"protocol":"http:","slashes":true,"auth":null,"host":"10.10.7.1","port":80,"hostname":"10.10.7.1","hash":null,"search":null,"query":null,"pathname":"/ap","path":"/ap","href":"http://10.10.7.1/ap"},"method":"POST"," ... length":90}}} [object Object]

r3wt3d
Posts: 28
Joined: Friday 10 November 2017 5:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by r3wt3d » Friday 24 November 2017 7:30

ufnec wrote:
Thursday 23 November 2017 4:03
Thanks for the great work, got it working with sonoff basic, but unable to do the same with the Dual or 4CH
It seems like the Dual and 4CH not able to connect to my wifi, below is the log from setupdevice.js

WiFiControl: Successfully connected to "ITEAD-100018b068"
OK | Sonoff paired. { success: true,
msg: 'Successfully connected to "ITEAD-100018b068"' }
device: {"deviceid":"100018b068","apikey":"4f18138a-50f9-4172-ac53-de21ce18bbb4"}
{"statusCode":200,"body":{"deviceid":"100018b068","apikey":"4f18138a-50f9-4172-ac53-de21ce18bbb4","accept":"post"},"headers":{"content-type":"application/json","connection":"keep-alive","content-length":"93"},"request":{"uri":{"protocol":"http:","slashes":true,"auth":null,"host":"10.10.7.1","port":80,"hostname":"10.10.7.1","hash":null,"search":null,"query":null,"pathname":"/ap","path":"/ap","href":"http://10.10.7.1/ap"},"method":"POST"," ... length":90}}} [object Object]
Did you tried this method in this post from Maximus?
maximus wrote:
Saturday 18 November 2017 20:12
So i have it:

simple sonoff server :

Code: Select all

server.get('/devices/:deviceId/:switchID0/:switchStatus0/:switchID1/:switchStatus1/:switchID2/:switchStatus2/:switchID3/:switchStatus3', function (req, res) {
    console.log('GET | %s | %s ', req.method, req.url);
    var d = state.getDeviceById(req.params.deviceId);

    if (!d) {
        res.status(404).send('Sonoff device ' + req.params.deviceId + ' not found');
    } else {
        res.sendStatus(200);
	
        state.pushMessage({ action: 'update', value: {switches: [ {"switch":"" + req.params.switchStatus0 +"","outlet":parseInt(req.params.switchID0)},{"switch":"" + req.params.switchStatus1 +"","outlet":parseInt(req.params.switchID1)},{"switch":"" + req.params.switchStatus2 +"","outlet":parseInt(req.params.switchID2)},{"switch":"" + req.params.switchStatus3 +"","outlet":parseInt(req.params.switchID3)}]}, target: d.id });
    }
});
Switch in Browser:

http://<<IP-Adress>>:1081/devices/10001xxxxx/0/off/1/on/2/off/3/off

the number is here the switchnumber and after that the switchstatus :D :D :D

thasts cool

now its time to integrate it in domotics or iobroker :D

Sonoff without flashing

ufnec
Posts: 6
Joined: Thursday 23 November 2017 3:55
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by ufnec » Friday 24 November 2017 9:15

r3wt3d wrote:
Friday 24 November 2017 7:30
Did you tried this method in this post from Maximus?
after running setupdevice.js, the device green led quickly blinks one time and repeats, which means device failed to connect to router.I have checked config file ssid and password are valid, somehow the device registration has failed.

r3wt3d
Posts: 28
Joined: Friday 10 November 2017 5:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by r3wt3d » Monday 27 November 2017 6:28

ufnec wrote:
Friday 24 November 2017 9:15
r3wt3d wrote:
Friday 24 November 2017 7:30
Did you tried this method in this post from Maximus?
after running setupdevice.js, the device green led quickly blinks one time and repeats, which means device failed to connect to router.I have checked config file ssid and password are valid, somehow the device registration has failed.
can you connect to sonoff.server.js port with curl from different device like PC or so?
Sometimes DHCP changes the server IP. Happened to me few times even I have set the IP statically on my raspberry pi...very weird.

ufnec
Posts: 6
Joined: Thursday 23 November 2017 3:55
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by ufnec » Tuesday 28 November 2017 4:50

checked sonoff.server.js both port and ip, i could get response without problem, but the 2 gang or 4 gang just couldn't connect to my wifi. I did tried many times during the weekend but still no luck, I have also tried sonoff.setupdevice.js with the sonoff basic I could pair it up on the 1st try.

maximus
Posts: 12
Joined: Wednesday 15 November 2017 23:40
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by maximus » Tuesday 28 November 2017 22:33

hi,

try this...press the first switch for 5 s till the wifi led blink 3times short one times long.

then press the other switch until the led blinking fast.n

then look at your wlan to connect to ssid intead... key12345678

after that start the setup.js

then the server

ufnec
Posts: 6
Joined: Thursday 23 November 2017 3:55
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by ufnec » Wednesday 29 November 2017 3:25

maximus wrote:
Tuesday 28 November 2017 22:33
hi,

try this...press the first switch for 5 s till the wifi led blink 3times short one times long.

then press the other switch until the led blinking fast.n

then look at your wlan to connect to ssid intead... key12345678

after that start the setup.js

then the server
Yes I did this also, after connected to sonos wifi "ITEAD-xxxx", i could ping 10.10.7.1 and I could get reply from http://10.10.7.1/devices

then I run setup.js, once done, wifi disconnected, and sonos is not connected to my home wifi.

maximus
Posts: 12
Joined: Wednesday 15 November 2017 23:40
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by maximus » Wednesday 29 November 2017 20:55

I have a other question, how can i add this server to domiticz

im new here.

@ufnec

you must connect to that wifi where switch have to work....then start the server

ufnec
Posts: 6
Joined: Thursday 23 November 2017 3:55
Target OS: -
Domoticz version:
Contact:

Re: SonOff without flashing firmware

Post by ufnec » Thursday 30 November 2017 3:30

maximus wrote:
Wednesday 29 November 2017 20:55
I have a other question, how can i add this server to domiticz

im new here.

@ufnec

you must connect to that wifi where switch have to work....then start the server
understand that the device need to connect to my wifi
I did the same for sonoff basic and it could connect without problem, then the same config file and procedure just couldn't get a sonoff dual and sonoff 4ch to connect to my wifi.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests