LowPowerLab Forum

Hardware support => Moteino => Topic started by: mario.almeida on March 02, 2017, 12:03:27 PM

Title: Arduino IDE to program moteino
Post by: mario.almeida on March 02, 2017, 12:03:27 PM
Hi Felix,

What version of Arduino IDE do you use to program Moteinos?

Am asking this question coz in one of my post https://lowpowerlab.com/forum/general-topics/sonarmote-sending-wrong-distance-value/, I mention issue about buff. Now I am facing the same issue with SwitchMote sync mode.

In SwitchMote I had to do the following changes to get it working.

char syncBuff[7];

      sprintf(syncBuff, "SYNC%d:%d", btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information
      radio.sendACK(syncBuff, strlen(syncBuff));

Title: Re: Arduino IDE to program moteino
Post by: Felix on March 02, 2017, 12:31:34 PM
1.0.6
What was the change?
Title: Re: Arduino IDE to program moteino
Post by: mario.almeida on March 02, 2017, 12:48:01 PM
Hi Felix,

In the Example SwitchMote sketch, you have char * buff = "justAnEmptyString"; I added another one as char syncBuff[7]; and replace sprintf(buff, "SYNC%d:%d", btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information
      radio.sendACK(buff, strlen(buff));
with sprintf(syncBuff, "SYNC%d:%d", btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information
      radio.sendACK(syncBuff, strlen(syncBuff));


Let me try with 1.0.6
Title: Re: Arduino IDE to program moteino [SOLVED]
Post by: mario.almeida on March 02, 2017, 03:35:15 PM
Hi Felix,

No issue with 1.0.6.

In  1.6.11 This is the message
QuoteBTN0:0[11] SYNC? [RX_RSSI:-42]GOT SYNC? REPLY FROM [11:17]:[SYNC0:1ptyString]
BTN0:0SYNC ACK mismatch: [SYNC0:1ptyString]
BTN0:0SYNC MODE ON
BTN0:0200,0,0,0,0,0,0,0,0,0SYNC MODE OFF
BTN0:0
btn[0]:D6 - TOP:    OFF
Having char * buff = "justAnEmptyString"; the string is not entirely replace but only the first matching part, but in 1.0.6 the entire string is replaced.

So to get it working in 1.6.11, I need to have char syncBuff[<size>];
Title: Re: Arduino IDE to program moteino
Post by: Felix on March 02, 2017, 03:51:53 PM
It must be differences in how the compiler interprets instantiated buffers in the different versions.
I try to compile the examples in both my favorite version 1.0.6 and the latest at that time. But I see they are great at messing up from version to version thus making it impossible to keep consistent, so what worked a few versions ago no longer works because they constantly change how the compilers work.... open source at its greatest.
Title: Re: Arduino IDE to program moteino
Post by: syrinxtech on March 03, 2017, 09:48:10 AM
For what it's worth, I always clear out buffers between re-use:


memset(&buf, '\0', sizeof(buf));


This way I'm guaranteed that there is at least one null character to stop printf's, etc from running off the end of the buffer.
Title: Re: Arduino IDE to program moteino
Post by: Felix on March 03, 2017, 09:55:31 AM
A nice library that helps with this is Arduiniana, I thought about integrating it in my examples but some folks might complain.
Title: Re: Arduino IDE to program moteino
Post by: perky on March 03, 2017, 10:03:35 AM
I couldn't see why this would fail, the sprintf is supposed to put a null terminator in there. Also there's no real difference between what Felix did with initialising a pointer to a string array and the syncBuff array (except that with the buff approach the "justAnEmptyString" string literal is copied from flash and put into SRAM so it uses flash to store that).

There's something not right here...

Edit: Also char syncBuff[7] should really be char syncBuff[8] because you need to allocate space for the null terminator, this might be working by accident as who knows what the last byte contains, you could end up stamping on another variable...

Mark.