bmsd/ispindels.c

changeset 675
a27af02ab16a
parent 654
0aef416dbceb
child 677
6e82fece1f8f
equal deleted inserted replaced
674:c865e3cdee04 675:a27af02ab16a
26 #include "bms.h" 26 #include "bms.h"
27 #include "xutil.h" 27 #include "xutil.h"
28 #include "ispindels.h" 28 #include "ispindels.h"
29 #include "mysql.h" 29 #include "mysql.h"
30 #include "nodes.h" 30 #include "nodes.h"
31 #include "websocket.h"
31 32
32 33
33 sys_ispindel_list *ispindels = NULL; 34 sys_ispindel_list *ispindels = NULL;
34 35
35 extern int debug; 36 extern int debug;
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) {

mercurial