Created
October 25, 2016 15:16
-
-
Save anonymous/61d7360c0a27eb2c4922b50ffb2be1ca to your computer and use it in GitHub Desktop.
app_main.c
This file contains hidden or 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
#include <stdio.h> | |
#include "common/platform.h" | |
#include "fw/src/mg_app.h" | |
#include "fw/src/mg_sys_config.h" | |
#include "fw/src/mg_mongoose.h" | |
#define COAP_OPTION_URI_PATH 11 | |
#define COAP_MULTICAST_GROUP 0xE00001BB //"224.0.1.187" | |
#define COAP_SEND_INTERVAL 0.05 | |
uint16_t id = 0; | |
double coap_send_status_timer = 0; | |
char *coap_port = "udp://:5683"; | |
struct mg_connection *coap_connection; | |
void coap_send_message() { | |
struct mg_coap_message msg; | |
memset(&msg, 0, sizeof(msg)); | |
msg.msg_id = id++; | |
msg.msg_type = MG_COAP_MSG_NOC; | |
msg.code_class = 0; | |
msg.code_detail = 30; | |
mg_coap_add_option(&msg, COAP_OPTION_URI_PATH, "uri", 3); | |
mg_coap_add_option(&msg, COAP_OPTION_URI_PATH, "a", 1); | |
mg_coap_add_option(&msg, 3412, "text", 4); | |
mg_coap_add_option(&msg, 3420, "text2", 5); | |
//msg.payload = "test"; | |
coap_connection->sa.sin.sin_addr.s_addr = htonl(COAP_MULTICAST_GROUP); | |
mg_coap_send_message(coap_connection, &msg); | |
LOG(LL_INFO,("Sending %d", msg.msg_id)); | |
} | |
void coap_loop_handler(struct mg_connection *nc) { | |
double now = mg_time(); | |
if (coap_send_status_timer == 0 || now > (coap_send_status_timer + 0.05)) { | |
coap_send_status_timer = now; | |
coap_send_message(); | |
} | |
} | |
static void coap_handler(struct mg_connection *nc, int ev, void *p) { | |
struct mg_coap_message *cm = (struct mg_coap_message *) p; | |
switch (ev) { | |
case MG_EV_COAP_CON: | |
// Confirmable message, needs acknowledge | |
LOG(LL_INFO,("CON with msg_id = %d received", cm->msg_id)); | |
break; | |
case MG_EV_COAP_NOC: | |
LOG(LL_INFO,("NOC with msg_id = %d received", cm->msg_id)); | |
break; | |
case MG_EV_COAP_ACK: | |
case MG_EV_COAP_RST: { | |
LOG(LL_INFO,("ACK/RST with msg_id = %d received", cm->msg_id)); | |
break; | |
} | |
case MG_EV_POLL: | |
coap_loop_handler(coap_connection); | |
break; | |
} | |
} | |
enum mg_app_init_result mg_app_init(void) { | |
coap_connection = mg_bind(mg_get_mgr(), coap_port, coap_handler); | |
if (coap_connection == NULL) { | |
LOG(LL_ERROR, ("Unable to start listener at %s", coap_port)); | |
} | |
mg_set_protocol_coap(coap_connection); | |
return MG_APP_INIT_SUCCESS; | |
} |
This file contains hidden or 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
S0hello.bin.0@20000000+124096+.2001b8b1 | |
cc3200_init 972329 hello 2016102515 (20161025-150452/master@a982166d+) | |
cc3200_init 7020 Mongoose IoT Firmware 2016102514 (20161025-143237/master@a982166d+) | |
cc3200_init 25300 RAM: 137276 total, 124108 free | |
start_nwp 739409 NWP v2.7.0.0 started, host driver v1.0.1.6 | |
cc3200_init 17940 Boot cfg 0: 0xfffffffffffffffe, 0x0, hello.bin.0 @ 0x20000000, spiffs.img.0 | |
fs_mount_idx 12989 Mounting spiffs.img.0.0 0xfffffffffffffffe | |
mg_sys_config_init 91380 MAC: F4B85ECB8CDD | |
mg_wifi_setup_ap 1451510 AP Mongoose_CB8CDD configured | |
mg_sys_config_init_http 5369 HTTP server started on [80] | |
cc3200_init 4950 Init done, RAM: 120916 free | |
coap_send_message 4950 Sending 0 | |
mg_wifi_on_change_cb 3420 WiFi: ready, IP 192.168.4.1 | |
coap_send_message 46019 Sending 1 | |
coap_send_message 50159 Sending 2 | |
coap_send_message 50129 Sending 3 | |
coap_send_message 50130 Sending 4 | |
coap_send_message 50159 Sending 5 | |
coap_send_message 50130 Sending 6 | |
coap_send_message 50159 Sending 7 | |
coap_send_message 50129 Sending 8 | |
coap_send_message 50129 Sending 9 | |
coap_send_message 50159 Sending 10 | |
coap_send_message 50130 Sending 11 | |
coap_send_message 50159 Sending 12 | |
coap_send_message 67090 Sending 13 | |
coap_send_message 50129 Sending 14 | |
coap_send_message 50159 Sending 15 | |
coap_send_message 50130 Sending 16 | |
coap_send_message 50159 Sending 17 | |
coap_send_message 50130 Sending 18 | |
coap_send_message 50159 Sending 19 | |
coap_send_message 50130 Sending 20 | |
coap_send_message 50129 Sending 21 | |
coap_send_message 50159 Sending 22 | |
coap_send_message 50130 Sending 23 | |
coap_send_message 50159 Sending 24 | |
coap_send_message 50130 Sending 25 | |
coap_send_message 50130 Sending 26 | |
coap_send_message 50159 Sending 27 | |
coap_send_message 50129 Sending 28 | |
coap_send_message 50159 Sending 29 | |
coap_send_message 50130 Sending 30 | |
coap_send_message 50130 Sending 31 | |
coap_send_message 50159 Sending 32 | |
coap_send_message 51370 Sending 33 | |
coap_send_message 50129 Sending 34 | |
coap_send_message 50159 Sending 35 | |
coap_send_message 50130 Sending 36 | |
coap_send_message 50159 Sending 37 | |
coap_send_message 50130 Sending 38 | |
coap_send_message 50130 Sending 39 | |
........ | |
coap_send_message 50160 Sending 1256 | |
coap_send_message 50129 Sending 1257 | |
umm_oom_cb 50100 Failed to allocate 34 | |
coap_send_message 4440 Sending 1258 | |
umm_oom_cb 46619 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
coap_send_message 4440 Sending 1259 | |
umm_oom_cb 32399 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4439 Failed to allocate 16 | |
coap_send_message 4440 Sending 1260 | |
umm_oom_cb 32370 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
coap_send_message 4440 Sending 1261 | |
umm_oom_cb 32399 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4439 Failed to allocate 16 | |
coap_send_message 4410 Sending 1262 | |
umm_oom_cb 32399 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
coap_send_message 4440 Sending 1263 | |
umm_oom_cb 32370 Failed to allocate 16 | |
umm_oom_cb 4439 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
coap_send_message 4440 Sending 1264 | |
umm_oom_cb 32399 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
umm_oom_cb 4440 Failed to allocate 16 | |
coap_send_message 4439 Sending 1265 |
This file contains hidden or 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
APP = hello | |
APP_MODULES = src | |
APP_FS_PATH = $(CURDIR)/fs | |
APP_CONF_SCHEMA = $(CURDIR)/src/conf_schema.yaml | |
MG_ENABLE_JS = 0 | |
MG_ENABLE_CLUBBY = 0 | |
MG_FEATURES = -DMG_ENABLE_HTTP_STREAMING_MULTIPART \ | |
-DMG_NO_BSD_SOCKETS \ | |
-DMG_LOCALS \ | |
-DMG_FS_SPIFFS \ | |
-DCC3200_FS_SLFS \ | |
-DDISABLE_C_CLUBBY \ | |
-DMG_ENABLE_SSL \ | |
-DMG_ENABLE_COAP | |
include $(REPO_PATH)/fw/platforms/$(PLATFORM)/Makefile.build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment