Raw binary transmission



  • Hi All

    Just getting to grips with MySensors.

    Is there a means to transmit raw binary data. In particular the handling of the transmission from the gateway to the controller - maybe as a hexadecimal encoded string of characters?

    I wish to send some bytes of bit flags to my custom controller (which publishes onto MQTT), this controller parses the serial port looking for carriage return ('\n') characters to split the received packets. This obviously presents a problem if the payload data actually contains the '\n' carriage return as a valid bit flag value, splitting the packet incorrectly. (Not to mention all the other control characters that may be received).

    Is such a feature already possibly, or do I need to investigate the gateway code and implement this myself?

    Cheers
    Gizi


  • Admin

    If you set payload using the following:

    https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MyMessage.cpp#L170

    The payload will be serialised into hex string when it reaches the gateway.



  • Ok, so I am obviously missing something here, I saw you mention this solution in my searches, but I am unable to output a serialised hex string. My test code below appears to be setting the packetType correctly for the different types but for P_CUSTOM my results are an empty string...

    #include <MySensor.h>
    #include <SPI.h>
    
    #define CHILD_ID 3
    
    #define MS_CEPIN 8
    #define MS_CSPIN 7
    
    MySensor gw(MS_CEPIN, MS_CSPIN);
    
    unsigned int counter=0;
    unsigned int counter2=0;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_VAR1);
    
    void setup()
    {
    	gw.begin(NULL, 99);
    	gw.present(CHILD_ID, S_CUSTOM);
    }
    
    // some random buffer for testing
    char buffer[10] = {'H','e','l','l','o',' ','Y','o','u','\0'};
    
    void loop()
    {
    	//send something periodically
    	counter++;
    	if (counter == 0) {
    		counter2++;
    		gw.send(msg.set(buffer));	//pt=0 > P_STRING
    		gw.send(msg.set(counter2));	//pt=3 > P_UINT16
    		gw.send(msg.set(buffer,5)); //pt=6 > P_CUSTOM
    	}
    }
    
    

    My gateway returns the following when raw dumping the received serial data (this was the 61st send)...

    mysensorsmqtt: serial recv - 0;0;3;0;9;read: 99-99-0 s=3,c=1,t=24,pt=0,l=9:Hello You
    mysensorsmqtt: serial recv - 99;3;1;0;24;Hello You
    
    mysensorsmqtt: serial recv - 0;0;3;0;9;read: 99-99-0 s=3,c=1,t=24,pt=3,l=2:61
    mysensorsmqtt: serial recv - 99;3;1;0;24;61
    
    mysensorsmqtt: serial recv - 0;0;3;0;9;read: 99-99-0 s=3,c=1,t=24,pt=6,l=5:
    mysensorsmqtt: serial recv - 99;3;1;0;24;
    
    

    So the "pt=" seems to be set as expected, but no serialised hex. I must be missing something simple.


  • Admin

    I haven't fiddled with the MQTT gateway much. Do you see the same problem using the SerialGateway?

    getString must provide a buffer...



  • Sorry for the confusion, this is using the SerialGateway - I have my own code server side parsing the serial responses. Everything after the 'mysensorsmqtt: serial recv -' is just dumps of the serial string received.

    Ill dig a little deeper into the code and look at the MyGateway side of the code, everything seemed in order but I will do some debugging.


Log in to reply
 

Suggested Topics

  • 1
  • 2
  • 2
  • 2
  • 10
  • 5

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts