ESP8266 gateway - Connection refused



  • Hi,

    I'm trying to use a esp8266 gateway as a standalone node and let it connect to Domoticz. After some hick ups I managed to compile my sketch. The gateway boots, but I'm not sure if it gets connected the right way. Serial log shows:

    0‚~?–$û!ƒ{ƒOAaû0;255;3;0;9;Starting gateway (R-NGE-, 2.0.0-beta)
    scandone
    state: 0 -> 2 (b0)
    .state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 4
    pm open phy_2,type:2 0 0
    cnt 
    
    connected with Bram&Nathalie, channel 11
    ip:192.168.2.242,mask:255.255.255.0,gw:192.168.2.254
    .IP: 192.168.2.242
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0
    65535
    65535
    
    

    In Domoticz I've added a Mysensors Lan Gateway in Hardware, with remote address 192.168.2.242 and port 5003. Which is opened in my router for 192.168.2.242. Domoticz log keeps showing:

    2016-02-22 12:48:16.489 Error: MySensors: Error: Connection refused
    2016-02-22 12:48:16.490 Error: TCP: Error: Connection refused
    

    The inclusion button in the sketch is disabled, but inclusion time is set to 60 seconds. Could this be part of the problem?
    Hope someone can help..


  • Admin

    Is the gateway address really set correct? Looks a bit weird.



  • gateway address must be my internet gateway right? In that case 192.168.2.254 is correct.
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 2, 1 is my Domoticz server. Is that the way to go or am I doing something wrong?


  • Admin

    I don't think Domoticz allows node to connect.

    You should use it the other way around (let Domoticz connect to the gateway).

    (and disable that define)



  • I tried it the other way around, but still no improvement.
    My sketch:

    #include <ESP8266WiFi.h>
    #include <ESP8266WiFiMulti.h>
    #include <WiFiClient.h>
    #include <WiFiClientSecure.h>
    #include <WiFiServer.h>
    #include <WiFiUdp.h>
    #include <EEPROM.h>
    #include <SPI.h>
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 9600
    
    // Enables and select radio type (if attached)
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_GATEWAY_ESP8266
    
    #define MY_ESP8266_SSID "Bram&Nathalie"
    #define MY_ESP8266_PASSWORD "mykey"
    
    // Enable UDP communication
    #define MY_USE_UDP
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,2,242
    
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,2,254
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // The port to keep open on node server mode 
    #define MY_PORT 2000      
    
    // How many clients should be able to connect to this gateway (default 1)
    #define MY_GATEWAY_MAX_CLIENTS 2
    
    // Controller ip address. Enables client mode (default is "server" mode). 
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. 
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 2, 1
    
    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    
    // Enable Inclusion mode button on gateway
    // #define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    //#define MY_INCLUSION_MODE_DURATION 60 
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3 
    
     
    // Flash leds on rx/tx/err
    // #define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    // #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Led pins used if blinking feature is enabled above
    #define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
    
    #if defined(MY_USE_UDP)
      #include <WiFiUdp.h>
    #else
      #include <ESP8266WiFi.h>
    #endif
    
    #include <MySensor.h>
    
    #define CHILD_ID_LIGHT 0
    #define LIGHT_SENSOR_ANALOG_PIN 1
    #define MIN 5  // Liquid
    #define MAX 114 // Air
    
    int sensorPin = A0; // select the input pin for the potentiometer
    int sensorValue = 0; // variable to store the value coming from the sensor
    
    void receive(const MyMessage &msg) {}
    MyMessage msg(CHILD_ID_LIGHT, V_HUM);
    
    void setup() { 
    }
    
    void presentation() {
      
      // Present locally attached sensors here    
      // Send the sketch version information to the gateway and Controller
          sendSketchInfo("Mobile Sensor 1", "Kruiden");
    
    // Register all sensors to gateway (they will be created as child devices)
          present(CHILD_ID_LIGHT, S_HUM);
    
    
    }
    
    
    void loop() {
      // Send locally attached sensors data here
      // read the value from the sensor:
    sensorValue = analogRead(sensorPin);
    delay(1000);
    int lastsensorValue = sensorValue;
     
    Serial.println(sensorValue);
    int sendValue =  map(sensorValue, 5, 114, 0, 100); 
    send( msg.set( sendValue ) ); 
    sleep(9000);
    }
    

    Serial log of arduino shows:

    0‚~?–4û!ƒ{“_Qaû0;255;3;0;9;Starting gateway (R-NGE-, 2.0.0-beta)
    scandone
    state: 0 -> 2 (b0)
    ..reconnect
    state: 2 -> 0 (0)
    f 0, .scandone
    state: 0 -> 2 (b0)
    .state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 3
    pm open phy_2,type:2 0 0
    cnt 
    ..
    connected with Bram&Nathalie, channel 11
    ip:192.168.2.242,mask:255.255.255.0,gw:192.168.2.254
    .IP: 192.168.2.242
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0
    65535
    65535
    65535
    
    

    the number 65535 keeps being printed like every second, which seems strange to me.


  • Admin

    @Bram81 said:

    MY_USE_UDP

    Why did you enable this?



  • Because further down is stated:

    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.

    My assumption was that I want it both to be a client and have it's data send to my domoticz controller, but obviously this isn't the way to go..?



  • disabled MY_USE_UDP and it's connecting now... Thanks, feel pretty stupid.. Attaching the humidity sensor does cause de gateway to a reboot loop. Could that be a power issue since it's connected to my laptop's usb right now?



  • So.. I am VERY confused.. The 8266 wifi gateway doesn't have to have my zwave controller (vera UI7) ip address defined anywhere? I used to have this working, but just started over with the released version of the 2.x code, so I deleted EVERYTHING relating to arduino and MySensors, and started over.
    With the generic GatewayESP8266 code, as soon as I enable the "#define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 185" which I thought was what was telling the code where to gind my Vera, it no longer compiles, but from what I think you're saying in this thread, I dont need to do that? Without my controller IP configured, it does compile and upload, and it connects to my WiFi, but then it just sits there doing "SANCHK:OK", because (I think) it doesn't know where to connect to the Vera... My Vera is configured with the IP of the gateway (192.168.1.106:5003) but it just keeps saying "Cannot Send command - Communications Error".. What am I missing?

    I read that "client" mode is new.. maybe I am messing up my "MySensors" terminology, but shouldn't the 8266 need to know where to talk to Vera?


  • Admin

    @172pilot said:

    MY_CONTROLLER_IP_ADDRESS

    The Vera plugin does not support client mode and must handle the connection to the ESP.8266.

    So instead go to the Vera/mysensors-device/advanced tab and enter the ESPs ip number.


Log in to reply
 

Suggested Topics

  • 5
  • 4
  • 4
  • 1
  • 3
  • 1

16
Online

11.2k
Users

11.1k
Topics

112.5k
Posts