Libre Solar Community Forum

Thingset on 8-bit AVR / Arduino

Hi guys.

I’m trying to include the thingset library into an Arduino Project.

The setup is

  • visual studio code
  • platform.io
  • thingset lib copied into src folder
  • main.cpp replaced with example code from thingset

Compiling the code results in:

Archiving .pio/build/nanoatmega328/libFrameworkArduinoVariant.a
src/thingset_txt.c: In function 'ts_json_serialize_value':
src/thingset_txt.c:196:60: error: expected ')' before 'PRIu64'
                 pos += snprintf(buf + pos, size - pos, "%" PRIu64 ",",

Adding the build flags:

build_flags =
    -std=c++11
    -D NATIVE_BUILD
    -pthread
    -Wall
    -Wno-deprecated-declarations
    -D TS_64BIT_TYPES_SUPPORT=0```

to the platformio.ini file results in:

Compiling .pio/build/nanoatmega328/src/cbor.c.o
Compiling .pio/build/nanoatmega328/src/jsmn.c.o
avr-gcc: error: unrecognized command line option '-pthread'
avr-gcc: error: unrecognized command line option '-pthread'
Compiling .pio/build/nanoatmega328/src/main.cpp.o
*** [.pio/build/nanoatmega328/src/jsmn.c.o] Error 1
Compiling .pio/build/nanoatmega328/src/thingset.c.o
*** [.pio/build/nanoatmega328/src/cbor.c.o] Error 1
avr-g++: error: unrecognized command line option '-pthread'
*** [.pio/build/nanoatmega328/src/main.cpp.o] Error 1
avr-gcc: error: unrecognized command line option '-pthread'
*** [.pio/build/nanoatmega328/src/thingset.c.o] Error 1

If I compile the project without the flag -pthread, I’m back at the beginning:

Archiving .pio/build/nanoatmega328/libFrameworkArduinoVariant.a
src/thingset_txt.c: In function 'ts_json_serialize_value':
src/thingset_txt.c:196:60: error: expected ')' before 'PRIu64'
                 pos += snprintf(buf + pos, size - pos, "%" PRIu64 ",",

I don’t now how to continue from here. Can I get rid of the use of pthread or do I need to include pthread to my project?

Best,
Dan

Pthreads are not needed for the library.

The other issue seems to be a bug. Can you please post this as an issue in the repository. I will take care of a fix.

Thanks for fixing, Martin.

If someone wants to test it on an Arduino, here is a minimal example code. Just replace the example code in the thingset folder structure with this:

#include <Arduino.h>
#include <stdio.h>
#include <thingset.h>

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#endif

bool enable_switch = false;

static struct ts_data_object data_objects[] = {
    TS_ITEM_BOOL(0x61, "HeaterEnable", &enable_switch, TS_ID_ROOT, TS_ANY_RW, 0),
};

void setup() {
    Serial.begin(9600);
}

void loop(void) {
    uint8_t response[100];
    struct ts_context ts;
    char ser_buf[100];
    ts_init(&ts, data_objects, ARRAY_SIZE(data_objects));

    const char request1[] = "= {\"HeaterEnable\":true}";
    sprintf(ser_buf, "Request:   %s\n", request1);
    Serial.println(ser_buf);
    ts_process(&ts, (uint8_t *)request1, strlen(request1), response, sizeof(response));
    sprintf(ser_buf, "Response:  %s\n\n", (char *)response);
    Serial.println(ser_buf);
    delay(5000);
}