Sketch presentation / Vera inclusion



  • Hello,
    I have been working for a while now trying to figure out why my sensor is unable to be properly recognized by my Vera server. The topology is simple: the Vera communicates with the Gateway via Ethernet, and the Gateway communicates with the sensor (Arduino Nano-based) via RF24 radios. I have verified that the everything aside from my code (Vera, network, Gateway, Arduinos, radios, etc) works by running a one of the example sensor sketches - it registers in the Vera during inclusion mode without issue. My code, on the other hand, is discovered as two devices, neither of which appears to actually have anything to do with my code.

    Any insight into the issue would be most appreciated.

    This is the present state of the code:

    #define BLABBERATOR_VERSION "0.5"
    
    
    #define SPI_SS  10  // SPI Slave Select
    #define SPI_MOSI 11 // SPI Master Out, Slave In
    #define SPI_MISO 12 // SPI Master In, Slave Out
    #define SPI_SCK  13 // SPI Synchronous Clock
    
    #include <MyConfig.h>
    #include <MySensors.h>
    #include <SPI.h>
    #include <SoftwareSerial.h>
    
    
    /******* Emic Defines, Globals, and Functions *************/
    #define EMIC_RXPIN   3  // Serial input (connects to Emic 2's SOUT pin)
    #define EMIC_TXPIN   4  // Serial output (connects to Emic 2's SIN pin)
    SoftwareSerial emicSerial =  SoftwareSerial(EMIC_RXPIN, EMIC_TXPIN) ;
    void emicSay(char* szStr)
    {
      unsigned long lStart ;  //Time that the last character was sent to the Emic
    
      Serial.print(F("Saying \"")) ;
      Serial.print(szStr) ;
      Serial.print(F("\"... ")) ;
      Serial.flush() ;
    
      //Send the string to the Emic
      emicSerial.listen() ;
      emicSerial.print('S') ;
      emicSerial.print(szStr) ;
      lStart = millis() ;   //Record the time
      emicSerial.print('\n') ;
      emicSerial.flush() ;
    
      //Wait for the Emic to finish
      while (emicSerial.read() != ':')
      {
        if (millis() - lStart > 5000)
        {//Wait for as long as 5 seconds before declaring defeat
          Serial.println(F("timeout waiting for the Emic to finish")) ;
          Serial.flush() ;
          return ;
        }
      }
      Serial.println(F("done")) ;
      Serial.flush() ;
    }
    
    /******* MySensor Defines, Globals, and Callback *************/
    #define NODE_ID 10
    
    
    //Callback function to receive incoming messages
    void receive(const MyMessage &message)
    {
      char * pszMsg ;
    
      //Handle acknowledgement messages
      if (message.isAck())
      {
        Serial.println(F("Ack received from the gateway")) ;
        Serial.flush() ;
      }
    
      //Handle messages by type
      switch (message.type)
      {
        case V_TEXT:    //V_CUSTOM is a guess at a reasonable message type
          pszMsg = (char*)message.getString() ; //This may or may not work
          if (pszMsg != NULL) //Check to see if the returned pointer is legit
          {
            if (pszMsg[0] != (char)0) //Check to see if the string is empty
            {
              emicSay(pszMsg) ;
            }
          }
          break ;
        default:
          Serial.print(F("Unhandled message of type ")) ;
          Serial.println(message.type) ;
          Serial.flush() ;
      }
    }
    
    /******* Stock Arduino Entry Points *************/
    void setup() {
      pinMode(SPI_SS, OUTPUT) ;   //SPI SS pin - set to output to prevent floating asserts stopping SPI
    
      /*
       * Debug serial port initialization (this is the USB link back to the programming computer)
       */
      Serial.begin(MY_BAUD_RATE); //Initialize using whatever the MySensors library is using to avoid conflict
      // this check is only needed on the Leonardo:
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
    
      delay(2000) ; //Wait 2 seconds to let the software on the other end of the link to get ready
      
      Serial.print(F("Blabberator booting: version ")) ;
      Serial.println(BLABBERATOR_VERSION) ;
      Serial.flush() ;
    
      /*
       * NOTE: This code was shamelessly stolen from the Emic demo
        When the Emic 2 powers on, it takes about 3 seconds for it to successfully
        initialize. It then sends a ":" character to indicate it's ready to accept
        commands. If the Emic 2 is already initialized, a CR will also cause it
        to send a ":"
      */
      Serial.print(F("Initializing Emic... ")) ;
      emicSerial.begin(9600);
      emicSerial.listen() ;                // Route incoming serial to this object
      emicSerial.print('\n') ;             // Send a CR in case the system is already up
      while (emicSerial.read() != ':') ;   // When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it
      delay(10) ;                          // Short delay
      emicSerial.flush() ;                 // Flush the receive buffer
      Serial.println(F("done")) ;
      Serial.flush() ;
    }
    
    void presentation()  
    {
      /*
       * MySensor node initialization
       * 
       * Sadly, these functions to not have a return value to indicate how they made out.
       */
      Serial.print(F("Initializing MySensor node... ")) ;
      sendSketchInfo("Blabberator", BLABBERATOR_VERSION);
      present(NODE_ID, S_INFO); 
      Serial.print(F("done")) ;
      Serial.flush() ;
    }
    
    void loop() {
      //Nothing to see here folks, move along
    }```

  • Admin

    Did you install device files for S-INFO?

    Cam't find any defines configuring radio type or if this is a gateway device.



  • S_INFO is defined in the library... is there more that has to be done to make use of it?

    The device isn't a gateway. What kind of defines would one expect to use for a RF24L radio?


  • Admin

    Did you install these on Vera?
    https://github.com/mysensors/Vera/tree/development/LcdText

    #define MY_RADIO_NRF24

    Before the MySensors include.



  • @hek Thanks! I'll give it a shot!



  • Working with ejtb, here is the updated code. We did upload those files and bounced the lua, However we were unable to get a device registered from the Vera. Any thoughts from this point?

    /*
     * Blabberator.ino
     * 
     * 
     * June 2016
     * 
     */
    
    #define BLABBERATOR_VERSION "0.5"
    
    
    #define SPI_SS  10  // SPI Slave Select
    #define SPI_MOSI 11 // SPI Master Out, Slave In
    #define SPI_MISO 12 // SPI Master In, Slave Out
    #define SPI_SCK  13 // SPI Synchronous Clock
    
    #include <MyConfig.h>
    #include <MySensors.h>
    #include <SPI.h>
    #include <SoftwareSerial.h>
    
    
    /******* Emic Defines, Globals, and Functions *************/
    #define EMIC_RXPIN   3  // Serial input (connects to Emic 2's SOUT pin)
    #define EMIC_TXPIN   4  // Serial output (connects to Emic 2's SIN pin)
    SoftwareSerial emicSerial =  SoftwareSerial(EMIC_RXPIN, EMIC_TXPIN) ;
    void emicSay(char* szStr)
    {
      unsigned long lStart ;  //Time that the last character was sent to the Emic
    
      Serial.print(F("Saying \"")) ;
      Serial.print(szStr) ;
      Serial.print(F("\"... ")) ;
      Serial.flush() ;
    
      //Send the string to the Emic
      emicSerial.listen() ;
      emicSerial.print('S') ;
      emicSerial.print(szStr) ;
      lStart = millis() ;   //Record the time
      emicSerial.print('\n') ;
      emicSerial.flush() ;
    
      //Wait for the Emic to finish
      while (emicSerial.read() != ':')
      {
        if (millis() - lStart > 5000)
        {//Wait for as long as 5 seconds before declaring defeat
          Serial.println(F("timeout waiting for the Emic to finish")) ;
          Serial.flush() ;
          return ;
        }
      }
      Serial.println(F("done")) ;
      Serial.flush() ;
    }
    
    /******* MySensor Defines, Globals, and Callback *************/
    #define NODE_ID 10
    
    
    //Callback function to receive incoming messages
    void receive(const MyMessage &message)
    {
      char * pszMsg ;
    
      //Handle acknowledgement messages
      if (message.isAck())
      {
        Serial.println(F("Ack received from the gateway")) ;
        Serial.flush() ;
      }
    
      //Handle messages by type
      switch (message.type)
      {
        case V_TEXT:    //V_CUSTOM is a guess at a reasonable message type
          pszMsg = (char*)message.getString() ; //This may or may not work
          if (pszMsg != NULL) //Check to see if the returned pointer is legit
          {
            if (pszMsg[0] != (char)0) //Check to see if the string is empty
            {
              emicSay(pszMsg) ;
            }
          }
          break ;
        default:
          Serial.print(F("Unhandled message of type ")) ;
          Serial.println(message.type) ;
          Serial.flush() ;
      }
    }
    
    /******* Stock Arduino Entry Points *************/
    void setup() {
      pinMode(SPI_SS, OUTPUT) ;   //SPI SS pin - set to output to prevent floating asserts stopping SPI
    
      /*
       * Debug serial port initialization (this is the USB link back to the programming computer)
       */
      Serial.begin(MY_BAUD_RATE); //Initialize using whatever the MySensors library is using to avoid conflict
      // this check is only needed on the Leonardo:
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
    
      delay(2000) ; //Wait 2 seconds to let the software on the other end of the link to get ready
      
      Serial.print(F("Blabberator booting: version ")) ;
      Serial.println(BLABBERATOR_VERSION) ;
      Serial.flush() ;
    
      /*
       * NOTE: This code was shamelessly stolen from the Emic demo
        When the Emic 2 powers on, it takes about 3 seconds for it to successfully
        initialize. It then sends a ":" character to indicate it's ready to accept
        commands. If the Emic 2 is already initialized, a CR will also cause it
        to send a ":"
      */
      Serial.print(F("Initializing Emic... ")) ;
      emicSerial.begin(9600);
      emicSerial.listen() ;                // Route incoming serial to this object
      emicSerial.print('\n') ;             // Send a CR in case the system is already up
      while (emicSerial.read() != ':') ;   // When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it
      delay(10) ;                          // Short delay
      emicSerial.flush() ;                 // Flush the receive buffer
      Serial.println(F("done")) ;
      Serial.flush() ;
    }
    
    void presentation()  
    {
      /*
       * MySensor node initialization
       * 
       * Sadly, these functions to not have a return value to indicate how they made out.
       */
      Serial.print(F("Initializing MySensor node... ")) ;
      sendSketchInfo("Blabberator", BLABBERATOR_VERSION);
      present(NODE_ID, S_INFO); 
      Serial.print(F("done")) ;
      Serial.flush() ;
    }
    
    void loop() {
      //Nothing to see here folks, move along
    }```

  • Hero Member

    Try running the "ClearEepromConfig" example sketch from MySensors examples and then try your sketch again. Might be that there is an old "NODE_ID" being used that is conflicting with another node. If you want to use static NODE_ID you should put the following before the MySensors.h include in your sketch:

    #define MY_NODE_ID 14

    You are also stil missing the

    #define MY_RADIO_NRF24

    Before the MySensors include that @hek pointed out.



  • @korttoma said:

    Try running the "ClearEepromConfig" example sketch from MySensors examples and then try your sketch again. Might be that there is an old "NODE_ID" being used that is conflicting with another node. If you want to use static NODE_ID you should put the following before the MySensors.h include in your sketch:

    #define MY_NODE_ID 14

    You are also stil missing the

    #define MY_RADIO_NRF24

    Before the MySensors include that @hek pointed out.

    ^^ this - I've had this happen before (just last night actually) but i recalled from when it happened in the past, found out it was using a dupe ID, ran eeprom sketch.. good to go now.


Log in to reply
 

Suggested Topics

  • 8
  • 7
  • 3
  • 9
  • 10
  • 7
  • 11

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts