int main() { m2x_context *ctx = NULL; m2x_response response; const char *from = "2015-01-01T01:00:00.000Z"; const char *end = "2016-01-01T01:00:00.000Z"; char buf[2048]; ctx = m2x_open(M2X_KEY); sprintf(buf, "{\"from\": \"%s\", \"end\": \"%s\"}", from, end); printf("Deleting location hisory from: %s end: %s for device: %s\n", from, end, device_id); response = m2x_device_delete_location_history(ctx, device_id, buf); printf("Status code: %d\n", response.status); if (m2x_is_success(&response) && response.raw) { printf("%s\n", response.raw); } m2x_release_response(&response); m2x_close(ctx); return 0; }
int main() { m2x_context ctx; struct timespec last_check_time, current_time; m2x_open(M2X_KEY, &ctx); /* Set up this context for accepting incoming commands */ ctx.keepalive = 1; m2x_mqtt_connect(&ctx); while (1) { m2x_command *command = m2x_next_command(&ctx); /* If no command is available, try fetching from remotely. */ if (!command) if (m2x_fetch_pending_commands(&ctx, device_id)) command = m2x_next_command(&ctx); /* If a command was found, process it. */ if (command) { process_command(&ctx, command); m2x_release_command(&ctx, command); } else sleep(1); /* throttle loop speed */ } m2x_close(&ctx); return 0; }
void *m2x_realloc(m2x_context *ctx, void *p, size_t len) { void *p2; p2 = realloc(p, len); if (!p2) { /* Not enough memory */ m2x_close(ctx); exit(ENOMEM); } return p2; }
int main() { m2x_context *ctx = NULL; char buf[2048]; m2x_response response; ctx = m2x_open(M2X_KEY); sprintf(buf, "{\"name\": \"%s\", \"description\": \"%s\", \"tags\": \"%s\", \"visibility\": \"%s\"}", name, description, tags, visibility); printf("Update device %s: %s\n", feed_id, buf); response = m2x_device_update(ctx, feed_id, buf); printf("Status code: %d\n", response.status); if (m2x_is_success(&response) && response.raw) { printf("%s\n", response.raw); } m2x_release_response(&response); m2x_close(ctx); return 0; }
int main() { m2x_context *ctx = NULL; JSON_Value *val = NULL; JSON_Array *feeds = NULL; size_t i; ctx = m2x_open(M2X_KEY); if (m2x_json_feed_list(ctx, "", &val) == 0) { feeds = json_object_get_array(json_value_get_object(val), "feeds"); for (i = 0; i < json_array_get_count(feeds); i++) { JSON_Object* feed = json_array_get_object(feeds, i); printf("Feed id: %s\n", json_object_get_string(feed, "id")); printf(" name: %s\n", json_object_get_string(feed, "name")); printf("Contains %ld streams\n\n", json_array_get_count(json_object_get_array(feed, "streams"))); } json_value_free(val); } m2x_close(ctx); return 0; }
int main() { m2x_context ctx; struct json_token *arr = NULL, *tok = NULL, *tok2 = NULL; int i, len; m2x_response response; char buf[40]; m2x_open(M2X_KEY, &ctx); response = m2x_device_list(&ctx, ""); printf("Response Status Code: %d\n", response.status); if (m2x_is_success(&response)) { arr = (struct json_token *) response.data; printf("Total: %d\n", parse_integer(find_json_token(arr, "body.total"))); printf("Pages: %d\n", parse_integer(find_json_token(arr, "body.pages"))); printf("Limit: %d\n\n", parse_integer(find_json_token(arr, "body.limit"))); tok = find_json_token(arr, "body.devices"); if (tok) { i = 0; while (1) { sprintf(buf, "[%d].id", i); tok2 = find_json_token(tok, buf); if (!tok2) { break; } print_token_as_string("Device ID: ", tok2); sprintf(buf, "[%d].name", i); tok2 = find_json_token(tok, buf); print_token_as_string("Device Name: ", tok2); printf("\n"); i++; } } } m2x_release_response(&ctx, &response); m2x_close(&ctx); return 0; }