int ping_cmd(int argc, char **argv) { ipv6_addr_t dst; int payload_len, _num; if ((argc < 2) || (ipv6_addr_from_str(&dst, argv[1]) == NULL)) { usage(argv[0]); return 1; } if ((argc < 3) || ((_num = atoi(argv[2])) == 0)) { _num = 3; } if ((argc < 4) || ((payload_len = atoi(argv[3])) == 0)) { payload_len = 16; } atomic_store(&num, _num); atomic_store(&received, 0); seq = 0; if (recv_ntfy.callback == NULL) { uip_icmp6_echo_reply_callback_add(&recv_ntfy, handle_reply); } for (uint16_t i = 0; i < _num; i++) { _waiting = true; ping_send((uip_ipaddr_t *)&dst, payload_len); xtimer_usleep(1000000); if (_waiting) { puts("Timeout"); } } return 0; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(mqtt_demo_process, ev, data) { PROCESS_BEGIN(); printf("MQTT Demo Process\n"); if(init_config() != 1) { PROCESS_EXIT(); } update_config(); def_rt_rssi = 0x8000000; uip_icmp6_echo_reply_callback_add(&echo_reply_notification, echo_reply_handler); etimer_set(&echo_request_timer, conf.def_rt_ping_interval); PUBLISH_TRIGGER->configure(SENSORS_ACTIVE, 1); /* Main loop */ while(1) { PROCESS_YIELD(); if(ev == sensors_event && data == PUBLISH_TRIGGER) { if(state == STATE_ERROR) { connect_attempt = 1; state = STATE_REGISTERED; } } if((ev == PROCESS_EVENT_TIMER && data == &publish_periodic_timer) || ev == PROCESS_EVENT_POLL || (ev == sensors_event && data == PUBLISH_TRIGGER && PUBLISH_TRIGGER->value(BUTTON_SENSOR_VALUE_STATE) == 0)) { state_machine(); } if(ev == PROCESS_EVENT_TIMER && data == &echo_request_timer) { ping_parent(); etimer_set(&echo_request_timer, conf.def_rt_ping_interval); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(mqtt_client_process, ev, data) { PROCESS_BEGIN(); printf("CC26XX MQTT Client Process\n"); conf = &cc26xx_web_demo_config.mqtt_config; if(init_config() != 1) { PROCESS_EXIT(); } register_http_post_handlers(); def_rt_rssi = 0x8000000; uip_icmp6_echo_reply_callback_add(&echo_reply_notification, echo_reply_handler); etimer_set(&echo_request_timer, conf->def_rt_ping_interval); /* Main loop */ while(1) { PROCESS_YIELD(); if(ev == sensors_event && data == CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER) { if(state == MQTT_CLIENT_STATE_ERROR) { connect_attempt = 1; state = MQTT_CLIENT_STATE_REGISTERED; } } if(ev == httpd_simple_event_new_config) { /* * Schedule next pass in a while. When HTTPD sends us this event, it is * also in the process of sending the config page. Wait a little before * reconnecting, so as to not cause congestion. */ etimer_set(&publish_periodic_timer, NEW_CONFIG_WAIT_INTERVAL); } if(ev == cc26xx_web_demo_config_loaded_event) { update_config(); } if((ev == PROCESS_EVENT_TIMER && data == &publish_periodic_timer) || ev == PROCESS_EVENT_POLL || ev == cc26xx_web_demo_publish_event || (ev == sensors_event && data == CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER)) { state_machine(); } if(ev == PROCESS_EVENT_TIMER && data == &echo_request_timer) { ping_parent(); etimer_set(&echo_request_timer, conf->def_rt_ping_interval); } if(ev == cc26xx_web_demo_load_config_defaults) { init_config(); etimer_set(&publish_periodic_timer, NEW_CONFIG_WAIT_INTERVAL); } } PROCESS_END(); }