Code Sample for ERS4 GEII UNICE ERS4

Dependencies:   C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed

Fork of DU4SmartCities by Philippe Bazot

Files at this revision

API Documentation at this revision

Comitter:
bazot
Date:
Thu Jan 25 11:15:06 2018 +0000
Parent:
19:48522ea6acef
Commit message:
Firts version for GEII ERS4

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 48522ea6acef -r 3045570c01ff main.cpp
--- a/main.cpp	Tue Oct 04 07:54:27 2016 +0000
+++ b/main.cpp	Thu Jan 25 11:15:06 2018 +0000
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2015 IBM Corp.
+ * Copyright (c) 2014, 2015, 2016, 2017 IBM Corp.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -35,11 +35,12 @@
 #define __APP_SW_REVISION__ "18"
 
 // Configuration values needed to connect to IBM IoT Cloud
-#define ORG "!!!!!!"             // For a registered connection, replace with your org
-#define ID  "!!!!!!"              // For a registered connection, replace with your id
-#define AUTH_TOKEN "!!!!!!"                // For a registered connection, replace with your auth-token
-#define TYPE "!!!!!!"      // For a registered connection, replace with your type
-#define DEVICE_NAME "!!!!!!!"     // Replace with your own name
+#define ORG ""             // For a registered connection, replace with your org
+#define ID  ""             // For a registered connection, replace with your id
+#define AUTH_TOKEN ""      // For a registered connection, replace with your auth-token
+#define TYPE ""            // For a registered connection, replace with your type
+#define DEVICE_NAME ""     // Replace with your own name
+// End Of Configuration values needed to connect to IBM IoT Cloud
 
 #define MQTT_PORT 1883
 #define MQTT_TLS_PORT 8883
@@ -297,11 +298,18 @@
 
 
 int connect(MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTEthernet* ipstack)
-{   
-    const char* iot_ibm = ".messaging.internetofthings.ibmcloud.com";
+{  
+
+    // The following 3 lines of code are ONLY used when connected to IBM Cloud !  
+    // const char* iot_ibm = ".messaging.internetofthings.ibmcloud.com";
+    // char hostname[strlen(org) + strlen(iot_ibm) + 1];
+    // sprintf(hostname, "%s%s", org, iot_ibm);
     
-    char hostname[strlen(org) + strlen(iot_ibm) + 1];
-    sprintf(hostname, "%s%s", org, iot_ibm);
+    //Instead, for a connection to a local PC, specify HERE BELOW the IP @ of the local PC!!!
+    char hostname[]="192.168.0.6";
+    
+    
+    
     EthernetInterface& eth = ipstack->getEth();
     ip_addr = eth.getIPAddress();
     gateway_addr = eth.getGateway();
@@ -406,10 +414,10 @@
     char* pubTopic = "iot-2/evt/status/fmt/json";
             
     char buf[250];
+    //sprintf(buf, "%0.4f \",\"%0.4f \",\"%0.4f", sensor.temp(),ain1.read(),ain2.read());
     sprintf(buf,
-     "{\"d\":{\"myName\":\"IoT mbed\",\"accelX\":%0.4f,\"accelY\":%0.4f,\"accelZ\":%0.4f,\"temp\":%0.4f,\"joystick\":\"%s\",\"potentiometer1\":%0.4f,\"potentiometer2\":%0.4f,\"Latitude\":43.7,\"Longitude\":7.25,\"Rfid\":12345}}",
+     "{\"d\":{\"name\":\"IoT mbed\",\"accelX\":%0.4f,\"accelY\":%0.4f,\"accelZ\":%0.4f,\"temp\":%0.4f,\"joystick\":\"%s\",\"potentiometer1\":%0.4f,\"potentiometer2\":%0.4f,\"lat\":43.9,\"long\":7.25,\"Rfid\":12345}}",
             MMA.x(), MMA.y(), MMA.z(), sensor.temp(), joystickPos, ain1.read(), ain2.read());
-     
     message.qos = MQTT::QOS0;
     message.retained = false;
     message.dup = false;