normen / homebridge-433-arduino

A homebridge plugin to control 433MHz switches using an Arduino as transceiver
25 stars 11 forks source link

Trouble with Websockets #27

Closed mikeMikeymike closed 3 years ago

mikeMikeymike commented 3 years ago

Thanks so much for providing and working on this code!

If it matters, I'm programming my ESP8266 using the Arduino IDE. The program works with a direct serial connection to my Rapsberry Pi via the serial port. But when I try using a websocket I get an error. I added a couple print statements to my Arduino code and I see that the ESP8266 is connecting to my internet. I left the default name for the WIFI_HOSTNAME

Here's the error from the homebridge log:

[Arduino RC Switch Platform] WebSocketClient: error [Arguments] {
  '0': Error: getaddrinfo ENOTFOUND arduino-433
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:69:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'arduino-433'
  }
}

And here's the relevant portion of the homebridge config:

 {
            "name": "Arduino RC Switch Platform",
            "host": "arduino-433",
            "input_output_timeout": 100,

And here's the code on the ESP8266 (with passwords and ssid redacted)

// uncomment this to start websocket server for homebridge -> set WLAN login creds
#define USE_WEBSOCKET

// uncomment this to use ESPilight insted of rc-switch to decode switches -> different message format
//#define USE_ESPILIGHT

// WIFI login if using websocket
#ifdef USE_WEBSOCKET
#define WIFI_SSID "xxx"
#define WIFI_PASS "xxx"
#define WIFI_HOSTNAME "arduino-433"
#endif
normen commented 3 years ago

It seems that your network router doesn't pick up on the hostname and doesn't add it to its DNS, so you can't use the name to connect to the ESP.. You could check if your router supports assigning a name (or fixed IP) by using the ESPs MAC address. Most routers have an option to at least assign a fixed IP for a certain devices/MAC. Of course that would involve finding out the MAC of your ESP, possibly also through your router.

mikeMikeymike commented 3 years ago

Thanks for your response. Unfortunately, assigning a fixed IP didn't help. I can connect to the Homebridge with homebridge.local so some hostnames work. My Netgear R7000P firmware seems a little buggy, so it may still be a problem with my router.

normen commented 3 years ago

Hm, but you did enter the IP address instead of "arduino-433" in the config then? I realize I didn't say that explicitly. You can just replace the "hostname" with the IP (also as a string).

mikeMikeymike commented 3 years ago

oops, I didn't do that. Silly me. Entering the IP does work.