fixed some issues, added ota-update
This commit is contained in:
parent
86596ac92f
commit
8c82ce0722
|
@ -46,7 +46,7 @@ SMALL=1
|
||||||
# REST Engine shall use Erbium CoAP implementation
|
# REST Engine shall use Erbium CoAP implementation
|
||||||
APPS += er-coap
|
APPS += er-coap
|
||||||
APPS += rest-engine
|
APPS += rest-engine
|
||||||
APPS += arduino
|
APPS += arduino json-resource json ota-update
|
||||||
|
|
||||||
include $(CONTIKI)/Makefile.include
|
include $(CONTIKI)/Makefile.include
|
||||||
include $(CONTIKI)/apps/arduino/Makefile.include
|
include $(CONTIKI)/apps/arduino/Makefile.include
|
||||||
|
|
|
@ -32,24 +32,13 @@
|
||||||
#ifndef PROJECT_RPL_WEB_CONF_H_
|
#ifndef PROJECT_RPL_WEB_CONF_H_
|
||||||
#define 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_LEDS 1
|
||||||
//#define PLATFORM_HAS_BUTTON 1
|
//#define PLATFORM_HAS_BUTTON 1
|
||||||
//#define PLATFORM_HAS_BATTERY 1
|
//#define PLATFORM_HAS_BATTERY 1
|
||||||
|
|
||||||
#define SICSLOWPAN_CONF_FRAG 1
|
#define SICSLOWPAN_CONF_FRAG 1
|
||||||
|
|
||||||
#define LOOP_INTERVAL (CLOCK_SECOND)
|
#define LOOP_INTERVAL (CLOCK_SECOND/4)
|
||||||
#define WIND_SPEEDS 30
|
#define WIND_SPEEDS 30
|
||||||
|
|
||||||
/* Save energy */
|
/* Save energy */
|
||||||
|
|
|
@ -13,15 +13,32 @@ extern "C" {
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "arduino-process.h"
|
#include "arduino-process.h"
|
||||||
#include "rest-engine.h"
|
#include "rest-engine.h"
|
||||||
|
#include "resources.h"
|
||||||
|
#include "ota-update.h"
|
||||||
|
|
||||||
extern resource_t res_wind, res_wind_speed_max, res_wind_status,
|
#define DEBUG 0
|
||||||
res_wind_speed, res_wind_direction, res_power_supply;
|
|
||||||
|
#if DEBUG
|
||||||
|
#include <stdio.h>
|
||||||
|
#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 STX 0x02
|
||||||
#define ETX 0x03
|
#define ETX 0x03
|
||||||
#define STRING_TERMINATOR 0x00
|
#define STRING_TERMINATOR 0x00
|
||||||
|
|
||||||
#define LED_PIN 4
|
#define LED_PIN 4
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int state = 0;
|
int state = 0;
|
||||||
|
@ -41,13 +58,16 @@ int wind_speed_idx = 0;
|
||||||
|
|
||||||
uint32_t idx;
|
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)
|
void set_no_data (void)
|
||||||
{
|
{
|
||||||
printf ("set no data\n");
|
PRINTF ("set no data\n");
|
||||||
strcpy (ws_status, "No data from sensor");
|
strcpy (ws_status, "No data from sensor");
|
||||||
ws_speed_lo = 000;
|
ws_speed_lo = 0;
|
||||||
ws_speed_hi = 000;
|
ws_speed_hi = 0;
|
||||||
ws_direction = 000;
|
ws_direction = 0;
|
||||||
ws_max_speed = 0;
|
ws_max_speed = 0;
|
||||||
ws_max_speed_hi = 0;
|
ws_max_speed_hi = 0;
|
||||||
ws_max_speed_lo = 0;
|
ws_max_speed_lo = 0;
|
||||||
|
@ -77,9 +97,10 @@ void setup (void)
|
||||||
rest_activate_resource (&res_wind_direction, "s/wind_direction");
|
rest_activate_resource (&res_wind_direction, "s/wind_direction");
|
||||||
rest_activate_resource (&res_wind_status, "s/wind_status");
|
rest_activate_resource (&res_wind_status, "s/wind_status");
|
||||||
rest_activate_resource (&res_power_supply, "s/power_supply");
|
rest_activate_resource (&res_power_supply, "s/power_supply");
|
||||||
|
OTA_ACTIVATE_RESOURCES();
|
||||||
#pragma GCC diagnostic pop
|
#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);
|
Serial1.begin (9600);
|
||||||
|
|
||||||
set_no_data ();
|
set_no_data ();
|
||||||
|
@ -87,14 +108,10 @@ void setup (void)
|
||||||
|
|
||||||
void loop (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) {
|
switch (state) {
|
||||||
case 0 :
|
case 0 :
|
||||||
printf ("state0\n");
|
PRINTF ("state0\n");
|
||||||
|
strcpy (ws_status, "0");
|
||||||
state0_counter ++;
|
state0_counter ++;
|
||||||
if (state0_counter > 10) {
|
if (state0_counter > 10) {
|
||||||
set_no_data ();
|
set_no_data ();
|
||||||
|
@ -103,7 +120,7 @@ void loop (void)
|
||||||
// wait for stx
|
// wait for stx
|
||||||
while (Serial1.available () > 0) {
|
while (Serial1.available () > 0) {
|
||||||
d = Serial1.read ();
|
d = Serial1.read ();
|
||||||
printf ("%d ", d);
|
PRINTF ("%d ", d);
|
||||||
if (d == STX) {
|
if (d == STX) {
|
||||||
state = 1;
|
state = 1;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
@ -114,13 +131,14 @@ void loop (void)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1 :
|
case 1 :
|
||||||
printf ("state1\n");
|
PRINTF ("state1\n");
|
||||||
|
strcpy (ws_status, "1");
|
||||||
state0_counter = 0;
|
state0_counter = 0;
|
||||||
|
|
||||||
// wait for etx and read message
|
// wait for etx and read message
|
||||||
while (Serial1.available () > 0) {
|
while (Serial1.available () > 0) {
|
||||||
d = Serial1.read ();
|
d = Serial1.read ();
|
||||||
printf ("%d ", d);
|
PRINTF ("%d ", d);
|
||||||
if (d == ETX) {
|
if (d == ETX) {
|
||||||
msg_length = count;
|
msg_length = count;
|
||||||
msg_buffer [count] = STRING_TERMINATOR;
|
msg_buffer [count] = STRING_TERMINATOR;
|
||||||
|
@ -137,16 +155,17 @@ void loop (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (state == 1)
|
if (state == 1 || state == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2 :
|
case 2 :
|
||||||
printf ("state2\n");
|
PRINTF ("state2\n");
|
||||||
|
strcpy (ws_status, "2");
|
||||||
// read checksum
|
// read checksum
|
||||||
while (Serial1.available () > 0) {
|
while (Serial1.available () > 0) {
|
||||||
d = Serial1.read ();
|
d = Serial1.read ();
|
||||||
printf ("%d ", d);
|
PRINTF ("%d ", d);
|
||||||
printf (" %d (%d)\n", d, count);
|
PRINTF (" %d (%d)\n", d, count);
|
||||||
checksum_buffer [count] = (unsigned char) (d & 0xff);
|
checksum_buffer [count] = (unsigned char) (d & 0xff);
|
||||||
count ++;
|
count ++;
|
||||||
if (count == 2) {
|
if (count == 2) {
|
||||||
|
@ -162,7 +181,8 @@ void loop (void)
|
||||||
unsigned int checksum_rx;
|
unsigned int checksum_rx;
|
||||||
int cnt;
|
int cnt;
|
||||||
|
|
||||||
printf ("state3\n");
|
PRINTF ("state3\n");
|
||||||
|
strcpy (ws_status, "3");
|
||||||
// calc and compare checksum
|
// calc and compare checksum
|
||||||
checksum = 0;
|
checksum = 0;
|
||||||
sscanf ((const char*)checksum_buffer, "%2X", &checksum_rx);
|
sscanf ((const char*)checksum_buffer, "%2X", &checksum_rx);
|
||||||
|
@ -171,7 +191,8 @@ void loop (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checksum_rx != checksum) {
|
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;
|
state = 0;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
@ -183,8 +204,9 @@ void loop (void)
|
||||||
char unit [1];
|
char unit [1];
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
printf ("state4\n");
|
PRINTF ("state4\n");
|
||||||
printf ("parse messge: %s\n", msg_buffer);
|
strcpy (ws_status, "4");
|
||||||
|
PRINTF ("parse messge: %s\n", msg_buffer);
|
||||||
sscanf
|
sscanf
|
||||||
( (const char*) msg_buffer
|
( (const char*) msg_buffer
|
||||||
, "Q,%3d,%3d.%2d,%c,%2d"
|
, "Q,%3d,%3d.%2d,%c,%2d"
|
||||||
|
@ -257,7 +279,7 @@ void loop (void)
|
||||||
ws_max_speed_lo = ws_max_speed % 100;
|
ws_max_speed_lo = ws_max_speed % 100;
|
||||||
ws_max_speed_hi = 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_speed_hi, ws_speed_lo, ws_unit, ws_direction, ws_status
|
||||||
, ws_max_speed_hi, ws_max_speed_lo);
|
, ws_max_speed_hi, ws_max_speed_lo);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue