P1 not working when using Mysensors ?



  • Hey guys,

    I am trying to make this sketch work for a few days now but it looks like it wont work in combination with Mysensors.
    Here the sketch without the Mysensors.
    I am receiving output of the P1 Port on hardware serial 2.

    
    #define MY_DEBUG
    
    //#define MY_RADIO_RF24
    //#include <MySensors.h>
    
    
    
    char c;
     
    void setup() {
     Serial.begin(19200);
      Serial2.begin(9600, SERIAL_7N1);
    }
     
    void loop() {
        if (Serial2.available()) {
            c = Serial2.read();
    
        Serial.print(c);
        }
    }
    
    
    
    
    
    /* Baud-rates available: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200, 256000, 512000, 962100
     *  
     *  Protocols available:
     * SERIAL_5N1   5-bit No parity 1 stop bit
     * SERIAL_6N1   6-bit No parity 1 stop bit
     * SERIAL_7N1   7-bit No parity 1 stop bit
     * SERIAL_8N1 (the default) 8-bit No parity 1 stop bit
     * SERIAL_5N2   5-bit No parity 2 stop bits 
     * SERIAL_6N2   6-bit No parity 2 stop bits
     * SERIAL_7N2   7-bit No parity 2 stop bits
     * SERIAL_8N2   8-bit No parity 2 stop bits 
     * SERIAL_5E1   5-bit Even parity 1 stop bit
     * SERIAL_6E1   6-bit Even parity 1 stop bit
     * SERIAL_7E1   7-bit Even parity 1 stop bit 
     * SERIAL_8E1   8-bit Even parity 1 stop bit 
     * SERIAL_5E2   5-bit Even parity 2 stop bit 
     * SERIAL_6E2   6-bit Even parity 2 stop bit 
     * SERIAL_7E2   7-bit Even parity 2 stop bit  
     * SERIAL_8E2   8-bit Even parity 2 stop bit  
     * SERIAL_5O1   5-bit Odd  parity 1 stop bit  
     * SERIAL_6O1   6-bit Odd  parity 1 stop bit   
     * SERIAL_7O1   7-bit Odd  parity 1 stop bit  
     * SERIAL_8O1   8-bit Odd  parity 1 stop bit   
     * SERIAL_5O2   5-bit Odd  parity 2 stop bit   
     * SERIAL_6O2   6-bit Odd  parity 2 stop bit    
     * SERIAL_7O2   7-bit Odd  parity 2 stop bit    
     * SERIAL_8O2   8-bit Odd  parity 2 stop bit    
    */
    
    

    When i am using this same sketch with the Mysensors it is not giving output anymore.
    Does someone has an clue ?
    I have used an Arduino nano 16mhz first on altsoftserial with the same result.
    in this example i am using an Arduino mega 2560.

    
    #define MY_DEBUG
    
    #define MY_RADIO_RF24
    #include <MySensors.h>
    
    
    
    char c;
     
    void setup() {
     Serial.begin(19200);
      Serial2.begin(9600, SERIAL_7N1);
    }
     
    void loop() {
        if (Serial2.available()) {
            c = Serial2.read();
    
        Serial.print(c);
        }
    }
    
    
    
    
    
    /* Baud-rates available: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200, 256000, 512000, 962100
     *  
     *  Protocols available:
     * SERIAL_5N1   5-bit No parity 1 stop bit
     * SERIAL_6N1   6-bit No parity 1 stop bit
     * SERIAL_7N1   7-bit No parity 1 stop bit
     * SERIAL_8N1 (the default) 8-bit No parity 1 stop bit
     * SERIAL_5N2   5-bit No parity 2 stop bits 
     * SERIAL_6N2   6-bit No parity 2 stop bits
     * SERIAL_7N2   7-bit No parity 2 stop bits
     * SERIAL_8N2   8-bit No parity 2 stop bits 
     * SERIAL_5E1   5-bit Even parity 1 stop bit
     * SERIAL_6E1   6-bit Even parity 1 stop bit
     * SERIAL_7E1   7-bit Even parity 1 stop bit 
     * SERIAL_8E1   8-bit Even parity 1 stop bit 
     * SERIAL_5E2   5-bit Even parity 2 stop bit 
     * SERIAL_6E2   6-bit Even parity 2 stop bit 
     * SERIAL_7E2   7-bit Even parity 2 stop bit  
     * SERIAL_8E2   8-bit Even parity 2 stop bit  
     * SERIAL_5O1   5-bit Odd  parity 1 stop bit  
     * SERIAL_6O1   6-bit Odd  parity 1 stop bit   
     * SERIAL_7O1   7-bit Odd  parity 1 stop bit  
     * SERIAL_8O1   8-bit Odd  parity 1 stop bit   
     * SERIAL_5O2   5-bit Odd  parity 2 stop bit   
     * SERIAL_6O2   6-bit Odd  parity 2 stop bit    
     * SERIAL_7O2   7-bit Odd  parity 2 stop bit    
     * SERIAL_8O2   8-bit Odd  parity 2 stop bit    
    */
    
    

  • Mod

    Welcome to the mysensors community @toine33

    What does the debug output from the node say?

    Are you sure the nrf24 is correctly wired? Is your gateway and controller up and running?

    If you haven't already, see https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help/ for the most common problems and how to troubleshoot them efficiently.



  • So the output wich is given on the first sketch is :

    /ISk5\2MT382-1003
    
    0-0:96.1.1(5A424556303035303738373110323132)
    1-0:1.8.1(08316.297*kWh)
    1-0:1.8.2(08472.574*kWh)
    1-0:2.8.1(00000.020*kWh)
    1-0:2.8.2(00000.010*kWh)
    0-0:96.14.0(0001)
    1-0:1.7.0(0000.38*kW)
    1-0:2.7.0(0000.00*kW)
    0-0:17.0.0(0999.00*kW)
    0-0:96.3.10(1)
    0-0:96.13.1()
    0-0:96.13.0()
    0-1:24.1.0(3)
    0-1:96.1.0(3238303131303031323031113336343132)
    0-1:24.3.0(190907210000)(00)(60)(1)(0-1:24.2.1)(m3)
    (04212.860)
    0-1:24.4.0(1)
    !
    
    

    You can see here the output of my energy meter wich is given every 10 seconds

    And this is the output when i am using the sketch with Mysensors,
    It is curently not connected because im am unable at the moment.
    The strange part is that the serial prints are not workig at this stage anymore or is this normal when using mysensors?

     
     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.0
    
    16 MCO:BGN:INIT NODE,CP=RNNNA---,VER=2.3.0
    25 TSM:INIT
    26 TSF:WUR:MS=0
    33 !TSM:INIT:TSP FAIL
    35 TSM:FAIL:CNT=1
    37 TSM:FAIL:DIS
    38 TSF:TDI:TSL
    10040 TSM:FAIL:RE-INIT
    10042 TSM:INIT
    10048 !TSM:INIT:TSP FAIL
    10051 TSM:FAIL:CNT=2
    10053 TSM:FAIL:DIS
    10054 TSF:TDI:TSL
    20057 TSM:FAIL:RE-INIT
    20059 TSM:INIT
    20065 !TSM:INIT:TSP FAIL
    20068 TSM:FAIL:CNT=3
    20070 TSM:FAIL:DIS
    20071 TSF:TDI:TSL
    30074 TSM:FAIL:RE-INIT
    30076 TSM:INIT
    30083 !TSM:INIT:TSP FAIL
    30086 TSM:FAIL:CNT=4
    30088 TSM:FAIL:DIS
    30089 TSF:TDI:TSL
    40092 TSM:FAIL:RE-INIT
    40094 TSM:INIT
    40100 !TSM:INIT:TSP FAIL
    40103 TSM:FAIL:CNT=5
    40105 TSM:FAIL:DIS
    40107 TSF:TDI:TSL
    50110 TSM:FAIL:RE-INIT
    50112 TSM:INIT
    50118 !TSM:INIT:TSP FAIL
    50121 TSM:FAIL:CNT=6
    50123 TSM:FAIL:DIS
    50124 TSF:TDI:TSL
    60127 TSM:FAIL:RE-INIT
    60129 TSM:INIT
    60135 !TSM:INIT:TSP FAIL
    60138 TSM:FAIL:CNT=7
    60140 TSM:FAIL:DIS
    60141 TSF:TDI:TSL
    120144 TSM:FAIL:RE-INIT
    120146 TSM:INIT
    120154 !TSM:INIT:TSP FAIL
    120156 TSM:FAIL:CNT=7
    120158 TSM:FAIL:DIS
    120160 TSF:TDI:TSL
    

    P.S
    I have done some testing also on RS485 and had the same situation.


  • Mod

    @toine33 yes this is normal. MySensors is unable to initialize the radio so it never reaches setup, nor loop.



  • You expect the baudrate to be 19200, but Mysensors also initialises the port at a baudrate. Maybe that one is done later and you should use the terminal on that baudrate?



  • Hey guys,
    Thanks for helping 🙂 . The sketch was working after i have deleted the Serial.begin in the void setup.

    void setup() {
    Serial.begin(19200);

    i only have some other issues at the moment haha,
    The value's from the gas meter / high an low elecktricity are showing wrong within Domoticz
    0_1567966720801_497ea466-8ee8-4bd4-be51-f4dc3f5c7099-image.png

    When i am doing /1000 on the send values of the GAS meter and elecktricity meters i am getting an beter value but i loose 3 decimals and cant see any calculated value by domoticz.
    Is there an option to send these decimals ?

    0_1567967331476_a16e0f3a-43fe-4ce7-9de6-46a76a1d0547-image.png

    #define MY_DEBUG 
    #define MY_RS485
    #define MY_RS485_DE_PIN 2
    #define MY_RS485_BAUD_RATE 19200
    #define MY_RS485_HWSERIAL Serial
    #define MY_NODE_ID 3
    
    #include <AltSoftSerial.h>
    #include <SPI.h>
    #include <MySensors.h>  
    
    AltSoftSerial altSerial;
    
    int msg[1];
    const uint64_t pipe = 0xE8E8F0F0E1LL;
    
    const int requestPin =  4;         
    char input; // incoming serial data (byte)
    bool readnextLine = false;
    #define BUFSIZE 500
    #define CHILD_ID_WATT 0
    #define CHILD_ID_KWH_LOW 1
    #define CHILD_ID_KWH_HIGH 2
    #define CHILD_ID_GAS 3
    #define CHILD_ID_CURRENT 4
    
    char buffer[BUFSIZE]; //Buffer for serial data to find \n .
    int bufpos = 0;
    long mEVLT = 0; //Meter reading Electrics - consumption low tariff
    long mEVHT = 0; //Meter reading Electrics - consumption high tariff
    long mEAV = 0;  //Meter reading Electrics - Actual consumption
    long mEAT = 0;  //Meter reading Electrics - Actual generated electricity (Solar panels)
    long mG = 0;   //Meter reading Gas
    
    MyMessage msgWatt(CHILD_ID_WATT, V_WATT);
    MyMessage msgKwhLow(CHILD_ID_KWH_LOW, V_KWH);      //Was V_KWH
    MyMessage msgKwhHigh(CHILD_ID_KWH_HIGH, V_KWH);     //Was V_KWH
    MyMessage msgGas(CHILD_ID_GAS, V_VOLUME);
    
    
    
    void setup() {
    //  Serial.begin(19200);
    //  delay(1000);
      
      altSerial.begin(9600);
      delay(1000);
    }
    
    
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Node", "1.0");
      present(CHILD_ID_WATT, S_POWER);
      present(CHILD_ID_KWH_LOW, S_POWER);
      present(CHILD_ID_KWH_HIGH, S_POWER);
      present(CHILD_ID_GAS, S_GAS);
    }
    
    
    
    void loop() {
      long tl = 0;
      long tld =0;
      if (altSerial.available()) {
          char input = altSerial.read();
          buffer[bufpos] = input&127;
          bufpos++;
          if (input == '\n') { // We received a new line (data up to \n)
            // 1-0:1.8.2 = Electricity consumption high tariff (DSMR v4.0)
            if (sscanf(buffer,"1-0:1.8.2(%ld%.%ld%*s" , &tl, &tld) >0 ) {
              tl *= 1000;
              tl += tld;
              mEVHT = tl;
              //mEVHT = tl * 1000 + tld;
              if (mEVHT > 0) {
      
                //mEVHT = 0;
              }
            }
      
      
    
            if (sscanf(buffer,"1-0:1.8.1(%ld.%ld" ,&tl, &tld)==2){
              tl *= 1000;
              tl += tld;
              mEVLT = tl;
      
              if (mEVLT > 0) {
      
      
              }
            }
    
    
      
            // 1-0:1.7.0 = Electricity consumption actual usage (DSMR v4.0)
            if (sscanf(buffer,"1-0:1.7.0(%ld.%ld" ,&tl , &tld) == 2)
            { 
              mEAV = (tl*1000)+tld*10;            
              if (mEAV > 0) {
      
              }
            }
    
    
    
    
    
    
    
    /* Geeft actuele waarde door maar doet geen compare
    if (sscanf(buffer,"(%ld.%ld" , &tl, &tld)==2 ) 
          {   mG = (tl*1000.0)+tld;
          mG = mG/1000;
          }
    */
    
    
    
    //Gastand uitlezen
    if (sscanf(buffer,"(%ld.%ld" , &tl, &tld)==2 ) 
          {   mG = (tl*1000.0)+tld;
          mG = mG;
          }
    
    
    
    
      
            // Empty buffer again (whole array)
            for (int i=0; i<500; i++)
            { 
              buffer[i] = 0;
            }
            bufpos = 0;
      
          }
           
          if (input == '!') {   //uitroepteken geeft einde van telegram aan, dus we gaan data versturen
            #ifdef DEBUG
              printData();
            #endif
            send(msgWatt.set(mEAV));
            send(msgKwhLow.set(mEVLT));
            send(msgKwhHigh.set(mEVHT));
            send(msgGas.set(mG));
            mEVHT=0;
            mEVLT = 0;
            mEAV = 0;
            mG = 0;
            //client.stop();
          } //Einde vraagteken detectie   
      
        } 
    
    }
    
    
     
    

    Thanks !


  • Mod

    Nice work @toine33
    Use set(value, numberOfDecimals)

    Example:

    send(msgWatt.set(mEAV, 3));
    

    Documentation: https://www.mysensors.org/apidocs/MyMessage_8h.html#a8af6ca9ee9a61b5954e405a2ae7de361



  • @mfalkvidd
    Sorry for asking , but as you already noticed i am not super familiar to the arduino coding haha.

    So i have tried send(msgWatt.set(mEAV, 3));
    But the only output i am receiving is something like this,

    TSF:MSG:SEND,3-3-0-0,s=3,c=1,t=35,pt=7,l=5,sg=0,ft=0,st=OK:4213752.000

    What i would like to archieve is an value like
    TSF:MSG:SEND,3-3-0-0,s=3,c=1,t=35,pt=7,l=5,sg=0,ft=0,st=OK:4213.752

    I just would like to ad an decimal somehow and send this to Domoticz.


  • Mod

    @toine33 asking is exactly what the forum is here for 🙂
    This should work (note: .0 is a "trick" to let the compiler know we want a floating point / decimal number)

    send(msgWatt.set(mEAV / 1000.0, 3));
    


  • @mfalkvidd
    Thank you so much 😄 Finnaly it is working as it should do!

    #define MY_DEBUG 
    #define MY_RS485
    #define MY_RS485_DE_PIN 2
    #define MY_RS485_BAUD_RATE 19200
    #define MY_RS485_HWSERIAL Serial
    #define MY_NODE_ID 3
    
    #include <AltSoftSerial.h>
    #include <SPI.h>
    #include <MySensors.h>  
    
    AltSoftSerial altSerial;
    
    int msg[1];
    const uint64_t pipe = 0xE8E8F0F0E1LL;
    
    const int requestPin =  4;         
    char input; // incoming serial data (byte)
    bool readnextLine = false;
    #define BUFSIZE 500
    #define CHILD_ID_WATT 0
    #define CHILD_ID_KWH_LOW 1
    #define CHILD_ID_KWH_HIGH 2
    #define CHILD_ID_GAS 3
    #define CHILD_ID_CURRENT 4
    
    char buffer[BUFSIZE]; //Buffer for serial data to find \n .
    int bufpos = 0;
    long mEVLT = 0; //Meter reading Electrics - consumption low tariff
    long mEVHT = 0; //Meter reading Electrics - consumption high tariff
    long mEAV = 0;  //Meter reading Electrics - Actual consumption
    long mEAT = 0;  //Meter reading Electrics - Actual generated electricity (Solar panels)
    long mG = 0;   //Meter reading Gas
    
    
    MyMessage msgWatt(CHILD_ID_WATT, V_WATT);
    MyMessage msgKwhLow(CHILD_ID_KWH_LOW, V_KWH);      //Was V_KWH
    MyMessage msgKwhHigh(CHILD_ID_KWH_HIGH, V_KWH);     //Was V_KWH
    MyMessage msgGas(CHILD_ID_GAS, V_VOLUME);
    
    
    
    void setup() {
    //  Serial.begin(19200);
    //  delay(1000);
      
      altSerial.begin(9600);
      delay(1000);
    }
    
    
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Node", "1.0");
      present(CHILD_ID_WATT, S_POWER);
      present(CHILD_ID_KWH_LOW, S_POWER);
      present(CHILD_ID_KWH_HIGH, S_POWER);
      present(CHILD_ID_GAS, S_GAS);
    }
    
    
    
    void loop() {
      long tl = 0;
      long tld =0;
      if (altSerial.available()) {
          char input = altSerial.read();
          buffer[bufpos] = input&127;
          bufpos++;
          if (input == '\n') { // We received a new line (data up to \n)
            // 1-0:1.8.2 = Electricity consumption high tariff (DSMR v4.0)
    
            
            if (sscanf(buffer,"1-0:1.8.2(%ld.%ld" , &tl, &tld) >0 ) {
              tl *= 1000;
              tl += tld;
              mEVHT = tl;
              //mEVHT = tl * 1000 + tld;
              if (mEVHT > 0) {
      
                //mEVHT = 0;
              }
            }
      
      
    
            if (sscanf(buffer,"1-0:1.8.1(%ld.%ld" ,&tl, &tld)==2){
              tl *= 1000;
              tl += tld;
              mEVLT = tl;
      
              if (mEVLT > 0) {
      
      
              }
            }
    
    
      
            // 1-0:1.7.0 = Electricity consumption actual usage (DSMR v4.0)
            if (sscanf(buffer,"1-0:1.7.0(%ld.%ld" ,&tl , &tld) == 2)
            { 
              mEAV = (tl*1000)+tld*10;            
              if (mEAV > 0) {
      
              }
            }
    
    
    
    
    //Gastand uitlezen
    
    if (sscanf(buffer,"(%ld.%ld" , &tl, &tld)==2 ) 
          {   mG = (tl*1000.0)+tld;
          mG = mG;
          }
    
    
    
    
      
            // Empty buffer again (whole array)
            for (int i=0; i<500; i++)
            { 
              buffer[i] = 0;
            }
            bufpos = 0;
      
          }
           
          if (input == '!') {   //uitroepteken geeft einde van telegram aan, dus we gaan data versturen
            #ifdef DEBUG
              printData();
            #endif
            send(msgWatt.set(mEAV));
            send(msgKwhLow.set(mEVLT / 1000.0, 3)); 
            send(msgKwhHigh.set(mEVHT / 1000.0, 3));
            send(msgGas.set(mG / 1000.0, 3));
            mEVHT=0;
            mEVLT = 0;
            mEAV = 0;
            mG = 0;
            //client.stop();
          } //Einde vraagteken detectie   
      
        } 
    
    }
    
    
     
    

    And here an picture how it is showing up in domoticz:

    0_1568053520513_cc789582-9497-47ae-a278-d906a1b3a0fd-image.png


Log in to reply
 

Suggested Topics

  • 3
  • 4
  • 24
  • 2
  • 2
  • 10

22
Online

11.2k
Users

11.1k
Topics

112.5k
Posts