0

Dependencies:   Cayenne-MQTT-mbed Servo nfc X_NUCLEO_IDW01M1v2 NetworkSocketAPI 13

Revision:
10:8892a1436342
Parent:
9:c206c33736fe
Child:
11:60c50eae8b81
--- a/main.cpp	Wed Aug 28 18:52:43 2019 +0000
+++ b/main.cpp	Sun Sep 01 15:22:41 2019 +0000
@@ -7,11 +7,14 @@
 #include "CayenneMQTTClient.h"
 #include "MQTTNetworkIDW01M1.h"
 #include "SpwfInterface.h"
-
-
+#include "mbed.h"
+#include "XNucleoIKS01A2.h" // czujniki ruchu
+#include "XNucleoNFC01A1.h"
+#include "NDefLib/NDefNfcTag.h"
+#include "NDefLib/RecordType/RecordURI.h"
 
-#include "mbed.h"
-#include "XNucleoIKS01A2.h"
+AnalogIn ain(A0); 
+
 
 /* Instantiate the expansion board */
 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
@@ -23,6 +26,15 @@
 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";
+char* password = "19f07b4d8806fe42bdda724980634f39d8e639ba";
+char* clientID = "bb8e7cc0-74b9-11e9-94e9-493d67fd755e";
+
+// WiFi network info.
+char* ssid = "Interneto";
+char* wifiPassword = "matu1234";
+
 /* Helper function for printing floats & doubles */
 static char *print_double(char* str, double v, int decimalDigits=2)
 {
@@ -59,38 +71,12 @@
   return str;
 }
 
- 
-
-
-#include "XNucleoNFC01A1.h"
-#include "NDefLib/NDefNfcTag.h"
-#include "NDefLib/RecordType/RecordURI.h"
-
 /**
  * Write a Ndef URI message linking to st.com site.
  * Write an NDef message with a Uri record linking the st.com site
  * @param nfcNucleo expansion board where write the NDef message
  */ 
 
-
-
-
-
-
-
-
-
-
-
-// WiFi network info.
-char* ssid = "Interneto";
-char* wifiPassword = "matu1234";
-
-// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
-char* username = "68880f30-7425-11e9-beb3-736c9e4bf7d0";
-char* password = "19f07b4d8806fe42bdda724980634f39d8e639ba";
-char* clientID = "bb8e7cc0-74b9-11e9-94e9-493d67fd755e";
-
 SpwfSAInterface interface(D8, D2); // TX, RX
 MQTTNetwork<SpwfSAInterface> network(interface);
 CayenneMQTT::MQTTClient<MQTTNetwork<SpwfSAInterface>, MQTTTimer> mqttClient(network, username, password, clientID);
@@ -229,62 +215,66 @@
         if (timer.expired()) {
             int error = 0;
             
-             uint8_t id;
-  float value1, value2;
-  char buffer1[32], buffer2[32];
-  int32_t axes[3];
+            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");
+            /* 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);
 
-  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");
+            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));
+
+            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));
+            float voltage_read = ain.read();
+            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));
-    
-    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));
+            // magnetometer->get_m_axes(axes);
+            // printf("LSM303AGR [mag/mgauss]:  %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
 
-    printf("---\r\n");
+            // accelerometer->get_x_axes(axes);
+            // printf("LSM303AGR [acc/mg]:  %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
 
-    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_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]);
 
-    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);
             }
-            
+
+            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);
@@ -295,16 +285,12 @@
     }
 }
 
-
-
-
-
 /**
 * Main function.
 */
 int main()
 {   
- printf("Initializing interface\n");
+    printf("Initializing interface\n");
     interface.connect(ssid, wifiPassword, NSAPI_SECURITY_WPA2);
 
     // Set the default function that receives Cayenne messages.
@@ -325,7 +311,4 @@
         network.disconnect();
 return 0;
 
-}
-
-
-
+}
\ No newline at end of file