Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Lucky65
    3. Best
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Best posts made by Lucky65

    • Weird protocol version mismatch

      Hello there, complete newby here to MySensors. I have been spending quite some time troubleshooting a particular issue that looks like a message protocol version mismatch but I have no idea why.

      Setup:

      • Miniwireless RFM69cw running the following sketch:
      #define MY_DEBUG
      #define MY_RADIO_RFM69
      #define MY_RFM69_NEW_DRIVER
      //#define MY_RFM69_ENABLE_ENCRYPTION
      #define MY_DEBUG_VERBOSE_RFM69
      #define MY_RADIO_RFM69
      #define MY_RFM69_FREQUENCY RFM69_915MHZ
      #define MY_RFM69_CS_PIN 10
      #define MY_RFM69_IRQ_PIN 2
      #define MY_BAUD_RATE 19200
      #include <MySensors.h>
      
      • Adafruit RFM69 Bonnet on Raspberry Pi 3 with the following configuration:
      ./configure \
              --spi-driver=SPIDEV \
              --spi-spidev-device=/dev/spidev0.0 \
              --my-transport=rfm69 \
              --my-rfm69-frequency=915 \
              --my-rfm69-irq-pin=15 \
              --my-rfm69-cs-pin=26 \
              --my-is-rfm69hw \
              --my-gateway=ethernet \
              --my-port=5003 \
              --my-debug=enable \
              --extra-cxxflags="-DMY_RFM69_RST_PIN=22 -DMY_DEBUG_VERBOSE_TRANSPORT_HAL"
      

      Because of the nature of my problem I added a simple printf statement in the RFM69_receive function in RFM69_new.cpp:

      LOCAL uint8_t RFM69_receive(uint8_t *buf, const uint8_t maxBufSize)
      {
              const uint8_t payloadLen = min(RFM69.currentPacket.payloadLen, maxBufSize);
              const uint8_t sender = RFM69.currentPacket.header.sender;
              const rfm69_sequenceNumber_t sequenceNumber = RFM69.currentPacket.header.sequenceNumber;
              const uint8_t controlFlags = RFM69.currentPacket.header.controlFlags;
              const rfm69_RSSI_t RSSI = RFM69.currentPacket.RSSI;
      
      printf("len=%d snd=%d seq=%d flg=%d rss=%d\n", payloadLen, sender, sequenceNumber, controlFlags, RSSI);
              if (buf != NULL) {
                      (void)memcpy((void *)buf, (void *)&RFM69.currentPacket.payload, payloadLen);
              }
              // clear data flag
              RFM69.dataReceived = false;
              if (RFM69_getACKRequested(controlFlags) && !RFM69_getACKReceived(controlFlags)) {
      #if defined(MY_GATEWAY_FEATURE) && (F_CPU>16*1000000ul)
                      // delay for fast GW and slow nodes
                      delay(50);
      #endif
                      RFM69_sendACK(sender, sequenceNumber, RSSI);
              }
              return payloadLen;
      }
      

      The debug output of the mysgw process is as follows immediately after starting and then a bit later when the miniwireless module starts up:

      pi@rfm69-1:~/MySensors $ sudo ./bin/mysgw
      May 24 01:27:58 INFO  Starting gateway...
      May 24 01:27:58 INFO  Protocol version - 2.3.2
      May 24 01:27:58 DEBUG MCO:BGN:INIT GW,CP=RPNGL---,FQ=NA,REL=255,VER=2.3.2
      May 24 01:27:58 DEBUG TSF:LRT:OK
      May 24 01:27:58 DEBUG TSM:INIT
      May 24 01:27:58 DEBUG TSF:WUR:MS=0
      May 24 01:27:58 DEBUG THA:INIT
      May 24 01:27:58 DEBUG TSM:INIT:TSP OK
      May 24 01:27:58 DEBUG TSM:INIT:GW MODE
      May 24 01:27:58 DEBUG THA:SAD:ADDR=0
      May 24 01:27:58 DEBUG TSM:READY:ID=0,PAR=0,DIS=0
      May 24 01:27:58 DEBUG MCO:REG:NOT NEEDED
      May 24 01:27:58 DEBUG Listening for connections on :5003
      May 24 01:27:58 DEBUG MCO:BGN:STP
      May 24 01:27:58 DEBUG THA:SAN:RES=1
      May 24 01:27:58 DEBUG MCO:BGN:INIT OK,TSP=1
      May 24 01:27:58 DEBUG TSM:READY:NWD REQ
      May 24 01:27:58 DEBUG THA:SND:MSG=0000FF020314FF
      May 24 01:27:58 DEBUG THA:SND:MSG LEN=7,RES=1
      May 24 01:27:58 DEBUG ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
      May 24 01:28:21 DEBUG THA:DATA:AVAIL
      len=7 snd=32 seq=100 flg=1 rss=62
      May 24 01:28:21 DEBUG THA:RCV:MSG=64FF020307FF00
      May 24 01:28:21 DEBUG !THA:RCV:PVER=3
      May 24 01:28:22 DEBUG THA:DATA:AVAIL
      len=7 snd=32 seq=100 flg=2 rss=71
      May 24 01:28:22 DEBUG THA:RCV:MSG=64FF020307FF00
      May 24 01:28:22 DEBUG !THA:RCV:PVER=3
      May 24 01:28:23 DEBUG THA:DATA:AVAIL
      len=7 snd=32 seq=100 flg=3 rss=66
      May 24 01:28:23 DEBUG THA:RCV:MSG=64FF020307FF00
      May 24 01:28:23 DEBUG !THA:RCV:PVER=3
      May 24 01:28:25 DEBUG THA:DATA:AVAIL
      len=7 snd=32 seq=100 flg=4 rss=66
      May 24 01:28:25 DEBUG THA:RCV:MSG=64FF020307FF00
      May 24 01:28:25 DEBUG !THA:RCV:PVER=3
      

      while the miniwireless output on the Arduino serial monitor is:

       
       __  __       ____
      |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
      | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
      | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
      |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
              |___/                      2.3.2
      
      104 MCO:BGN:INIT NODE,CP=RPNNA---,FQ=8,REL=255,VER=2.3.2
      167 TSM:INIT
      174 TSF:WUR:MS=0
      184 RFM69:INIT
      192 RFM69:INIT:PIN,CS=10,IQP=2,IQN=0
      212 RFM69:PTX:LEVEL=5 dBm
      225 TSM:INIT:TSP OK
      235 TSF:SID:OK,ID=100
      247 TSM:FPAR
      256 RFM69:SWR:SEND,TO=255,SEQ=0,RETRY=0
      276 RFM69:CSMA:RSSI=-84
      ...
      776 RFM69:CSMA:RSSI=-83
      794 ?TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2834 !TSM:FPAR:NO REPLY
      2846 TSM:FPAR
      2854 RFM69:SWR:SEND,TO=255,SEQ=1,RETRY=0
      2877 RFM69:CSMA:RSSI=-84
      ...
      3371 RFM69:CSMA:RSSI=-84
      3391 ?TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      5431 !TSM:FPAR:NO REPLY
      5443 TSM:FPAR
      5451 RFM69:SWR:SEND,TO=255,SEQ=2,RETRY=0
      5474 RFM69:CSMA:RSSI=-83
      ...
      5967 RFM69:CSMA:RSSI=-82
      5988 ?TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      8028 !TSM:FPAR:NO REPLY
      8040 TSM:FPAR
      8048 RFM69:SWR:SEND,TO=255,SEQ=3,RETRY=0
      8071 RFM69:CSMA:RSSI=-83
      ...
      8564 RFM69:CSMA:RSSI=-83
      8585 ?TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      10625 !TSM:FPAR:FAIL
      10635 TSM:FAIL:CNT=1
      10647 TSM:FAIL:DIS
      10657 TSF:TDI:TSL
      10665 RFM69:RSL
      

      As you can see the fields in my printf statement don't seem to be correct. The sequence number seems to be decoded as the flags field, and the sender as the sequence number. I'm running from the master branch on github and the current Arduino MySensors library.
      For the life of me I cannot think of what else was changed. I believe the install is as clean as it can be starting from a clean Raspbian and latest pull from github. The only other change I made was in RFM69_new.cpp to enable the RFM69_CS_PIN as per instruction in a previous thread. Thank you for that, the support and documentation on this site is really very good.
      It's probably something silly I did, so my apologies in advance.

      posted in Troubleshooting
      Lucky65
      Lucky65
    • RE: Weird protocol version mismatch

      OK, did some more troubleshooting.

      1. Confirmed that using a Moteino has exactly the same result with the previous code
      2. I added the basic send/receive debugging in the RFM69_new.cpp on both the Arduino side and the Raspberry Pi side:
      LOCAL uint8_t RFM69_receive(uint8_t *buf, const uint8_t maxBufSize)
      {
      	const uint8_t payloadLen = min(RFM69.currentPacket.payloadLen, maxBufSize);
      	const uint8_t sender = RFM69.currentPacket.header.sender;
      	const rfm69_sequenceNumber_t sequenceNumber = RFM69.currentPacket.header.sequenceNumber;
      	const uint8_t controlFlags = RFM69.currentPacket.header.controlFlags;
      	const rfm69_RSSI_t RSSI = RFM69.currentPacket.RSSI;
      
      	DEBUG_OUTPUT(PSTR("LEN=%" PRIu8 ",DST=%" PRIu8 ",VER=%" PRIu8 ",SND=%" PRIu8 ",FLG=%" PRIu8 ",SEQ=%" PRIu8 "\n"),
      		(int)RFM69.currentPacket.header.packetLen,
      		(int)RFM69.currentPacket.header.recipient,
      		(int)RFM69.currentPacket.header.version,
      		(int)RFM69.currentPacket.header.sender,
      		(int)RFM69.currentPacket.header.controlFlags,
      		(int)RFM69.currentPacket.header.sequenceNumber);
      
      	if (buf != NULL) {
      		(void)memcpy((void *)buf, (void *)&RFM69.currentPacket.payload, payloadLen);
      	}
      	// clear data flag
      	RFM69.dataReceived = false;
      	if (RFM69_getACKRequested(controlFlags) && !RFM69_getACKReceived(controlFlags)) {
      #if defined(MY_GATEWAY_FEATURE) && (F_CPU>16*1000000ul)
      		// delay for fast GW and slow nodes
      		delay(50);
      #endif
      		RFM69_sendACK(sender, sequenceNumber, RSSI);
      	}
      	return payloadLen;
      }
      

      and

      LOCAL bool RFM69_sendFrame(rfm69_packet_t *packet, const bool increaseSequenceCounter)
      {
      	// ensure we are in RX for correct RSSI sampling, dirty hack to enforce rx restart :)
      	RFM69.radioMode = RFM69_RADIO_MODE_STDBY;
      	(void)RFM69_setRadioMode(RFM69_RADIO_MODE_RX);
      	delay(1); // timing for correct RSSI sampling
      	const uint32_t CSMA_START_MS = hwMillis();
      	while (!RFM69_channelFree() &&
      	        ((hwMillis() - CSMA_START_MS) < MY_RFM69_CSMA_TIMEOUT_MS)) {
      		doYield();
      	}
      	// set radio to standby to load fifo
      	(void)RFM69_setRadioMode(RFM69_RADIO_MODE_STDBY);
      	if (increaseSequenceCounter) {
      		// increase sequence counter, overflow is ok
      		RFM69.txSequenceNumber++;
      	}
      	// clear FIFO and flags
      	RFM69_clearFIFO();
      	// assign sequence number
      	packet->header.sequenceNumber = RFM69.txSequenceNumber;
      
      	DEBUG_OUTPUT(PSTR("LEN=%" PRIu8 ",DST=%" PRIu8 ",VER=%" PRIu8 ",SND=%" PRIu8 ",FLG=%" PRIu8 ",SEQ=%" PRIu8 "\n"),
      		(int)packet->header.packetLen,
      		(int)packet->header.recipient,
      		(int)packet->header.version,
      		(int)packet->header.sender,
      		(int)packet->header.controlFlags,
      		(int)packet->header.sequenceNumber);
      
      	// write packet
      	const uint8_t finalLen = packet->payloadLen + RFM69_HEADER_LEN; // including length byte
      	(void)RFM69_burstWriteReg(RFM69_REG_FIFO, packet->data, finalLen);
      
      	// send message
      	(void)RFM69_setRadioMode(RFM69_RADIO_MODE_TX); // irq upon txsent
      	const uint32_t txStartMS = hwMillis();
      	while (!RFM69_irq && (hwMillis() - txStartMS < MY_RFM69_TX_TIMEOUT_MS)) {
      		doYield();
      	};
      	return RFM69_irq;
      }
      

      On the Arduino (Moteino) side I removed the MY_DEBUG_VERBOSE_RFM69 define to reduce the debug output and changed node ID to 99:

       __  __       ____
      |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
      | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
      | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
      |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
              |___/                      2.3.2
      
      16 MCO:BGN:INIT NODE,CP=RPNNA---,FQ=16,REL=255,VER=2.3.2
      26 TSM:INIT
      28 TSF:WUR:MS=0
      29 TSM:INIT:TSP OK
      31 TSM:INIT:STATID=99
      33 TSF:SID:OK,ID=99
      35 TSM:FPAR
      537 LEN=12,DST=255,VER=1,SND=99,FLG=32,SEQ=1
      544 ?TSF:MSG:SEND,99-99-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2551 !TSM:FPAR:NO REPLY
      2553 TSM:FPAR
      3055 LEN=12,DST=255,VER=1,SND=99,FLG=32,SEQ=2
      3062 ?TSF:MSG:SEND,99-99-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      5069 !TSM:FPAR:NO REPLY
      5071 TSM:FPAR
      5112 LEN=12,DST=255,VER=1,SND=99,FLG=32,SEQ=3
      5120 ?TSF:MSG:SEND,99-99-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      7128 !TSM:FPAR:NO REPLY
      7130 TSM:FPAR
      7171 LEN=12,DST=255,VER=1,SND=99,FLG=32,SEQ=4
      7178 ?TSF:MSG:SEND,99-99-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      9186 !TSM:FPAR:FAIL
      9187 TSM:FAIL:CNT=1
      9189 TSM:FAIL:DIS
      9191 TSF:TDI:TSL
      

      The mysgw output for those exact messages:

      May 24 19:52:54 DEBUG THA:DATA:AVAIL
      May 24 19:52:54 DEBUG LEN=12,DST=255,VER=99,SND=32,FLG=1,SEQ=99
      May 24 19:52:54 DEBUG THA:RCV:MSG=63FF020307FF00
      May 24 19:52:54 DEBUG !THA:RCV:PVER=3
      May 24 19:52:57 DEBUG THA:DATA:AVAIL
      May 24 19:52:57 DEBUG LEN=12,DST=255,VER=99,SND=32,FLG=2,SEQ=99
      May 24 19:52:57 DEBUG THA:RCV:MSG=63FF020307FF00
      May 24 19:52:57 DEBUG !THA:RCV:PVER=3
      May 24 19:52:59 DEBUG THA:DATA:AVAIL
      May 24 19:52:59 DEBUG LEN=12,DST=255,VER=99,SND=32,FLG=3,SEQ=99
      May 24 19:52:59 DEBUG THA:RCV:MSG=63FF020307FF00
      May 24 19:52:59 DEBUG !THA:RCV:PVER=3
      May 24 19:53:01 DEBUG THA:DATA:AVAIL
      May 24 19:53:01 DEBUG LEN=12,DST=255,VER=99,SND=32,FLG=4,SEQ=99
      May 24 19:53:01 DEBUG THA:RCV:MSG=63FF020307FF00
      May 24 19:53:01 DEBUG !THA:RCV:PVER=3
      

      So there is some kind of misalignment in the message header. Is there some setting that modifies the header, like maybe a meshing flag or mode? I quickly lost my way digging in the lower level transport abstractions. I'm also convinced that there is some setting that I'm not using correctly. More than happy to try whatever anyone can come up.
      BTW I did a completely clean install of the MySensors github files on the Pi and modified only the RFM69_new.cpp file after that.

      posted in Troubleshooting
      Lucky65
      Lucky65
    • RE: Weird protocol version mismatch

      I think the appropriate words of wisdom are that the Raspberry Pi as gateway, directly interfacing to the RFM69 radio via GPIO, is not well supported yet. In fact, now that I've looked at it in more detail, there really is no use case where this is a desirable configuration. Any Arduino embedded controller can function as the gateway for connection to a home automation controller. Much cheaper, lower power and less complicated. I got my Home Assistant setup working with a Moteino gateway over serial with minimal effort.

      posted in Troubleshooting
      Lucky65
      Lucky65