Ultrasonic-Servo Combo
Dependencies: Cayenne-MQTT-mbed mbed Servo X_NUCLEO_IDW01M1v2 NetworkSocketAPI HCSR04
Diff: main.cpp
- Revision:
- 2:445f09de09bd
- Parent:
- 1:a2d8aec2bb92
- Child:
- 3:4056f1cd4c47
diff -r a2d8aec2bb92 -r 445f09de09bd main.cpp --- a/main.cpp Thu Oct 20 22:57:56 2016 +0000 +++ b/main.cpp Wed Oct 26 23:01:03 2016 +0000 @@ -14,12 +14,12 @@ // Cayenne authentication info. This should be obtained from the Cayenne Dashboard. char* username = "MQTT_USERNAME"; +char* password = "MQTT_PASSWORD"; char* clientID = "CLIENT_ID"; -char* password = "MQTT_PASSWORD"; SpwfSAInterface interface(D8, D2); // TX, RX MQTTNetwork<SpwfSAInterface> network(interface); -Cayenne::MQTTClient<MQTTNetwork<SpwfSAInterface>, MQTTTimer> mqttClient(network); +CayenneMQTT::MQTTClient<MQTTNetwork<SpwfSAInterface>, MQTTTimer> mqttClient(network, username, password, clientID); DigitalOut led1(LED1); @@ -27,7 +27,7 @@ * Print the message info. * @param[in] message The message received from the Cayenne server. */ -void outputMessage(Cayenne::MessageData& message) +void outputMessage(CayenneMQTT::MessageData& message) { switch (message.topic) { case COMMAND_TOPIC: @@ -48,11 +48,11 @@ printf(" type=%s", message.type); } for (size_t i = 0; i < message.valueCount; ++i) { - if (message.values[i].value) { - printf(" value=%s", message.values[i].value); + if (message.getValue(i)) { + printf(" value=%s", message.getValue(i)); } - if (message.values[i].unit) { - printf(" unit=%s", message.values[i].unit); + if (message.getUnit(i)) { + printf(" unit=%s", message.getUnit(i)); } } if (message.id) { @@ -65,7 +65,7 @@ * Handle messages received from the Cayenne server. * @param[in] message The message received from the Cayenne server. */ -void messageArrived(Cayenne::MessageData& message) +void messageArrived(CayenneMQTT::MessageData& message) { int error = 0; // Add code to process the message. Here we just ouput the message data. @@ -75,9 +75,9 @@ switch(message.channel) { case 0: // Set the onboard LED state - led1 = atoi(message.values[0].value); + led1 = atoi(message.getValue()); // Publish the updated LED state - if ((error = mqttClient.publishData(DATA_TOPIC, message.channel, NULL, NULL, message.values[0].value)) != CAYENNE_SUCCESS) { + if ((error = mqttClient.publishData(DATA_TOPIC, message.channel, NULL, NULL, message.getValue())) != CAYENNE_SUCCESS) { printf("Publish LED state failure, error: %d\n", error); } break; @@ -105,7 +105,7 @@ wait(2); } - if ((error = mqttClient.connect(username, clientID, password)) != MQTT::SUCCESS) { + if ((error = mqttClient.connect()) != MQTT::SUCCESS) { printf("MQTT connect failed, error: %d\n", error); return error; } @@ -122,8 +122,8 @@ // Send device info. Here we just send some example values for the system info. These should be changed to use actual system data, or removed if not needed. mqttClient.publishData(SYS_VERSION_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, CAYENNE_VERSION); mqttClient.publishData(SYS_MODEL_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "mbedDevice"); - mqttClient.publishData(SYS_CPU_MODEL_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "CPU Model"); - mqttClient.publishData(SYS_CPU_SPEED_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "1000000000"); + //mqttClient.publishData(SYS_CPU_MODEL_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "CPU Model"); + //mqttClient.publishData(SYS_CPU_SPEED_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "1000000000"); return CAYENNE_SUCCESS; }