int main(int argc,char **argv){ signal(SIGPIPE,SIG_IGN); e = engine_new(); sockaddr_ server; easy_sockaddr_ip4(&server,argv[1],atoi(argv[2])); uint32_t size = atoi(argv[3]); uint32_t i = 0; for( ; i < size; ++i){ int32_t fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); easy_noblock(fd,1); int32_t ret; if(0 == (ret = easy_connect(fd,&server,NULL))) on_connected(fd,0,e); else if(ret == -EINPROGRESS){ connector *c = connector_new(fd,e,2000); engine_associate(e,c,on_connected); }else{ close(fd); printf("connect to %s %d error\n",argv[1],atoi(argv[2])); } } //engine_regtimer(e,1000,timer_callback,NULL); engine_run(e); return 0; }
NetworkInterface* easy_connect(bool log_messages, char* WiFiSSID, char* WiFiPassword ) { // This functionality only makes sense when using WiFi #if defined (EASY_CONNECT_WIFI) // We essentially want to populate the _ssid and _password and then call easy_connect() again. if (WiFiSSID != NULL) { if(strlen(WiFiSSID) > WIFI_SSID_MAX_LEN) { printf("ERROR - WiFi SSID is too long - %d vs %d.\n", strlen(WiFiSSID), WIFI_SSID_MAX_LEN); return NULL; } _ssid = WiFiSSID; } if (WiFiPassword != NULL) { if(strlen(WiFiPassword) > WIFI_PASSWORD_MAX_LEN) { printf("ERROR - WiFi Password is too long - %d vs %d\n", strlen(WiFiPassword), WIFI_PASSWORD_MAX_LEN); return NULL; } _password = WiFiPassword; } #endif // EASY_CONNECT_WIFI return easy_connect(log_messages); }
int main(int argc, char **argv) { struct nefit_easy easy; char *serial_number, *access_key, *password; EASY_UNUSED(argc); EASY_UNUSED(argv); /* init library */ xmpp_initialize(); serial_number = getenv("NEFIT_SERIAL_NUMBER"); access_key = getenv("NEFIT_ACCESS_KEY"); password = getenv("NEFIT_PASSWORD"); if (!serial_number || !access_key || !password) { printf("The following environmental variabled must be set\n"); printf("NEFIT_SERIAL_NUMBER=123456789\n"); printf("NEFIT_ACCESS_KEY=abcdefhijklmnopq\n"); printf("NEFIT_PASSWORD=wachtw\n"); exit(1); } easy_connect(&easy, serial_number, access_key, password, value_obtained); get_values(&easy); //manual_temperature(&easy, 23); //clock_mode(&easy); /* enter the event loop */ xmpp_run(easy.xmpp_ctx); /* release our connection and context */ xmpp_conn_release(easy.xmpp_conn); xmpp_ctx_free(easy.xmpp_ctx); /* shutdown lib */ xmpp_shutdown(); return 0; }
// Entry point to the program int main() { unsigned int seed; size_t len; #ifdef MBEDTLS_ENTROPY_HARDWARE_ALT // Used to randomize source port mbedtls_hardware_poll(NULL, (unsigned char *) &seed, sizeof seed, &len); #elif defined MBEDTLS_TEST_NULL_ENTROPY #warning "mbedTLS security feature is disabled. Connection will not be secure !! Implement proper hardware entropy for your selected hardware." // Used to randomize source port mbedtls_null_entropy_poll( NULL,(unsigned char *) &seed, sizeof seed, &len); #else #error "This hardware does not have entropy, endpoint will not register to Connector.\ You need to enable NULL ENTROPY for your application, but if this configuration change is made then no security is offered by mbed TLS.\ Add MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES and MBEDTLS_TEST_NULL_ENTROPY in mbed_app.json macros to register your endpoint." #endif srand(seed); red_led = LED_OFF; blue_led = LED_OFF; status_ticker.attach_us(blinky, 250000); // Keep track of the main thread mainThread = osThreadGetId(); printf("\nStarting mbed Client example in "); #if defined (MESH) || (MBED_CONF_LWIP_IPV6_ENABLED==true) printf("IPv6 mode\n"); #else printf("IPv4 mode\n"); #endif mbed_trace_init(); NetworkInterface* network = easy_connect(true); if(network == NULL) { printf("\nConnection to Network Failed - exiting application...\n"); return -1; } // we create our button and LED resources ButtonResource button_resource; LedResource led_resource; BigPayloadResource big_payload_resource; #ifdef TARGET_K64F // On press of SW3 button on K64F board, example application // will call unregister API towards mbed Device Connector //unreg_button.fall(&mbed_client,&MbedClient::test_unregister); unreg_button.fall(&unregister); // Observation Button (SW2) press will send update of endpoint resource values to connector obs_button.fall(&button_clicked); #else // Send update of endpoint resource values to connector every 15 seconds periodically timer.attach(&button_clicked, 15.0); #endif // Create endpoint interface to manage register and unregister mbed_client.create_interface(MBED_SERVER_ADDRESS, network); // Create Objects of varying types, see simpleclient.h for more details on implementation. M2MSecurity* register_object = mbed_client.create_register_object(); // server object specifying connector info M2MDevice* device_object = mbed_client.create_device_object(); // device resources object // Create list of Objects to register M2MObjectList object_list; // Add objects to list object_list.push_back(device_object); object_list.push_back(button_resource.get_object()); object_list.push_back(led_resource.get_object()); object_list.push_back(big_payload_resource.get_object()); // Set endpoint registration object mbed_client.set_register_object(register_object); // Register with mbed Device Connector mbed_client.test_register(register_object, object_list); registered = true; while (true) { updates.wait(25000); if(registered) { if(!clicked) { mbed_client.test_update_register(); } }else { break; } if(clicked) { clicked = false; button_resource.handle_button_click(); } } mbed_client.test_unregister(); status_ticker.detach(); }