989
Dependencies: mbed Servo X_NUCLEO_IKS01A2 X_NUCLEO_IDW01M1v2 NetworkSocketAPI NDefLib MQTT
Diff: main.cpp
- Revision:
- 16:233b89a6b72f
- Parent:
- 14:641560b57584
- Child:
- 17:83d0cd810ed3
--- a/main.cpp Wed Sep 28 14:59:32 2016 +0000 +++ b/main.cpp Wed Sep 28 15:36:07 2016 +0000 @@ -42,6 +42,10 @@ #define MQTT_PORT 1883 #define MQTT_TLS_PORT 8883 #define IBM_IOT_PORT MQTT_PORT +// WiFi network credential +#define SSID "crespan" // Network must be visible otherwise it can't connect +#define PASSW "" +#warning "Wifi password empty" char id[30] = ID; // mac without colons char org[12] = ORG; @@ -175,13 +179,11 @@ LOG("Publishing %s\n", buf); return client->publish(pubTopic, message); } - int main() { - int err; - const char * ssid = "crespan"; // Network must be visible otherwise it can't connect - const char * seckey = "Elfrontal0"; + const char * ssid = SSID; // Network must be visible otherwise it can't connect + const char * seckey = PASSW; // Timer tyeld; @@ -196,13 +198,11 @@ pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n"); pc.printf("\r\nconnecting to AP\r\n"); -//****************************************************************** -// quickstartMode = (strcmp(org, "quickstart") == 0); - if (strcmp(org, "quickstart") == 0){quickstartMode = true;} - MQTTWiFi ipstack(spwf, ssid, seckey, NSAPI_SECURITY_WPA2); - MQTT::Client<MQTTWiFi, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack); - if (quickstartMode){ + if (strcmp(org, "quickstart") == 0){quickstartMode = true;} + MQTTWiFi ipstack(spwf, ssid, seckey, NSAPI_SECURITY_WPA2); + MQTT::Client<MQTTWiFi, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack); + if (quickstartMode){ char mac[50]; char *digit=NULL; sprintf (mac,"%s",ipstack.getWiFi().get_mac_address()); @@ -213,16 +213,15 @@ strcat (id, digit); digit = strtok (NULL, ":"); } - } - attemptConnect(&client, &ipstack); - if (connack_rc == MQTT_NOT_AUTHORIZED || connack_rc == MQTT_BAD_USERNAME_OR_PASSWORD) - { - while (true) - wait(1.0); // Permanent failures - don't retry - } - int count = 0; -// tyeld.start(); - + } + attemptConnect(&client, &ipstack); + if (connack_rc == MQTT_NOT_AUTHORIZED || connack_rc == MQTT_BAD_USERNAME_OR_PASSWORD) + { + while (true) + wait(1.0); // Permanent failures - don't retry + } + int count = 0; +// tyeld.start(); while (true) { if (++count == /*100*/2)