summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-05-28 22:46:03 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2018-05-28 22:46:03 +0200
commitc374814673bb6e000074d8a82447f171b13d5499 (patch)
tree7c07f1c307af5a9030362ce126f8661e000fcd94 /main
parent8a2a8747b6672ffe3ff72671c9273c935d152eab (diff)
downloadmodern-esp-sandbox-c374814673bb6e000074d8a82447f171b13d5499.tar.gz
modern-esp-sandbox-c374814673bb6e000074d8a82447f171b13d5499.tar.bz2
modern-esp-sandbox-c374814673bb6e000074d8a82447f171b13d5499.tar.xz
modern-esp-sandbox-c374814673bb6e000074d8a82447f171b13d5499.zip
wip
Diffstat (limited to 'main')
-rw-r--r--main/main.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 7858a77..354d015 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -140,7 +140,7 @@ static int on_config_item(void *ctx, const char* key, const char* value) {
typedef int (kv_event_handler)(void *ctx, const char *key, const char *value);
static int config_read_on_line(kv_event_handler *event_handler, void *ctx, const char* line, size_t sz) {
- printf("Handling line: #%d, %s\n", sz, line);
+ // printf("Handling line: #%d, %s\n", sz, line);
char *ptr = strchr(line, '=');
if (ptr == NULL) {
printf("Could not find '='\n");
@@ -159,7 +159,7 @@ static int config_read(kv_event_handler *event_handler, void *ctx)
int pos = 0;
int fd = open("config", O_RDONLY, 0);
- printf("fd=%d\n", fd);
+ // printf("fd=%d\n", fd);
if (fd < 0) {
ret = -1;
goto fail;
@@ -177,17 +177,17 @@ static int config_read(kv_event_handler *event_handler, void *ctx)
}
ret = read(fd, buf, sizeof(buf));
- printf("read: pos=%d, ret=%d\n", (int) pos, ret);
+ // printf("read: pos=%d, ret=%d\n", (int) pos, ret);
if (ret > 0) {
char *end = (char *)memchr(buf, 0, ret);
if (end == NULL) {
- printf("too line line, could not find newline\n");
+ printf("could not find newline\n");
ret = -1;
goto fail;
} else {
*end = '\0';
size_t line_sz = end - buf;
- printf("line_sz=%d\n", line_sz);
+ // printf("line_sz=%d\n", line_sz);
pos += line_sz + 1;
ret = config_read_on_line(event_handler, ctx, buf, line_sz);
@@ -205,7 +205,7 @@ fail:
close(fd);
}
- printf("%s: ret=%d\n", __FUNCTION__, ret);
+ // printf("%s: ret=%d\n", __FUNCTION__, ret);
return ret;
}
@@ -213,7 +213,7 @@ fail:
static int config_write_kv(int fd, const char *key, const char *value) {
int ret;
char c;
- printf("Writing %s=%s\n", key, value);
+ // printf("Writing %s=%s\n", key, value);
size_t sz = strlen(key);
ret = write(fd, (char *)key, sz);
@@ -269,7 +269,7 @@ fail:
close(fd);
}
- printf("%s: ret=%d\n", __FUNCTION__, ret);
+ // printf("%s: ret=%d\n", __FUNCTION__, ret);
return ret;
}
@@ -281,7 +281,7 @@ void wifi_event_handler_cb(System_Event_t *event)
}
if (event->event_id == EVENT_STAMODE_GOT_IP) {
- printf("STA GOT IP\n");
+ // printf("STA GOT IP\n");
if (main_task_handle) {
xTaskNotify(main_task_handle, EVENTS_GOT_IP, eSetBits);
}
@@ -339,7 +339,7 @@ static int mqtt_connect() {
goto fail;
}
- printf("%s: network connected\n", __FUNCTION__);
+ // printf("%s: network connected\n", __FUNCTION__);
#if defined(MQTT_TASK)
if ((ret = MQTTStartTask(&mqtt_client)) != pdPASS) {
@@ -355,7 +355,7 @@ static int mqtt_connect() {
printf("%s: MQTTConnect:%d\n", __FUNCTION__, ret);
goto fail;
}
- printf("%s: mqtt connected\n", __FUNCTION__);
+ // printf("%s: mqtt connected\n", __FUNCTION__);
return 0;
@@ -380,14 +380,15 @@ static int mqtt_publish(const char *topic, const char *value) {
MQTTMessage m;
bzero(&m, sizeof(m));
- m.qos = QOS0;
+ m.qos = QOS1;
m.payloadlen = strlen(value);
m.payload = (void *)value;
+ m.retained = 1;
return MQTTPublish(&mqtt_client, buf, &m);
}
static void set_station_mode(struct config &config) {
- printf("STATION_MODE\n");
+ // printf("STATION_MODE\n");
if (wifi_get_opmode_default() != NULL_MODE) {
printf("Setting default station mode");
wifi_set_opmode(NULL_MODE);
@@ -457,6 +458,8 @@ void user_init() {
int ret;
os_printf("SDK version: %s, free: %d\n", system_get_sdk_version(), system_get_free_heap_size());
+ os_printf("App: instace: " CONFIG_ESPTOOLPY_APP_NUM ", build: %s\n", __TIMESTAMP__);
+ os_printf("Upgrade: boot mode: %d, version: %d, user addr=%08x, flash map: %d\n", system_get_boot_mode(), system_get_boot_version(), system_get_userbin_addr(), system_get_flash_size_map());
fs_init();