diff --git a/examples/osd/arduino-windsonic/Makefile b/examples/osd/arduino-windsonic/Makefile index 5879b69f0..015fba7f1 100644 --- a/examples/osd/arduino-windsonic/Makefile +++ b/examples/osd/arduino-windsonic/Makefile @@ -46,7 +46,7 @@ SMALL=1 # REST Engine shall use Erbium CoAP implementation APPS += er-coap APPS += rest-engine -APPS += arduino +APPS += arduino json-resource json ota-update include $(CONTIKI)/Makefile.include include $(CONTIKI)/apps/arduino/Makefile.include diff --git a/examples/osd/arduino-windsonic/project-conf.h b/examples/osd/arduino-windsonic/project-conf.h index 0c0cbd254..aa9da9cea 100644 --- a/examples/osd/arduino-windsonic/project-conf.h +++ b/examples/osd/arduino-windsonic/project-conf.h @@ -32,24 +32,13 @@ #ifndef PROJECT_RPL_WEB_CONF_H_ #define PROJECT_RPL_WEB_CONF_H_ - -#ifdef IEEE802154_CONF_PANID -#undef IEEE802154_CONF_PANID -#define IEEE802154_CONF_PANID 0xA001 // default panid -#endif // IEEE802154_CONF_PANID - -#ifdef CHANNEL_802_15_4 -#undef CHANNEL_802_15_4 -#define CHANNEL_802_15_4 25 // default frequency (11-26) -#endif - //#define PLATFORM_HAS_LEDS 1 //#define PLATFORM_HAS_BUTTON 1 //#define PLATFORM_HAS_BATTERY 1 #define SICSLOWPAN_CONF_FRAG 1 -#define LOOP_INTERVAL (CLOCK_SECOND) +#define LOOP_INTERVAL (CLOCK_SECOND/4) #define WIND_SPEEDS 30 /* Save energy */ diff --git a/examples/osd/arduino-windsonic/sketch.pde b/examples/osd/arduino-windsonic/sketch.pde index de1f7c1ac..a9f810590 100644 --- a/examples/osd/arduino-windsonic/sketch.pde +++ b/examples/osd/arduino-windsonic/sketch.pde @@ -13,45 +13,65 @@ extern "C" { #include #include "arduino-process.h" #include "rest-engine.h" +#include "resources.h" +#include "ota-update.h" -extern resource_t res_wind, res_wind_speed_max, res_wind_status, - res_wind_speed, res_wind_direction, res_power_supply; +#define DEBUG 0 + +#if DEBUG +#include +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +extern resource_t + res_wind, + res_wind_speed_max, + res_wind_status, + res_wind_speed, + res_wind_direction, + res_power_supply; #define STX 0x02 #define ETX 0x03 #define STRING_TERMINATOR 0x00 #define LED_PIN 4 + } -int state = 0; -char ws_status [32]; -int ws_speed_hi = 0; -int ws_speed_lo = 0; -char ws_unit [8]; -int ws_direction = 0; +int state = 0; +char ws_status [32]; +int ws_speed_hi = 0; +int ws_speed_lo = 0; +char ws_unit [8]; +int ws_direction = 0; int supply_voltage_hi = 0; -int supply_voltage_lo = 0; -int ws_max_speed = 0; -int ws_max_speed_lo = 0; -int ws_max_speed_hi = 0; +int supply_voltage_lo = 0; +int ws_max_speed = 0; +int ws_max_speed_lo = 0; +int ws_max_speed_hi = 0; int wind_speeds [WIND_SPEEDS]; // every 2 seconds we get a value int wind_speed_idx = 0; uint32_t idx; +int d, count, msg_length, state0_counter = 0; +unsigned char msg_buffer [128], checksum_buffer [3], checksum; + void set_no_data (void) { - printf ("set no data\n"); + PRINTF ("set no data\n"); strcpy (ws_status, "No data from sensor"); - ws_speed_lo = 000; - ws_speed_hi = 000; - ws_direction = 000; - ws_max_speed = 0; + ws_speed_lo = 0; + ws_speed_hi = 0; + ws_direction = 0; + ws_max_speed = 0; ws_max_speed_hi = 0; ws_max_speed_lo = 0; - wind_speed_idx = 0; + wind_speed_idx = 0; strcpy (ws_unit, ""); for (idx = 0; idx < WIND_SPEEDS; idx++) @@ -71,15 +91,16 @@ void setup (void) rest_init_engine (); #pragma GCC diagnostic ignored "-Wwrite-strings" - rest_activate_resource (&res_wind, "s/wind"); - rest_activate_resource (&res_wind_speed, "s/wind_speed"); + rest_activate_resource (&res_wind, "s/wind"); + rest_activate_resource (&res_wind_speed, "s/wind_speed"); rest_activate_resource (&res_wind_speed_max, "s/wind_speed_max"); rest_activate_resource (&res_wind_direction, "s/wind_direction"); - rest_activate_resource (&res_wind_status, "s/wind_status"); - rest_activate_resource (&res_power_supply, "s/power_supply"); + rest_activate_resource (&res_wind_status, "s/wind_status"); + rest_activate_resource (&res_power_supply, "s/power_supply"); + OTA_ACTIVATE_RESOURCES(); #pragma GCC diagnostic pop - //mcu_sleep_set(128); // Power consumtion 278uA; average over 20 minutes + mcu_sleep_set(0); // Power consumtion 278uA; average over 20 minutes Serial1.begin (9600); set_no_data (); @@ -87,14 +108,10 @@ void setup (void) void loop (void) { - static int d, count, msg_length, state0_counter = 0; - static unsigned char msg_buffer [128], checksum_buffer [3], checksum; - - printf ("state = %d", state); - switch (state) { case 0 : - printf ("state0\n"); + PRINTF ("state0\n"); + strcpy (ws_status, "0"); state0_counter ++; if (state0_counter > 10) { set_no_data (); @@ -103,7 +120,7 @@ void loop (void) // wait for stx while (Serial1.available () > 0) { d = Serial1.read (); - printf ("%d ", d); + PRINTF ("%d ", d); if (d == STX) { state = 1; count = 0; @@ -114,13 +131,14 @@ void loop (void) break; case 1 : - printf ("state1\n"); + PRINTF ("state1\n"); + strcpy (ws_status, "1"); state0_counter = 0; // wait for etx and read message while (Serial1.available () > 0) { d = Serial1.read (); - printf ("%d ", d); + PRINTF ("%d ", d); if (d == ETX) { msg_length = count; msg_buffer [count] = STRING_TERMINATOR; @@ -137,16 +155,17 @@ void loop (void) } } } - if (state == 1) + if (state == 1 || state == 0) break; case 2 : - printf ("state2\n"); + PRINTF ("state2\n"); + strcpy (ws_status, "2"); // read checksum while (Serial1.available () > 0) { d = Serial1.read (); - printf ("%d ", d); - printf (" %d (%d)\n", d, count); + PRINTF ("%d ", d); + PRINTF (" %d (%d)\n", d, count); checksum_buffer [count] = (unsigned char) (d & 0xff); count ++; if (count == 2) { @@ -162,7 +181,8 @@ void loop (void) unsigned int checksum_rx; int cnt; - printf ("state3\n"); + PRINTF ("state3\n"); + strcpy (ws_status, "3"); // calc and compare checksum checksum = 0; sscanf ((const char*)checksum_buffer, "%2X", &checksum_rx); @@ -171,7 +191,8 @@ void loop (void) } if (checksum_rx != checksum) { - printf ("checksum mismatch %02x != %02x\n", checksum, checksum_rx); + PRINTF ("checksum mismatch %02x != %02x\n", checksum, checksum_rx); + sprintf (ws_status, "CS: %02x!=%02x,%s", checksum, checksum_rx,msg_buffer); state = 0; break; } else { @@ -183,8 +204,9 @@ void loop (void) char unit [1]; int status; - printf ("state4\n"); - printf ("parse messge: %s\n", msg_buffer); + PRINTF ("state4\n"); + strcpy (ws_status, "4"); + PRINTF ("parse messge: %s\n", msg_buffer); sscanf ( (const char*) msg_buffer , "Q,%3d,%3d.%2d,%c,%2d" @@ -257,7 +279,7 @@ void loop (void) ws_max_speed_lo = ws_max_speed % 100; ws_max_speed_hi = ws_max_speed / 100; - printf ("speed: %d.%02d %s, dir: %d, status: %s, max: %d.%02d\n" + PRINTF ("speed: %d.%02d %s, dir: %d, status: %s, max: %d.%02d\n" , ws_speed_hi, ws_speed_lo, ws_unit, ws_direction, ws_status , ws_max_speed_hi, ws_max_speed_lo);