.ino is compiled as C++. your test is C code. put the C code in a .c file and the declaration in .h file and include the .h in .ino
I created a test.c, copied the content of your main.c into it and renamed the main function to test().
TheThen I created a test.h with
#ifndef test_h
#define test_h
extern "C" void test(char * buff);
#endif
and in ino setup() I call test();
it compiles. It runs. Output:
2 sections
type=section
section [0]: start_pin= 0, end_pin= 71, red= 0, green=255, blue= 0
section [1]: start_pin=216, end_pin=287, red=255, green= 53, blue= 0
in ino
void setup()
{
Serial.begin(115200);
char buff[700];
test(buff);
Serial.print(buff);
}
in .c
void test(char* buff)
{
static const char *s =
"{ \"type\": \"section\", \"sections\": [{ \"start_pin\": 0, \"end_pin\": 71, \"colour_red\": 0, \"colour_green\": 255, \"colour_blue\": 0 }, { \"start_pin\": 216, \"end_pin\": 287, \"colour_red\": 255, \"colour_green\": 0, \"colour_blue\": 0 }] }";
int status = json_read_object(s, json_attrs, NULL);
if (status != 0) {
sprintf(buff, json_error_string(status));
return;
}
int pos = sprintf(buff, "%d sections\n", num_sections);
pos += sprintf(buff + pos, "type=%s\n", thenode.type);
for (int i = 0; i < num_sections; ++i) {
pos +=
sprintf(buff + pos,
"section [%u][%d]: start_pin=%3ustart_pin=%3d, end_pin=%3uend_pin=%3d, red=%3ured=%3d, green=%3ugreen=%3d, blue=%3u\n"blue=%3d\n",
i, thenode.thelight[i].start_pin,
thenode.thelight[i].end_pin,
thenode.thelight[i].colour_red,
thenode.thelight[i].colour_green,
thenode.thelight[i].colour_blue);
}
}
}