Last active
August 6, 2018 15:13
-
-
Save nliviu/79eb9c96fc92fa60fe458fa8c949abc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void print_mgos_ro_vars(struct json_out *out, va_list *ap) { | |
struct mgos_ro_vars *p = va_arg(*ap, struct mgos_ro_vars *); | |
json_printf(out, | |
"{mac_address: %Q, arch: %Q, fw_version: %Q, fw_timestamp: %Q, " | |
"fw_id: %Q}", | |
p->mac_address, p->arch, p->fw_version, p->fw_timestamp, | |
p->fw_id); | |
} | |
static void main_timer_cb(void *arg) { | |
(void) arg; | |
time_t now = time(0); | |
const char *fw_timestamp = mgos_sys_ro_vars_get_fw_timestamp(); | |
mgos_mqtt_pubf("test1", 1, false, "{fw_timestamp: %Q, now: %lu}", fw_timestamp, | |
now); | |
int arr[] = {1, 2, 3, 4}; | |
mgos_mqtt_pubf("test2", 1, false, "{now: %lu, mgos_ro_vars: %M, array: %M}", | |
now, print_mgos_ro_vars, &mgos_sys_ro_vars, json_printf_array, | |
arr, sizeof(arr), sizeof(arr[0]), "%d"); | |
} | |
/* | |
mosquitto_sub -t test1 -t test2 | |
{"fw_timestamp": "2018-08-06T07:36:37Z", "now": 1533541034} | |
{"now": 1533541034, "mgos_ro_vars": {"mac_address": "30AEA4323558", "arch": "esp32", "fw_version": "1.0", "fw_timestamp": "2018-08-06T07:36:37Z", "fw_id": "20180806-073637/???"}, "array": [1, 2, 3, 4]} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment