Commit 237071a5 authored by Michael Tross's avatar Michael Tross

support user limit reached error message

wait 5 minutes instead of exit'ing and
immediately being restarted ...
parent df882d04
......@@ -52,6 +52,7 @@ netatmo_vdcd_t* devlist = NULL;
/* VDC-API data */
char g_vdc_modeluid[33] = { 0, };
char g_vdc_dsuid[35] = { 0, };
char g_lib_dsuid[35] = { "053f848b85bb382198025cea1fd087f100" };
......@@ -91,11 +92,11 @@ void signal_handler(int signum)
void* networkThread(void *arg __attribute__((unused)))
{
int rc;
static time_t last = 0;
while (!g_shutdown_flag) {
sleep(5);
time_t now = time(NULL);
if (now >= last + 10) {
......@@ -104,17 +105,27 @@ void* networkThread(void *arg __attribute__((unused)))
now, last, g_access_token, netatmo.refresh_token,
g_access_token_valid_until, g_query_devices_time, g_query_values_time);
last = now;
if (g_access_token_valid_until <= now) {
netatmo_get_token();
}
if (g_access_token && (g_query_devices_time <= now)) {
if (netatmo_get_devices() >= 0) {
if ((rc = netatmo_get_devices()) >= 0) {
g_query_devices_time = g_resync_devices + now;
g_network_changes = true;
} else {
g_query_devices_time = 60 + now;
g_query_values_time = 61 + now;
now = time(NULL);
switch(rc) {
case NETATMO_USER_LIMIT_REACHED:
g_query_devices_time = 300 + now;
break;
case NETATMO_TOKEN_EXPIRED:
g_query_devices_time = 600 + now;
break;
default:
g_query_devices_time = 60 + now;
break;
}
g_query_values_time = g_query_devices_time + 1;
}
}
if (g_access_token && (netatmo.base.modules_num > 0) && (g_query_values_time <= now)) {
......@@ -122,9 +133,11 @@ void* networkThread(void *arg __attribute__((unused)))
g_query_values_time = g_reload_values + now;
g_network_changes = true;
} else {
now = time(NULL);
g_query_values_time = 60 + now;
}
}
last = now;
}
}
......
......@@ -93,13 +93,15 @@ typedef struct netatmo_vdcd
} netatmo_vdcd_t;
#define NETATMO_OK 0
#define NETATMO_OUT_OF_MEMORY -1
#define NETATMO_AUTH_FAILED -10
#define NETATMO_BAD_CONFIG -12
#define NETATMO_DEVLIST_FAILED -13
#define NETATMO_GETMEASURE_FAILED -13
#define NETATMO_BAD_ACCESS_TOKEN -14
#define NETATMO_TOKEN_EXPIRED -15
#define NETATMO_GETMEASURE_FAILED -14
#define NETATMO_BAD_ACCESS_TOKEN -15
#define NETATMO_TOKEN_EXPIRED -16
#define NETATMO_USER_LIMIT_REACHED -17
extern const char *g_cfgfile;
......@@ -108,6 +110,7 @@ extern netatmo_data_t netatmo;
extern netatmo_vdcd_t* devlist;
extern pthread_mutex_t g_network_mutex;
extern char g_vdc_modeluid[33];
extern char g_vdc_dsuid[35];
extern char g_lib_dsuid[35];
......
......@@ -335,6 +335,8 @@ netatmo_get_token()
}
} else if (!strcmp(key, "scope")) {
// ignore
} else if (!strcmp(key, "expire_in")) {
// ignore
} else if (!strcmp(key, "error")) {
if (type == json_type_string) {
vdc_report(LOG_ERR, "network: token reponse contains error: %s\n", json_object_get_string(val));
......@@ -465,6 +467,7 @@ int netatmo_get_devices()
return NETATMO_GETMEASURE_FAILED;
}
rc = NETATMO_OK;
json_object_object_foreach(jobj, key, val) {
enum json_type type = json_object_get_type(val);
//printf("key %s, type %d\n", key, type);
......@@ -484,9 +487,15 @@ int netatmo_get_devices()
g_access_token = NULL;
g_access_token_valid_until = 0;
}
rc = NETATMO_TOKEN_EXPIRED;
break;
}
} else if (!strcmp(key, "message")) {
vdc_report(LOG_ERR, "network: devicelist response error: %s\n", json_object_get_string(val));
if (!strcmp(json_object_get_string(val), "User usage reached")) {
rc = NETATMO_USER_LIMIT_REACHED;
break;
}
}
}
}
......@@ -615,8 +624,9 @@ int netatmo_get_devices()
free(response->memory);
free(response);
if (g_access_token == NULL) {
return NETATMO_TOKEN_EXPIRED;
/* either access token or api error like usage limit reached */
if (rc != NETATMO_OK) {
return rc;
}
if ((NULL == netatmo.base.bssid) || (strlen(netatmo.base.bssid) == 0)) {
......
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