bmsd/ispindels.c

changeset 579
1253a237b620
parent 578
e75ce5bbda73
child 587
31caffee8c9c
equal deleted inserted replaced
578:e75ce5bbda73 579:1253a237b620
48 char *datetime, buf[65], *line, *logfile; 48 char *datetime, buf[65], *line, *logfile;
49 struct tm *mytime; 49 struct tm *mytime;
50 time_t timestamp; 50 time_t timestamp;
51 FILE *fp; 51 FILE *fp;
52 52
53 if (debug) 53 // if (debug)
54 printf("ispindel_set: %s %s\n", node, payload); 54 // printf("ispindel_set: %s %s\n", node, payload);
55 55
56 /* 56 /*
57 * Search ispindel record in the memory array and use it if found. 57 * Search ispindel record in the memory array and use it if found.
58 */ 58 */
59 if (ispindels) { 59 if (ispindels) {
64 break; 64 break;
65 } 65 }
66 } 66 }
67 } 67 }
68 68
69 if (debug) 69 // if (debug)
70 printf("new_ispindel %s\n", new_ispindel ? "true":"false"); 70 // printf("new_ispindel %s\n", new_ispindel ? "true":"false");
71 71
72 /* 72 /*
73 * Allocate new ispindel if not yet known. 73 * Allocate new ispindel if not yet known.
74 */ 74 */
75 if (new_ispindel) { 75 if (new_ispindel) {
119 if (json_object_object_get_ex(metric, "gravity", &val)) { 119 if (json_object_object_get_ex(metric, "gravity", &val)) {
120 ispindel->gravity = json_object_get_double(val); 120 ispindel->gravity = json_object_get_double(val);
121 } 121 }
122 } 122 }
123 123
124 ispindel_dump(ispindel); 124 // ispindel_dump(ispindel);
125 125
126 if (new_ispindel) { 126 if (new_ispindel) {
127 if (ispindels == NULL) { 127 if (ispindels == NULL) {
128 ispindels = ispindel; 128 ispindels = ispindel;
129 } else { 129 } else {
141 141
142 /* 142 /*
143 * The data is complete, see if we can write a log entry. 143 * The data is complete, see if we can write a log entry.
144 */ 144 */
145 if (ispindel->beercode && strlen(ispindel->beercode) && ispindel->beername && strlen(ispindel->beername) && 145 if (ispindel->beercode && strlen(ispindel->beercode) && ispindel->beername && strlen(ispindel->beername) &&
146 (strcmp(ispindel->mode, (char *)"ON") == 0)) { 146 ispindel->online && (strcmp(ispindel->mode, (char *)"ON") == 0)) {
147 datetime = malloc(72); 147 datetime = malloc(72);
148 timestamp = time(NULL);
148 mytime = localtime(&timestamp); 149 mytime = localtime(&timestamp);
149 snprintf(datetime, 72, "%04d-%02d-%02d %02d:%02d:%02d", 150 snprintf(datetime, 72, "%04d-%02d-%02d %02d:%02d:%02d",
150 mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); 151 mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
151 152
152 line = xstrcpy(datetime); 153 line = xstrcpy(datetime);
154 snprintf(buf, 64, "%.4f", ispindel->temperature); 155 snprintf(buf, 64, "%.4f", ispindel->temperature);
155 line = xstrcat(line, buf); 156 line = xstrcat(line, buf);
156 line = xstrcat(line, (char *)","); 157 line = xstrcat(line, (char *)",");
157 snprintf(buf, 64, "%.5f", ispindel->gravity); 158 snprintf(buf, 64, "%.5f", ispindel->gravity);
158 line = xstrcat(line, buf); 159 line = xstrcat(line, buf);
160 line = xstrcat(line, (char *)",");
161 snprintf(buf, 64, "%.5f", 1 + (ispindel->gravity / (258.6 - ((ispindel->gravity / 258.2) * 227.1))));
162 line = xstrcat(line, buf);
159 line = xstrcat(line, (char *)","); 163 line = xstrcat(line, (char *)",");
160 snprintf(buf, 64, "%.5f", ispindel->battery); 164 snprintf(buf, 64, "%.5f", ispindel->battery);
161 line = xstrcat(line, buf); 165 line = xstrcat(line, buf);
162 line = xstrcat(line, (char *)","); 166 line = xstrcat(line, (char *)",");
163 snprintf(buf, 64, "%.5f", ispindel->angle); 167 snprintf(buf, 64, "%.5f", ispindel->angle);

mercurial