0

MKR1000 and Adafruit MQTT Library
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

MKR1000 and Adafruit MQTT Library

by pilow on Sun May 01, 2016 4:06 pm

Hi,

I was struggling with "error: 'dtostrf' was not declared in this scope" when compiling sketches for Arduino MKR1000 when including Adafruit_MQTT_Library

As per the doc, this library is not compatible with all hardware.
The missing function (dtostrf) id declared in Adafruit_MQTT.cpp lines 24 to 31
Code: Select all | TOGGLE FULL SIZE
#ifdef ARDUINO_SAMD_ZERO
static char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
  char fmt[20];
  sprintf(fmt, "%%%d.%df", width, prec);
  sprintf(sout, fmt, val);
  return sout;
}
#endif


just duplicate this code block in the cpp file, and change to :
Code: Select all | TOGGLE FULL SIZE
#ifdef ARDUINO_SAMD_MKR1000
static char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
  char fmt[20];
  sprintf(fmt, "%%%d.%df", width, prec);
  sprintf(sout, fmt, val);
  return sout;
}
#endif


So that you keep compatibility with Arduino Zero, and get an error free compilation for Arduino MKR1000 board !

"C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-gcc" -c -g -x assembler-with-cpp -DF_CPU=48000000L -DARDUINO=10608 -DARDUINO_SAMD_MKR1000 -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804e -DUSBCON '-DUSB_MANUFACTURER="Arduino LLC"' '-DUSB_PRODUCT="Arduino MKR1000"' "-IC:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel/CMSIS/Include/" "-IC:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel/Device/ATMEL/" "-IC:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.5\cores\arduino" "-IC:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.5\variants\mkr1000" "C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.5\cores\arduino\pulse_asm.S" -o "C:\Users\xxx\AppData\Local\Temp\buildfa67b9090c78c4dce955f3b5a8052adf.tmp\core\pulse_asm.S.o"

You can find the file to modify in the \Documents\Arduino\libraries\Adafruit_MQTT folder.

Been logging Luminosity and Temperature flawlessly with Adafruit MQTT Library to Adafruit.IO since this little hack with my MKR1000 ! =)

pilow
 
Posts: 4
Joined: Thu Oct 29, 2015 4:01 am

Please be positive and constructive with your questions and comments.


cron