mdopp / simple-sonoff-server

Emulates the original sonoff-cloud-servers within your local network.
BSD 2-Clause "Simplified" License
144 stars 47 forks source link

Connecting to 10.10.7.1:80... failed: Connection timed out. #12

Closed NiekN closed 6 years ago

NiekN commented 6 years ago

i cannot succeed in connecting to the Sonoff, and need some help

im running the simple-sonoff-server(at putty screen 1) 1.set the sonoff basic into AP mode

  1. find and logged into the sonoff (at chrome url) 3,. but when i used "wget -O- 10.10.7.1/device" (at putty screen 2) i get... Connecting to 10.10.7.1:80... failed: Connection timed out. Retrying. what im doing wrong here ??
NiekN commented 6 years ago

how can i connect with my pi on the access point that will appear (SSID:ITEAD-10000xxxxx Password:12345678)??

mdopp commented 6 years ago

For me, I use my notebook for setting up the sonoff devices. Wasn't able to make it happen with my pi.

Questions:

NiekN commented 6 years ago

its nice you are willing to help, thx

i can connect with my laptop on the sonoff that works, so i think a ping will work i opened 2 screens with putty , connected to my PI one to run the server and the other for the commands i added the command "sudo route change 0.0.0.0 mask 0.0.0.0 10.10.7.1" image

NiekN commented 6 years ago

how do you setting it up with a laptop? where do you add these commands?

NiekN commented 6 years ago

1.connecting the laptop to the sonoff (I succeed)

  1. adding http://10.10.7.1/device in the url at chrome(I succeed)
  2. wget -O- --post-data='{"version":4,"ssid":"yourSSID","password":"yourSSID_PASSWORD","serverName":"n.n.n.n","port":1080}' --header=Content-Type:application/json "http://10.10.7.1/ap" (do not know?)
mdopp commented 6 years ago

I am using the sonoff.devicesetup.js

But I just realized that it will not work in the current version. var serverIP = "0.0.0.0" Must be the ip of your raspberry

Other than that it should work.

NiekN commented 6 years ago

I changed the var serverIP = "0.0.0.0" in ip of my PI at sonoff.devicesetup.js

  1. start up sonoff-server
  2. sudo route change 0.0.0.0 mask 0.0.0.0 10.10.7.1
  3. node sonoff.devicesetup.js (on PI). image d
NiekN commented 6 years ago

but do i have to connect with the PI to the sonoff AP? Im using the PI remote, so i cannot connect it also to the sonoff AP.

pevecyan commented 6 years ago

Afaik, you should run sonof server on PI and then with your laptop start setup device script with ip and port pointing towards your PI

NiekN commented 6 years ago

So this means, for my understanding

  1. start sonoff server on PI
  2. set sonoff in AP mode
  3. connect laptop to sonoff
  4. run scriptsonoff.devicesetup.js on my laptop( so i have to copy this file to my laptop?)
NiekN commented 6 years ago

how to run scriptsonoff.devicesetup.js ?

pevecyan commented 6 years ago

Yeah, that is correct procedure, you should copy the whole repository to a laptop. You will also need node installed on that laptop, before running setup you have to run cmd "npm install" in repository folder, which installs all dependencies . To run setup you have to run "node scriptsonoff.devicesetup.js".

NiekN commented 6 years ago

OK, i will try to install it

mdopp commented 6 years ago

@NiekN were you able to make it work?

NiekN commented 6 years ago

still not

-i installed nodejs on win10 pc -runned nodejs command promt -node sonoff.setupdevice.js -set device in AP mode

image

mdopp commented 6 years ago

I never used the node.js box. But I think you still have to write "node sonoff.server.js" to run it. You screenshot shows that windows tries to run it native.

NiekN commented 6 years ago

i did run node sonoff.server.js at PI

when in switch manually my laptop to connect to AP of sonoff i get image

NiekN commented 6 years ago

it look like it is connected successfully . but it did not drop directly out off AP mode, but after a time out i get an error like it shows in teh screenshot

mdopp commented 6 years ago

I will check the code once again if i see something strange after the last commit.

About the "did not drop directly out of AP mode" => this seams to be an Windows thing (at least on my windows 10 mashine). It is just scanning when the list of wifi networks is open. Otherwise it will just scan every now and then.

mdopp commented 6 years ago

OK, that could be a simple problem in the code => can you please try to change

var serverIP = "0.0.0.0"

to the ip-adress of your raspberry pi with an editor (notepad will do), and re-run the code? If that works, I will change the code to solve this for others to.

NiekN commented 6 years ago

i had already changed it to ip of raspbarry var serverIP = "my ip of raspberry "

in file :sonoff.setupdevice.js

NiekN commented 6 years ago

do i have to install NetworkManager??

mdopp commented 6 years ago

should not be nessesary on windows (at least 10)

mdopp commented 6 years ago

just double checked everything, and i do not see any reasons why it should not work. As you can connect from windows everything should work fine. I will get a device tomorrow and try again. Only if you have a new device with a version > 1.5.5 it should not work.

NiekN commented 6 years ago

ok.
but it pairs with sonoff . but it looks like the Sonoff it changing to the SSID/password of my network and connecting to the sonoff server, which is running

NiekN commented 6 years ago

version 1.5.5 ??? is that the hardware version

NiekN commented 6 years ago

my sonoff basic is TH 1.0

NiekN commented 6 years ago

mmh i did not use the ewelink app to this device, should i do that ? I do not know if it will send the ID and API anymore .
Double checked .

-Server still running on PI -sonoff.setupdevice.js IP of raspberry was added correctly (at win10) -sonoff.config,json my SSID, pasword, IP of raspberry port http1080,https1081 socket1443 was added correctly(at win10)
-installed nodejs(at win10) -runned node sonoff.setupdevice.js(at win10) -set sonoff in AP mode and connect with laptop

mdopp commented 6 years ago

Did you see anything on the log files of the pi? Otherwise it is not connecting there. Also: this tool uses environment variables for the said, pwd, ... Not the config files

NiekN commented 6 years ago

I wil check the logs, but i do not know where searching for

NiekN commented 6 years ago

Environment variables of the sonoff device, where do I have to set them ?

NiekN commented 6 years ago

try again, now with the lates simple-sonoff-server 1.1.2 and a different PC (win7) same results

mdopp commented 6 years ago

on your windows PC, pls set

set WIFI_SSID={yourSSID}
set WIFI_PASSWORD={yourPassword}
set HTTPS_PORT=1080

About the log on the raspberry: I mean the consol output of the server. Does it show anything about a connecting device?

mdopp commented 6 years ago

Since the last merge, the sonoff.setupdevice.js was not reading the sonoff.config.json anymore, but looking for environment variables instead. This make the change of the serverIP in the code obsolete again as it will read if from the config. I just changed it again to look first for sonoff.config.json, then overwrite parameters with environment variables for docker. And if they are still unset, it is shown in the console output to identify this as an problem.

Maybe you can use this version for tracing your error?

NiekN commented 6 years ago

i edit sonoff.setupdevice.js on my laptop

var wifiSSID = "mySSID" var wifiPassword = "my password" var httpsPort = 1080

start the server run sonoff.setupdevice.js set sonoff in AP mode connect

the sonoff drops out of AP mode

NiekN commented 6 years ago

at my router i cannot see it that it is connected when i used the FING app, i see it has a IP adress in my range the led is still blinking (not like AP mode, but 2x fast blinks

i see nothing happening on the sonoff- server

mdopp commented 6 years ago

Ok. But that it how it should look like on this script.

Few things I can imagine: wrong password, wrong ssid or, what happens to me most of the time: router is set to not allow new connections for security reasons. This would be a thing that you have to check on your router.

And are you sure that it's port 1080 for https?

NiekN commented 6 years ago

i also cannot control it by using http://127.0.0.1:1080/devices/deviceID/on

i also cannot do this procedure again i think. it does not send a AP when it is in AP-mode is there a way to log in this device . or is it now useless???

i also made a dummy switch with http://127.0.0.1:1080/devices/deviceID/on http://127.0.0.1:1080/devices/deviceID/off

the sonof server comes with a message GET | GET | /devices/100031xxxx/on

NiekN commented 6 years ago

at sonof.config,json

    "httpPort": 1080,
    "httpsPort": 1081,
    "websocketPort": 1443
}

}

at sonoff.setupdevice.js var httpsPort = 1080

so there is a mis match

so i stopped the server edit at sonof.config,json

    "httpPort": 1081,
    "httpsPort": 1080,

still nothing is happons

NiekN commented 6 years ago

but should the sonoff not stopping with blinking?

NiekN commented 6 years ago

ok i can access the AP-mode again and tested the new file "sonoff.setupdevice.js"

the same results, also connected like the last image. it drops directly outoff AP-mode but still blinking 2x fast ?

NiekN commented 6 years ago

double check SSID and password. they are OK router blocking the new connection, i hsvr s dimple modem/router from ziggo supplier. I cannot file anything what should block it

mdopp commented 6 years ago

You can repeat this procedure as often as you want. It should not be possible to brick the device this way.

The port is just the 2nd part. First the sonoff device must be shown on your router. But it will only frequently. Just every few seconds for a few seconds. For me it seams that the times between connecting retries are getting longer over time.

Can you open a telnet session to the pi from your windows PC?

Telnet 192.???.???.??? 1081

But being honest: I am getting lost here... It's very difficult to debug with this little input (not knowing all your configuration)

NiekN commented 6 years ago

I appreciate your help, but im not familaire with this, sorry

When i check my router i cannot see that it at connect devices . But my FING app , shows it is present. And it is a IP in my range. So the router did give a IP adress to the sonoff. I also can change te last number op the IP adress of the sonoff in my router, so it's now fixed in my router at :192.168.178.240

So actually i think it is connected to my router . but you wrote :requently. Just every few seconds for a few seconds. so it is not always active ?

About the blinking of the LED , it this normall ? i have also a device connected to ewelink , and there the LED is only on when the relay of this device is on

i can open a telnet session with putty , but telnet has a fix port :23 i think

mdopp commented 6 years ago

The blinking lights shows that it is searching the server. Telnet works with every port, just like putty. You just have to specify it. This way you can check if the server is listening on the expected port, and make sure there is no network rule blocking the connection.

NiekN commented 6 years ago

OK , clear but if now the sonoff has a IP, could i not just easily controll in with a url in chrome to test it? somethning like so: 192.168.178.240/on( without server)

pevecyan commented 6 years ago

Sadly with stock firmware on it you could not. It uses websockets for communication with server and not plain http requests.

mdopp commented 6 years ago

Correct.

  1. The setup tells the device, which wifi to use, and where to find the control server.
  2. The device connects to the wifi.
  3. The device tries to establish an https connection to the given serverIp + https port, luckily without checking the c certificate (only starting with rom version 1.6, that's why it won't work with newer versions yet)
  4. The server tells which websocket port should be used.
  5. The device connects to the websocket port From now on status messages are send by the device to the server, and commands are send by the server to the device. Both are shown on the command line output of the server
NiekN commented 6 years ago

OK .. clear. firmware 1.6 .. is it possible to check which version is on the sonoff
this one is an old type TH1.0 . So point 3 and/or 4 is not working at my side

mdopp commented 6 years ago

If it would be the firmware, it still should show something on the server side. Can you please!! send some config and logs from there? I can not continue like this