Cannot add Nodes trough RS 485



  • Hello,

    I would like to ask you for your help. I frozen on adding a Nodes to Mycontroller.

    I am using Serial RS485 gateway - This I managed to add to MyController
    ![0_1626943900630_Gateway.JPG](Uploading 100%)

    As a Nod I am using DHT sketch with RS485 enabled and NOD definition

    #define MY_NODE_ID 22
    #define MY_PARENT_NODE_ID 0
    

    If I try to add Node manually Node is in status down
    ![0_1626944062318_Node.JPG](Uploading 100%)

    Communication between GW and Node works well

    0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RSNGA---,FQ=16,REL=255,VER=2.3.2
    0;255;3;0;9;5 TSM:INIT
    0;255;3;0;9;7 TSF:WUR:MS=0
    0;255;3;0;9;10 TSM:INIT:TSP OK
    0;255;3;0;9;13 TSM:INIT:GW MODE
    0;255;3;0;9;15 TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;19 MCO:REG:NOT NEEDED
    0;255;3;0;14;Gateway startup complete.
    0;255;0;0;18;2.3.2
    0;255;3;0;9;23 MCO:BGN:STP
    0;255;3;0;9;29 MCO:BGN:INIT OK,TSP=1
    0;255;3;0;9;33 TSM:READY:NWD REQ
    0;255;3;0;9;53 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
    0;255;3;0;9;7954 TSF:MSG:READ,22-22-0,s=0,c=1,t=1,pt=7,l=5,sg=0:41.0
    22;0;1;0;1;41.0
    

    Thank you very much for any advice



  • This post is deleted!

  • Plugin Developer

    @qobouky your attachments are not available. can you please add it again?
    do not you get your node by running discover on MyController?



  • Gateway
    Gateway.PNG

    Node
    Node.PNG

    Unfortunately function discover does not add anything


  • Plugin Developer

    @qobouky seems you have problem with MyController and serial port communication. I do not see the node 0 too (gateway node).
    can you check the MyController log file, is there any error? Also check the baud rate and port number of your serial device.



  • Of course it was issue on my side. My understanding was that GW baud rate in mycontroller should be baud rate of RS485. When I changed baud rate to correct value everything works well. Nod is added automatically.

    But I would like to kindly ask you for next suggestion.

    I plan to use one Arduino to monitor Temp, Hum and CO2. Those sensors are presented in MyController as static now.

    Additionally script should control 3 relays. I added relay script from My sensors but I have no idea where I should see those relays in MyController and how to control them manually

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 2
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 9600
    
    // Enable this if RS485 is connected to a hardware serial port
    //#define MY_RS485_HWSERIAL Serial1
    
    #define MY_NODE_ID 20
    
    #include <MySensors.h>
    
    static const uint64_t UPDATE_INTERVAL = 10000;
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_CO2 2
    
    #define RELAY_PIN 10  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 3 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgCo2(CHILD_ID_CO2, V_LEVEL);
    MyMessage msgCo2b(CHILD_ID_CO2, V_UNIT_PREFIX);
    
    // ----------------------------------------------------------------------------
    
    void before()
    {
        for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
            // Then set relay pins in output mode
            pinMode(pin, OUTPUT);
            // Set relay to last known state (using eeprom storage)
            digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
        }
    }
    
    void presentation()  
    { 
      // Send the sketch version information to the gateway
      sendSketchInfo("Lihen", "1.0");
      
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
      present(CHILD_ID_CO2, S_AIR_QUALITY);
      send(msgCo2b.set("ppm"));
    
      for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
      }
    }
    
    // ----------------------------------------------------------------------------
    void setup()
    {
      Serial.println( F("Arduino MySensors RS485 Node test") );    // Fonction F() permet de placer la chaine dans la mémoire eprogramme (Arduino IDE 1.0).
      analogReference(INTERNAL);
      delay(1000);
    }
    
    
    void loop()
    {
        Serial.println( F("Loop ...") );
        TempHum();
        readCO2(); 
        // Sleep for a while to save energy
        sleep(UPDATE_INTERVAL); 
    }
    
    void TempHum ()
    {
        int temperature = 30;
        int humidity = 50;
        Serial.print(F("Tmp: "));
        Serial.println(temperature);
        Serial.print(F("Hum: "));
        Serial.println(humidity);
    
        send(msgTemp.set(temperature, 1));
        send(msgHum.set(humidity, 1));
    }
    
    int readCO2()
    {
        int CO2value = 1550;
        Serial.print(F("CO2: "));
        Serial.println(CO2value);
    
        send(msgCo2.set(CO2value)); 
    }
    
    void receive(const MyMessage &message)
    {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.getType()==V_STATUS) {
            // Change relay state
            digitalWrite(message.getSensor()-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
            // Store state in eeprom
            saveState(message.getSensor(), message.getBool());
            // Write some debug info
            Serial.print("Incoming change for sensor:");
            Serial.print(message.getSensor());
            Serial.print(", New status: ");
            Serial.println(message.getBool());
        }
    }
    

  • Plugin Developer

    @qobouky to get V_STATUS, you can do it two ways

    1. (added automatically in MyController) Send the current status of the relays on your presentation block in your MySensors sketch
    2. (add manually in MyController) - you can see S_BINARY sensors in MyController on this node. You can add a V_STATUS variable on each S_BINARY sensor in MyController

    You will get a control option for your relays.



  • Sorry but do I understand correctly that relay should be visible as a Sensor in MyController?

    Sensor_Relay.PNG


  • Plugin Developer

    @qobouky You are correct, the Binary type sensors should be visible here.
    I just revisited your sketch and I found a conflict on the allocated sensors id

    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_CO2 2
    
    #define NUMBER_OF_RELAYS 3 // Total number of attached relays
    void presentation()  {
    present(CHILD_ID_HUM, S_HUM);
    present(CHILD_ID_TEMP, S_TEMP);
    present(CHILD_ID_CO2, S_AIR_QUALITY);
    
     for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
      }
    }
    

    your relay sensor id should start from 3 or above.
    I do not see the use of pin=RELAY_PIN.
    You can present the status of your relay's, that can create V_STATUS on MyController

    example:

    #define RELAY_SENSOR 3 // Relay sensor starts at 3
    
    void presentation()  {
    ....
    MyMessage relayMsg(RELAY_SENSOR, V_STATUS);
    for (int sensor=RELAY_SENSOR; sensor < (RELAY_SENSOR + NUMBER_OF_RELAYS); sensor++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
        relayMsg.sensor = sensor;
        send(relayMsg.set(loadState(sensor))); // current status of the relay
      }
    }
    

    NOTE: You have to update your relay code on setup and in receive too


Log in to reply
 

Suggested Topics

14
Online

11.4k
Users

11.1k
Topics

112.7k
Posts