43 void ispindel_set(char *node, char *payload) |
44 void ispindel_set(char *node, char *payload) |
44 { |
45 { |
45 sys_ispindel_list *ispindel, *tmpp; |
46 sys_ispindel_list *ispindel, *tmpp; |
46 struct json_object *jobj, *metric, *val; |
47 struct json_object *jobj, *metric, *val; |
47 bool new_ispindel = true; |
48 bool new_ispindel = true; |
48 char *datetime, buf[65], *line, *logfile; |
49 char *datetime, buf[65], *line, *logfile, *msg = NULL; |
49 struct tm *mytime; |
50 struct tm *mytime; |
50 time_t timestamp; |
51 time_t timestamp; |
51 FILE *fp; |
52 FILE *fp; |
52 |
53 |
53 // if (debug) |
54 // if (debug) |
118 } |
119 } |
119 if (json_object_object_get_ex(metric, "gravity", &val)) { |
120 if (json_object_object_get_ex(metric, "gravity", &val)) { |
120 ispindel->gravity = json_object_get_double(val); |
121 ispindel->gravity = json_object_get_double(val); |
121 } |
122 } |
122 } |
123 } |
|
124 |
|
125 msg = xstrcpy((char *)"{\"device\":\"ispindel\",\"node\":\""); |
|
126 msg = xstrcat(msg, node); |
|
127 msg = xstrcat(msg, (char *)"\",\"unit\":\""); |
|
128 msg = xstrcat(msg, ispindel->alias); |
|
129 msg = xstrcat(msg, (char *)"\",\"online\":"); |
|
130 msg = xstrcat(msg, ispindel->online ? (char *)"1":(char *)"0"); |
|
131 msg = xstrcat(msg, (char *)",\"mode\":\""); |
|
132 msg = xstrcat(msg, ispindel->mode); |
|
133 msg = xstrcat(msg, (char *)"\",\"temperature\":"); |
|
134 snprintf(buf, 64, "%.4f", ispindel->temperature); |
|
135 msg = xstrcat(msg, buf); |
|
136 msg = xstrcat(msg, (char *)",\"angle\":"); |
|
137 snprintf(buf, 64, "%.5f", ispindel->angle); |
|
138 msg = xstrcat(msg, buf); |
|
139 msg = xstrcat(msg, (char *)",\"battery\":"); |
|
140 snprintf(buf, 64, "%.6f", ispindel->battery); |
|
141 msg = xstrcat(msg, buf); |
|
142 msg = xstrcat(msg, (char *)",\"gravity\":"); |
|
143 snprintf(buf, 64, "%.5f", ispindel->gravity); |
|
144 msg = xstrcat(msg, buf); |
|
145 msg = xstrcat(msg, (char *)",\"alarm\":"); |
|
146 snprintf(buf, 64, "%d", ispindel->alarm); |
|
147 msg = xstrcat(msg, buf); |
|
148 msg = xstrcat(msg, (char *)"}"); |
|
149 ws_broadcast(msg); |
|
150 free(msg); |
|
151 msg = NULL; |
123 |
152 |
124 // ispindel_dump(ispindel); |
153 // ispindel_dump(ispindel); |
125 |
154 |
126 if (new_ispindel) { |
155 if (new_ispindel) { |
127 if (ispindels == NULL) { |
156 if (ispindels == NULL) { |