Use the STM32F411 Nucleo Board, Nucleo Sensor Shield, WIZnet5500 Ethernet to upload temperature data to M2X

Dependencies:   M2XStreamClient Nucleo_Sensor_Shield WIZnet_Library jsonlite mbed

Fork of M2X_Nucleo411_ESP8266-wifi by AT&T Developer Summit Hackathon 2016

Files at this revision

API Documentation at this revision

Comitter:
sjallouli
Date:
Mon Dec 28 23:52:17 2015 +0000
Parent:
6:694279899cf2
Child:
8:031089277ba0
Commit message:
Use the Nucleo Sensor Shield to get the temperature

Changed in this revision

ESP8266Interface.lib Show diff for this revision Revisions of this file
Nucleo_Sensor_Shield.lib Show annotated file Show diff for this revision Revisions of this file
WIZnet_Library.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ESP8266Interface.lib	Fri Dec 11 00:58:10 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/teams/ESP8266/code/ESP8266Interface/#03fd9333670d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Nucleo_Sensor_Shield.lib	Mon Dec 28 23:52:17 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/ST-Americas-mbed-Team/code/Nucleo_Sensor_Shield/#57888ec40e75
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WIZnet_Library.lib	Mon Dec 28 23:52:17 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/WIZnet/code/WIZnet_Library/#cb8808b47e69
--- a/main.cpp	Fri Dec 11 00:58:10 2015 +0000
+++ b/main.cpp	Mon Dec 28 23:52:17 2015 +0000
@@ -1,41 +1,92 @@
 #include "mbed.h"
 #include "M2XStreamClient.h"
-#include "ESP8266Interface.h"
+#include "WIZnetInterface.h"
 #include "TCPSocketConnection.h"
+#include "x_cube_mems.h"
 
 
 /*
-*  ESP8266 Wifi Config for nucleo 411
+*  WIZnet 5500 Config for nucleo 411
 */
-ESP8266Interface wifi(D8,D2,D3,"wifiName","wifiPassword",115200); // TX,RX,Reset,SSID,Password,Baud 
+Serial pc(SERIAL_TX, SERIAL_RX);
+SPI spi(D11, D12, D13); // mosi, miso, sclk
+
+#define USE_DHCP    1
 
+const char * IP_Addr    = "192.168.2.72";
+const char * IP_Subnet  = "255.255.255.0";
+const char * IP_Gateway = "192.168.2.2";
+unsigned char MAC_Addr[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 //
 // Fill these field in from you ATT M2X Account
 //
-char deviceId[] = "<deviceID>"; // Device you want to push to
-char streamName[] = "<streamID>"; // Stream you want to push to
-char m2xKey[] = "<deviceAPIKey>"; // Your M2X API Key or Master API Key
+char deviceId[] = "1e166d399d3996f3b9da939b6b78dab9"; // Device you want to push to
+char streamName[] = "temperature"; // Stream you want to push to
+char m2xKey[] = "cf5454902aad1b81f4bf55743fbc0ccc"; // Your M2X API Key or Master API Key
+
+
+volatile float TEMPERATURE_Value_C;
+volatile float TEMPERATURE_Value_F;
+
+/* 
+to access the data go to:
+
+https://m2x.att.com/catalog/1e166d399d3996f3b9da939b6b78dab9
+
+*/
 
 int main()
 {
-    printf("Starting...\r\n");
+  /* Create sensor board object */
+  static X_CUBE_MEMS *mems_expansion_board = X_CUBE_MEMS::Instance();
+  
+  pc.baud(115200); // console terminal to 115200 baud
+
+  spi.frequency(1000000);
+  WIZnetInterface ethernet(&spi,D10, D3);
+
+  pc.printf("Ethernet Init\r\n");
+#if USE_DHCP
+  int ret = ethernet.init(MAC_Addr);
+#else
+  int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway);
+#endif
 
-    // connect to wifi
-    wifi.init(); //Reset
-    wifi.connect(); //Use DHCP
-    printf("IP Address is %s \n\r", wifi.getIPAddress());
+  if (!ret) 
+  {
+    pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress());
+    ret = ethernet.connect();
+    
+    if (!ret) 
+    {
+      pc.printf("IP: %s, MASK: %s, GW: %s\r\n",
+      ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway());
+    }
+    else
+    {
+      pc.printf("Error ethernet.connect() - ret = %d\r\n", ret);
+      exit(0);
+    }
+  }
+  else
+  {
+    pc.printf("Error ethernet.init() - ret = %d\r\n", ret);
+    exit(0);
+  }
 
     // Initialize the M2X client
     Client client;
     M2XStreamClient m2xClient(&client, m2xKey,1,"52.22.150.98"); // api-m2x.att.com
     
-    int ret;
     volatile int randomNumber = 0;
 
-    while (true) {
-        // send a random number to M2X every 5 seconds
-        randomNumber = rand();
-        ret = m2xClient.updateStreamValue(deviceId, streamName, randomNumber);
+    while (true) 
+    {
+        // send the temperature to M2X every 5 seconds
+        mems_expansion_board->hts221.GetTemperature((float *)&TEMPERATURE_Value_C);/* Read temperature */
+        ret = m2xClient.updateStreamValue(deviceId, streamName, TEMPERATURE_Value_C);/* Send to M2X */
+        
+        pc.printf("Temperature:\t\t %f C\r\n", TEMPERATURE_Value_C);
         printf("send() returned %d\r\n", ret);
         wait(5.0);
     }