0
Dependencies: Cayenne-MQTT-mbed Servo nfc X_NUCLEO_IDW01M1v2 NetworkSocketAPI 13
Diff: main.cpp
- Revision:
- 11:60c50eae8b81
- Parent:
- 10:8892a1436342
- Child:
- 12:32dbf8ff8d80
diff -r 8892a1436342 -r 60c50eae8b81 main.cpp --- a/main.cpp Sun Sep 01 15:22:41 2019 +0000 +++ b/main.cpp Sun Sep 01 15:50:42 2019 +0000 @@ -1,30 +1,23 @@ -/** -* Example app for using the Cayenne MQTT C++ library to send and receive example data. This example uses -* the X-NUCLEO-IDW01M1 WiFi expansion board via the X_NUCLEO_IDW01M1v2 library. -*/ - #include "MQTTTimer.h" #include "CayenneMQTTClient.h" #include "MQTTNetworkIDW01M1.h" #include "SpwfInterface.h" #include "mbed.h" -#include "XNucleoIKS01A2.h" // czujniki ruchu -#include "XNucleoNFC01A1.h" +#include "XNucleoIKS01A2.h" // czujniki ruchu i otoczenia +#include "XNucleoNFC01A1.h" // modul nfc #include "NDefLib/NDefNfcTag.h" #include "NDefLib/RecordType/RecordURI.h" AnalogIn ain(A0); - +DigitalOut led1(LED1); +DigitalOut wifiLed(LED3); /* Instantiate the expansion board */ static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); /* Retrieve the composing elements of the expansion board */ -static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer; static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor; -static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; -static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer; // Cayenne authentication info. This should be obtained from the Cayenne Dashboard. char* username = "68880f30-7425-11e9-beb3-736c9e4bf7d0"; @@ -81,8 +74,6 @@ MQTTNetwork<SpwfSAInterface> network(interface); CayenneMQTT::MQTTClient<MQTTNetwork<SpwfSAInterface>, MQTTTimer> mqttClient(network, username, password, clientID); -DigitalOut led1(LED1); - /** * Print the message info. * @param[in] message The message received from the Cayenne server. @@ -193,8 +184,16 @@ */ void loop(void) { + if(network.connected()) + { + wifiLed = 1; + } else + { + wifiLed = 0; + } + // Start the countdown timer for publishing data every 5 seconds. Change the timeout parameter to publish at a different interval. - MQTTTimer timer(5000); + MQTTTimer timer(2500); while (true) { // Yield to allow MQTT message processing. @@ -218,31 +217,18 @@ uint8_t id; float value1, value2; char buffer1[32], buffer2[32]; - int32_t axes[3]; /* Enable all sensors */ hum_temp->enable(); press_temp->enable(); - // magnetometer->enable(); - // accelerometer->enable(); - // acc_gyro->enable_x(); - // acc_gyro->enable_g(); - printf("\r\n--- Starting new run ---\r\n"); hum_temp->read_id(&id); printf("HTS221 humidity & temperature = 0x%X\r\n", id); press_temp->read_id(&id); printf("LPS22HB pressure & temperature = 0x%X\r\n", id); - magnetometer->read_id(&id); - printf("LSM303AGR magnetometer = 0x%X\r\n", id); - accelerometer->read_id(&id); - printf("LSM303AGR accelerometer = 0x%X\r\n", id); - acc_gyro->read_id(&id); - printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id); printf("\r\n"); - hum_temp->get_temperature(&value1); hum_temp->get_humidity(&value2); printf("HTS221: [temp] %7s C, [hum] %s%%\r\n", print_double(buffer1, value1), print_double(buffer2, value2)); @@ -253,20 +239,6 @@ float voltage_read = ain.read(); printf("---\r\n"); - // magnetometer->get_m_axes(axes); - // printf("LSM303AGR [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); - - // accelerometer->get_x_axes(axes); - // printf("LSM303AGR [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); - - // acc_gyro->get_x_axes(axes); - // printf("LSM6DSL [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); - - // acc_gyro->get_g_axes(axes); - // printf("LSM6DSL [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); - - - if ((error = mqttClient.publishData(DATA_TOPIC, 1, TYPE_TEMPERATURE, UNIT_CELSIUS, value1)) != CAYENNE_SUCCESS) { printf("Publish temperature failed, error: %d\n", error); } @@ -274,7 +246,6 @@ if ((error = mqttClient.publishData(DATA_TOPIC, 3, TYPE_VOLTAGE, UNIT_VOLTS, voltage_read)) != CAYENNE_SUCCESS) { printf("Publish voltage failed, error: %d\n", error); } - if ((error = mqttClient.publishData(DATA_TOPIC, 2, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, value2)) != CAYENNE_SUCCESS) { printf("Publish barometric pressure failed, error: %d\n", error);