50 #ifdef IPSO_TEMPERATURE
51 extern const struct ipso_objects_sensor IPSO_TEMPERATURE;
54 #ifndef IPSO_TEMPERATURE_MIN
55 #define IPSO_TEMPERATURE_MIN (-50 * LWM2M_FLOAT32_FRAC)
58 #ifndef IPSO_TEMPERATURE_MAX
59 #define IPSO_TEMPERATURE_MAX (80 * LWM2M_FLOAT32_FRAC)
62 static struct ctimer periodic_timer;
63 static int32_t min_temp;
64 static int32_t max_temp;
65 static int read_temp(int32_t *value);
68 temp(lwm2m_context_t *ctx, uint8_t *outbuf,
size_t outsize)
71 if(read_temp(&value)) {
72 return ctx->writer->write_float32fix(ctx, outbuf, outsize,
73 value, LWM2M_FLOAT32_BITS);
78 LWM2M_RESOURCES(temperature_resources,
80 LWM2M_RESOURCE_CALLBACK(5700, { temp,
NULL, NULL }),
82 LWM2M_RESOURCE_STRING(5701,
"Cel"),
84 LWM2M_RESOURCE_FLOATFIX(5603, IPSO_TEMPERATURE_MIN),
86 LWM2M_RESOURCE_FLOATFIX(5604, IPSO_TEMPERATURE_MAX),
88 LWM2M_RESOURCE_FLOATFIX_VAR(5601, &min_temp),
90 LWM2M_RESOURCE_FLOATFIX_VAR(5602, &max_temp),
92 LWM2M_INSTANCES(temperature_instances,
93 LWM2M_INSTANCE(0, temperature_resources));
94 LWM2M_OBJECT(temperature, 3303, temperature_instances);
97 read_temp(int32_t *value)
99 #ifdef IPSO_TEMPERATURE
101 if(IPSO_TEMPERATURE.read_value ==
NULL ||
102 IPSO_TEMPERATURE.read_value(&temp) != 0) {
107 *value = (temp * LWM2M_FLOAT32_FRAC) / 1000;
109 if(*value < min_temp) {
111 lwm2m_object_notify_observers(&temperature,
"/0/5601");
113 if(*value > max_temp) {
115 lwm2m_object_notify_observers(&temperature,
"/0/5602");
124 handle_periodic_timer(
void *ptr)
126 static int32_t last_value = IPSO_TEMPERATURE_MIN;
130 if(read_temp(&v) && v != last_value) {
132 lwm2m_object_notify_observers(&temperature,
"/0/5700");
138 ipso_temperature_init(
void)
141 min_temp = IPSO_TEMPERATURE_MAX;
142 max_temp = IPSO_TEMPERATURE_MIN;
144 #ifdef IPSO_TEMPERATURE
145 if(IPSO_TEMPERATURE.init) {
146 IPSO_TEMPERATURE.init();
152 lwm2m_engine_register_object(&temperature);
Header file for the Contiki IPSO Objects for OMA LWM2M
Header file for the Contiki OMA LWM2M object API
Header file for the Contiki OMA LWM2M engine
#define NULL
The null pointer.
#define CLOCK_SECOND
A second, measured in system clock time.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
void ctimer_reset(struct ctimer *c)
Reset a callback timer with the same interval as was previously set.
CoAP implementation for the REST Engine.