override precision with _geoprec

closes #58
This commit is contained in:
Jan-Piet Mens
2016-03-04 12:40:54 +01:00
parent 5973275ee4
commit 77a5545d92
3 changed files with 25 additions and 3 deletions
+3
View File
@@ -1091,3 +1091,6 @@ We also have a Docker image to create containers which integrate a [Mosquitto br
It actually is possible to gateway location publishes arriving via HTTP into MQTT, though you should be careful not to create loops. You can accomplish this with one or more Lua hooks using MQTT from within Lua.
### Override reverse-geo precision
If a payload is received with an element called `_geoprec` it contains an ovveride for the Recorder's configured reverse-geo precision.
+16 -2
View File
@@ -536,7 +536,7 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle
static UT_string *reltopic = NULL, *filename = NULL;
char *jsonstring, *_typestr = NULL;
time_t now;
int pingping = FALSE, skipslash = 0;
int pingping = FALSE, skipslash = 0, geoprec = geohash_prec();
int r_ok = TRUE; /* True if recording enabled for a publish */
payload_type _type;
@@ -777,6 +777,12 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle
goto cleanup;
}
/*
if (impossible_rule(ud, UB(username), UB(device), tst, lat, lon) == TRUE) {
goto cleanup;
}
*/
if ((j = json_find_member(json, "acc")) != NULL) {
if (j->tag == JSON_STRING) {
acc = atof(j->string_);
@@ -798,6 +804,14 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle
}
}
if ((j = json_find_member(json, "_geoprec")) != NULL) {
if (j->tag == JSON_STRING) {
geoprec = atoi(j->string_);
} else {
geoprec = j->number_;
}
}
#if 0
/* Haversine */
@@ -833,7 +847,7 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle
utstring_renew(ghash);
utstring_renew(addr);
utstring_renew(cc);
p = geohash_encode(lat, lon, geohash_prec());
p = geohash_encode(lat, lon, geoprec);
if (p != NULL) {
utstring_printf(ghash, "%s", p);
free(p);
+6 -1
View File
@@ -634,6 +634,7 @@ static JsonNode *line_to_location(char *line)
char tstamp[64], *bp;
double lat, lon;
long tst;
int geoprec = geohash_prec();
snprintf(tstamp, 21, "%s", line);
@@ -670,7 +671,11 @@ static JsonNode *line_to_location(char *line)
lon = j->number_;
}
if ((ghash = geohash_encode(lat, lon, geohash_prec())) != NULL) {
if ((j = json_find_member(o, "_geoprec")) != NULL) {
geoprec = j->number_;
}
if ((ghash = geohash_encode(lat, lon, geoprec)) != NULL) {
json_append_member(o, "ghash", json_mkstring(ghash));
get_geo(o, ghash);
free(ghash);