aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2019-05-25 04:13:46 +0200
committerBjørn Mork <bjorn@mork.no>2019-05-25 04:13:46 +0200
commit69a990b6657debc4fe9a43db07d0fdb564fbff76 (patch)
tree9af3fb554a636a6fd789549646f59d7f0ca95a1d
parenta4f9b2d273ebb62ca82f16b9a7e68a427e90fbb6 (diff)
wip: fix Kaifa crash
Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r--obinsectd.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/obinsectd.c b/obinsectd.c
index 8c42ae6..bf59b1d 100644
--- a/obinsectd.c
+++ b/obinsectd.c
@@ -1027,14 +1027,15 @@ static void add_obis(json_object *pubcfg, json_object *pub, const char *key, jso
int scale = get_scale(key);
double f;
+ debug("*** adding %s ***\n", key);
if (!current_list && !strcmp(key, "1-1:0.2.129.255"))
set_current_list(json_object_get_string(val));
if (scale > 1) {
- f = json_object_get_int(val) / scale;
+ f = (double)json_object_get_int(val) / scale;
newval = json_object_new_double(f);
}
if (json_object_object_get_ex(pub, "normal", &normal))
- json_object_object_add(normal, key, val);
+ json_object_object_add(normal, key, newval);
add_keyval(pubcfg, pub, key, newval, true);
if (alias)
add_keyval(pubcfg, pub, alias, newval, true);
@@ -1061,9 +1062,6 @@ static json_object *normalize(json_object *pubcfg, json_object *json)
if (json_object_object_get_ex(pubcfg, "normal", NULL))
json_object_object_add(ret, "normal", json_object_new_object());
- /* include the message time-stamp if available and not 0 */
- if (json_object_object_get_ex(notification, "date-time", &tmp) && json_object_get_int(tmp))
- add_keyval(pubcfg, ret, "date-time", json_object_get(tmp), true);
/* overall formatting differs between the 3:
@@ -1161,6 +1159,7 @@ static json_object *normalize(json_object *pubcfg, json_object *json)
json_object_object_foreach(body, key, val) {
i++;
+ debug("*** code %u ***\n", i);
if (n == 1)
/* the simplest Aidon and Kaifa list
* has only a single value:
@@ -1174,12 +1173,19 @@ static json_object *normalize(json_object *pubcfg, json_object *json)
}
else if (!strncmp(key, "obis", 4))
mykey = json_object_get_string(val);
- else
+ else {
/* "mykey" is the obis code for Kamstrup lists. Look up by index for Kaifa lists */
- add_obis(pubcfg, ret, mykey ? mykey : obis_lookup(listname, i), obis_get_val(mykey, val));
+ if (!mykey)
+ mykey = obis_lookup(listname, i);
+ add_obis(pubcfg, ret, mykey, obis_get_val(mykey, val));
+ }
}
}
+ /* include the message time-stamp if available and not 0 */
+ if (json_object_object_get_ex(notification, "date-time", &tmp) && json_object_get_int(tmp))
+ add_keyval(pubcfg, ret, "date-time", json_object_get(tmp), false);
+
return ret;
}