BigW Consortium Gitlab

Commit 1e7b192d by Zahid Chowdhury

combainApiKey modifiable via dhub dynamically, set dhub json string format same…

combainApiKey modifiable via dhub dynamically, set dhub json string format same for gnss & wifi, i.e.zero for alt & vacc, finally auto-start location
parent 0731aeba
......@@ -46,11 +46,20 @@ static size_t WriteMemCallback(void *contents, size_t size, size_t nmemb, void *
void *CombainHttpThreadFunc(void *context)
{
char combainUrl[128] = "https://cps.combain.com?key=";
strncat(combainUrl, combainApiKey, sizeof(combainUrl) - (1 + strlen(combainUrl)));
char combainUrl[128];
char OldCombainApiKey[MAX_LEN_API_KEY];
do {
auto t = RequestJson->dequeue();
// Have the API key changeable from DHUB
if (strncmp(OldCombainApiKey,combainApiKey, sizeof(combainUrl) - (1 + strlen(combainUrl))) != 0)
{
strncpy(OldCombainApiKey, combainApiKey, sizeof(combainUrl) - (1 + strlen(combainUrl)));
combainUrl[0] = '\0';
strcpy(combainUrl, "https://cps.combain.com?key=");
strncat(combainUrl, combainApiKey, sizeof(combainUrl) - (1 + strlen(combainUrl)));
}
// Bug existed as we kept tacking onto the existing buffer
HttpReceiveBuffer.used = 0;
HttpReceiveBuffer.data[0] = 0;
......@@ -69,6 +78,7 @@ void *CombainHttpThreadFunc(void *context)
LE_ASSERT(curl_easy_setopt(curl, CURLOPT_HTTPHEADER, httpHeaders) == CURLE_OK);
LE_ASSERT(curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, requestBody.c_str()) == CURLE_OK);
LE_INFO("APIKEY: %s", combainUrl);
LE_INFO("SENDING %d char: %s", requestBody.length(), requestBody.c_str());
LE_ASSERT(curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemCallback) == CURLE_OK);
......
......@@ -463,18 +463,24 @@ static bool TryParseAsSuccess(json_t *responseJson, std::shared_ptr<CombainResul
static void SetApiKey (double timestamp, const char *api_key, void *contextPtr)
{
LE_INFO("SetApiKey called");
LE_INFO("DHUB SetApiKey called with ApiKey: %s", api_key);
if (strlen(api_key) > (MAX_LEN_API_KEY - 1))
{
LE_INFO("To large an ApiKey!!");
return;
}
strncpy(combainApiKey, api_key, MAX_LEN_API_KEY - 1);
combainApiKeySet = true;
LE_INFO("combainApiKey set from dhub starting http thread");
CombainHttpInit(&RequestJson, &ResponseJson, ResponseAvailableEvent);
le_thread_Ref_t httpThread = le_thread_Create("CombainHttp", CombainHttpThreadFunc, NULL);
le_thread_Start(httpThread);
/* Only start HttpThread if combainApiKeySet was not set
* Thus, we are using combainApiKeySet to mean that HttpThread is running
*/
if (!combainApiKeySet)
{
combainApiKeySet = true;
LE_INFO("Starting http thread");
CombainHttpInit(&RequestJson, &ResponseJson, ResponseAvailableEvent);
le_thread_Ref_t httpThread = le_thread_Create("CombainHttp", CombainHttpThreadFunc, NULL);
le_thread_Start(httpThread);
}
}
COMPONENT_INIT
......
......@@ -153,18 +153,17 @@ static void PackJson
" \"alt\": %lf, \"vAcc\": %lf, \"fixType\" : \"GNSS\", \"ts\" : %ju}",
scanp->lat, scanp->lon, scanp->hAccuracy,
scanp->alt, scanp->vAccuracy, (uintmax_t)ts);
// For Wifi we keep the same JSON format as GNSS - i.e. alt & vAcc are 0
// TODO: go to jansson directly and send NULL
else if (loc == WIFI)
len = snprintf(jsonp, jsonl,
"{ \"lat\": %lf, \"lon\": %lf, \"hAcc\": %lf,"
" \"fixType\" : \"WIFI\", \"ts\" : %ju}",
scanp->lat, scanp->lon, scanp->hAccuracy, (uintmax_t)ts);
else
LE_FATAL("ILLEGAL Location Type: WIFI|GPS");
" \"alt\": %lf, \"vAcc\": %lf, \"fixType\" : \"WIFI\", \"ts\" : %ju}",
scanp->lat, scanp->lon, scanp->hAccuracy,
(double) 0, (double) 0, (uintmax_t)ts);
if (len >= jsonl)
{
LE_FATAL("JSON string (len %d) is longer than buffer (size %zu).", len, jsonl);
}
}
static void LocationResultHandler(
......
sandboxed: true
start: manual
start: auto
version: 0.0.1
extern:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment