Test

Dependencies:   Cayenne-MQTT-mbed ESP8266Interface mbed

Fork of Cayenne-ESP8266Interface by myDevicesIoT

Revision:
10:4f0cd8d9fbd5
Parent:
9:4302de820980
diff -r 4302de820980 -r 4f0cd8d9fbd5 main.cpp
--- a/main.cpp	Fri Nov 11 18:23:45 2016 +0000
+++ b/main.cpp	Wed Oct 11 14:01:48 2017 +0000
@@ -9,18 +9,18 @@
 #include "ESP8266Interface.h"
 
 // WiFi network info.
-char* ssid = "ssid";
-char* wifiPassword = "wifiPassword";
+char* wifi_ssid = "FERRARELLE";
+char* wifi_password = "effervescentenaturale2017";
 
 // Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
-char* username = "MQTT_USERNAME";
-char* password = "MQTT_PASSWORD";
-char* clientID = "CLIENT_ID";
+char* username = "4c713520-d0e3-11e6-ae8c-f90e83be502a";
+char* password = "93c1cdfaafe5a296a36d6e5247eb73c2b1ab01d4";
+char* clientID = "3070fd00-ae74-11e7-8c02-137ff2c4ffef";
 
 // Use Cayenne IP instead of "mqtt.mydevices.com" since the ESP8266Interface doesn't support looking up the domain name.
-#define CAYENNE_IP "57.7.250.10"
+#define CAYENNE_IP "34.226.39.40"
 
-ESP8266Interface interface(D8, D2, D3, ssid, wifiPassword, 115200); // TX, RX, Reset, SSID, Password, Baud
+ESP8266Interface interface(D8, D2, D3, wifi_ssid, wifi_password, 115200); // TX, RX, Reset, SSID, Password, Baud
 MQTTNetwork<ESP8266Interface> network(interface);
 CayenneMQTT::MQTTClient<MQTTNetwork<ESP8266Interface>, MQTTTimer> mqttClient(network, username, password, clientID);
 
@@ -132,6 +132,10 @@
     // Start the countdown timer for publishing data every 5 seconds. Change the timeout parameter to publish at a different interval.
     MQTTTimer timer(5000);
 
+	static float temperature = 0;
+	static float luminosity = 10;
+	static float pressure = -10;
+
     while (true) {
         // Yield to allow MQTT message processing.
         mqttClient.yield(1000);
@@ -150,13 +154,13 @@
         // Publish some example data every few seconds. This should be changed to send your actual data to Cayenne.
         if (timer.expired()) {
             int error = 0;
-            if ((error = mqttClient.publishData(DATA_TOPIC, 0, TYPE_TEMPERATURE, UNIT_CELSIUS, 30.5)) != CAYENNE_SUCCESS) {
+            if ((error = mqttClient.publishData(DATA_TOPIC, 0, TYPE_TEMPERATURE, UNIT_CELSIUS, temperature++)) != CAYENNE_SUCCESS) {
                 printf("Publish temperature failed, error: %d\n", error);
             }
-            if ((error = mqttClient.publishData(DATA_TOPIC, 1, TYPE_LUMINOSITY, UNIT_LUX, 1000)) != CAYENNE_SUCCESS) {
+            if ((error = mqttClient.publishData(DATA_TOPIC, 1, TYPE_LUMINOSITY, UNIT_LUX, luminosity++)) != CAYENNE_SUCCESS) {
                 printf("Publish luminosity failed, error: %d\n", error);
             }
-            if ((error = mqttClient.publishData(DATA_TOPIC, 2, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, 800)) != CAYENNE_SUCCESS) {
+            if ((error = mqttClient.publishData(DATA_TOPIC, 2, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, pressure++)) != CAYENNE_SUCCESS) {
                 printf("Publish barometric pressure failed, error: %d\n", error);
             }
             // Restart the countdown timer for publishing data every 5 seconds. Change the timeout parameter to publish at a different interval.