0
Dependencies: Cayenne-MQTT-mbed Servo nfc X_NUCLEO_IDW01M1v2 NetworkSocketAPI 13
Diff: main.cpp
- Revision:
- 13:7b3b429e9731
- Parent:
- 12:32dbf8ff8d80
- Child:
- 14:c5aab7546de9
diff -r 32dbf8ff8d80 -r 7b3b429e9731 main.cpp --- a/main.cpp Thu Sep 05 20:00:08 2019 +0000 +++ b/main.cpp Sat Sep 07 08:57:23 2019 +0000 @@ -8,7 +8,6 @@ #include "NDefLib/NDefNfcTag.h" #include "NDefLib/RecordType/RecordURI.h" #include "Servo.h" - /* Instantiate the expansion board */ static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); @@ -132,7 +131,8 @@ case 4: // Set the onboard LED state & actuator PIN myLed = atoi(message.getValue()); - + wait(0.1); + myservo = myservo <= 0 ? 0.5 : -0.05; actuatorPin2 = atoi(message.getValue()); // Publish the updated LED state if ((error = mqttClient.publishData(DATA_TOPIC, message.channel, NULL, NULL, message.getValue())) != CAYENNE_SUCCESS) { @@ -210,7 +210,7 @@ int error = 0; uint8_t id; - float value1, value2; + float value1, value2, value3; // char buffer1[32], buffer2[32]; /* Enable all sensors */ @@ -220,6 +220,7 @@ press_temp->read_id(&id); hum_temp->get_temperature(&value1); + hum_temp->get_humidity(&value3); // press_temp->get_temperature(&value1); press_temp->get_pressure(&value2); // printf("LPS22HB: [temp] %7s C, [press] %s mbar\r\n", print_double(buffer1, value1), print_double(buffer2, value2)); @@ -228,6 +229,10 @@ if ((error = mqttClient.publishData(DATA_TOPIC, 1, TYPE_TEMPERATURE, UNIT_CELSIUS, value1)) != CAYENNE_SUCCESS) { printf("Publish temperature failed, error: %d\n", error); } + + if ((error = mqttClient.publishData(DATA_TOPIC, 5, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT, value3)) != CAYENNE_SUCCESS) { + printf("Publish humidity failed, error: %d\n", error); + } if ((error = mqttClient.publishData(DATA_TOPIC, 3, TYPE_VOLTAGE, UNIT_VOLTS, voltage_read)) != CAYENNE_SUCCESS) { printf("Publish voltage failed, error: %d\n", error); @@ -255,10 +260,6 @@ // Set the default function that receives Cayenne messages. mqttClient.setDefaultMessageHandler(messageArrived); - for(float p=0; p<1.0; p += 0.2) { - myservo = p; - wait(1.5); -} // Connect to Cayenne. if (connectClient() == CAYENNE_SUCCESS) {