Local copy
Dependencies: C12832_lcd ConfigFile EthernetInterface LM75B MMA7660 MQTTPacket mbed-rtos mbed
Fork of IBMIoTClientExampleForLPC1768 by
Diff: src/QuickstartClient.cpp
- Revision:
- 3:ca5b84eb8f3b
- Parent:
- 2:25ddff75a8c7
- Child:
- 5:1b54a0b7b39d
--- a/src/QuickstartClient.cpp Mon Jun 23 20:12:18 2014 +0000 +++ b/src/QuickstartClient.cpp Tue Jun 24 10:29:07 2014 +0000 @@ -18,8 +18,8 @@ macAddress = mac; //Generate topic string - string str = "iot-2/evt/status/fmt/json"; - strcpy(topic, str.c_str()); + memcpy(topic, "iot-2/evt/status/fmt/json", 25); + topic[25] = '\0'; loadConfig(); @@ -30,38 +30,42 @@ ConfigFile cfg; - char value[BUFSIZ]; + char value[30]; + char value1[30]; + char value2[30]; + char value3[30]; if (cfg.read("/local/device.cfg")) { quickstartMode = false; - if (cfg.getValue("org", &value[0], sizeof(value))) { + if (cfg.getValue("org", value, sizeof(value))) { stringstream ss(value); ss >> org; } else { lcd.printf("No org defined in config\n"); } - if (cfg.getValue("type", &value[0], sizeof(value))) { - stringstream ss(value); + if (cfg.getValue("type", value1, sizeof(value1))) { + stringstream ss(value1); ss >> type; } else { lcd.printf("No type defined in config\n"); } - if (cfg.getValue("id", &value[0], sizeof(value))) { - stringstream ss(value); + if (cfg.getValue("id", value2, sizeof(value2))) { + stringstream ss(value2); ss >> id; } else { lcd.printf("No id defined in config\n"); } - if (cfg.getValue("token", &value[0], sizeof(value))) { - stringstream ss(value); + if (cfg.getValue("token", value3, sizeof(value3))) { + stringstream ss(value3); ss >> token; } else { lcd.printf("No token defined in config\n"); } + } else { org = "quickstart"; type = "iotsample-mbed-lpc1768"; @@ -118,18 +122,14 @@ //Construct client ID string str = string("d:") + org + ":" + type + ":" + id; - char clientId[ strlen(str.c_str()) + 1]; - strcpy(clientId, str.c_str()); + char clientId[str.size()]; + memcpy(clientId, str.c_str(), str.size() + 1); //Set MQTT connect options data.clientID.cstring = clientId; data.keepAliveInterval = 20; data.cleansession = 1; data.MQTTVersion = 3; - if (!quickstartMode) { - data.password.cstring = token.c_str(); - - } //Attempt MQTT connect len = MQTTSerialize_connect(buf, buflen, &data);