add index and struct for messured values

This commit is contained in:
Harald Pichler 2015-10-11 15:30:30 +02:00
parent e8471445ed
commit fd24ecd26e

View file

@ -17,6 +17,7 @@ extern "C" {
#include "rest-engine.h" #include "rest-engine.h"
#include "sketch.h"
extern volatile uint8_t mcusleepcycle; // default 16 extern volatile uint8_t mcusleepcycle; // default 16
@ -33,10 +34,13 @@ DallasTemperature dsensors(&oneWire);
// arrays to hold device addresses // arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer; DeviceAddress insideThermometer, outsideThermometer;
extern resource_t res_dtemp, res_battery; extern resource_t res_dtemp1, res_dtemp2, res_battery;
float d_temp; float d_temp;
char d_temp_s[8]; char d_temp_s[8];
// sketch.h
struct dstemp ds1820[7];
#define LED_PIN 4 #define LED_PIN 4
} }
@ -54,20 +58,23 @@ void printAddress(uint8_t* adress)
} }
// function to print the temperature for a device // function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress) void printTemperature(DeviceAddress deviceAddress,int index)
{ {
d_temp = dsensors.getTempC(deviceAddress); d_temp = dsensors.getTempC(deviceAddress);
dtostrf(d_temp , 6, 2, d_temp_s ); dtostrf(d_temp , 6, 2, d_temp_s );
printf("Temp C: "); printf("Temp C: ");
printf("%s",d_temp_s); printf("%s",d_temp_s);
// copy to structure
ds1820[index].ftemp=d_temp;
strcpy(ds1820[index].stemp, d_temp_s);
} }
void printData(DeviceAddress deviceAddress) void printData(DeviceAddress deviceAddress, int index)
{ {
printf("Device Address: "); printf("Device Address: ");
printAddress(deviceAddress); printAddress(deviceAddress);
printf(" "); printf(" ");
printTemperature(deviceAddress); printTemperature(deviceAddress,index);
printf("\n"); printf("\n");
} }
@ -145,7 +152,8 @@ void setup (void)
printf("\n"); printf("\n");
// init coap resourcen // init coap resourcen
rest_init_engine (); rest_init_engine ();
rest_activate_resource (&res_dtemp, "s/temp"); rest_activate_resource (&res_dtemp1, "s/t1/temp");
rest_activate_resource (&res_dtemp2, "s/t2/temp");
rest_activate_resource (&res_battery, "s/batter"); rest_activate_resource (&res_battery, "s/batter");
} }
@ -161,8 +169,8 @@ void loop (void)
printf("DONE\n"); printf("DONE\n");
// print the device information // print the device information
printData(insideThermometer); printData(insideThermometer,0);
printData(outsideThermometer); printData(outsideThermometer,1);
mcusleepcycle=32; // sleep, wakeup every 32 cycles mcusleepcycle=32; // sleep, wakeup every 32 cycles
// debug only // debug only