ACKme WiFi module + Nucleo MEMS module example. Connect and publish sensor data to M2X.

Dependencies:   M2XStreamClient WiConnect Nucleo_Sensor_Shield jsonlite mbed

Fork of m2x-MEMS_ACKme_Wifi_demo by David Kwak

Files at this revision

API Documentation at this revision

Comitter:
davidkwak
Date:
Thu Dec 11 20:56:33 2014 +0000
Child:
1:276e4607719f
Commit message:
Initial publish/commit of an example with the ACKme WiFi module and X-NUCLEO-IKS01A1 sensor board.

Changed in this revision

M2XStreamClient.lib Show annotated file Show diff for this revision Revisions of this file
WiConnect.lib Show annotated file Show diff for this revision Revisions of this file
X-CUBE-MEMS1.lib Show annotated file Show diff for this revision Revisions of this file
jsonlite.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
target_config.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/M2XStreamClient.lib	Thu Dec 11 20:56:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ATT-M2X-team/code/M2XStreamClient/#0d574742208f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WiConnect.lib	Thu Dec 11 20:56:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ACKme/code/WiConnect/#bc2b10351ee3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/X-CUBE-MEMS1.lib	Thu Dec 11 20:56:33 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mridup/code/X-CUBE-MEMS1/#5304cf34f9a3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jsonlite.lib	Thu Dec 11 20:56:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/citrusbyte/code/jsonlite/#807034181e02
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 11 20:56:33 2014 +0000
@@ -0,0 +1,206 @@
+#include "mbed.h"
+// include target specific defines
+#include "target_config.h"
+// include X-CUBE-MEMS1 Library
+#include "x_cube_mems.h"
+// include the Wiconnect Host Library API header
+#include "Wiconnect.h"
+// include M2X Library
+#include "M2XStreamClient.h"
+
+/**
+  * Connect the ACKme WiFi module directly to the Nucleo board.
+  * Connect the X-NUCLEO-IKS01A1 module on top of the ACKme WiFi module.
+  */
+
+/**
+  * Hyperterminal configuration
+  * 115200 bauds, 8-bit data, no parity
+  */
+
+/**
+  * This is the name of your WiFi network.
+  * Look for this name in your WiFi settings.
+  * (e.g. your phone's list of WiFi networks in the WiFi settings menu.)
+  * tip: add double-quotes around SSID to add spaces to name.
+  */
+#define NETWORK_SSID "\"<YOUR NETWORK NAME HERE>\""
+
+/**
+  * This is the password of your WiFi network.
+  * Leave as empty string (e.g "") to connect to OPEN network.
+  */
+#define NETWORK_PASSWORD "\"<YOUR NETWORK PASSWORD HERE>\""
+
+const char key[] = "0a49487bc297bc061ca49ac01eb3755f";      // Replace with your M2X API key
+const char feed[] = "db817fd389c05eca79c331b4bb6daf8d";     // Replace with your blueprint Feed ID
+const char tempStream[] = "temperature";                    // Replace with your stream name  
+const char humStream[] = "humidity";                        // Replace with your stream name  
+const char accStream[] = "acceleration";                    // Replace with your stream name  
+
+char name[] = "redmond_st_office";  // Name of current location of datasource
+double latitude = 47.633889;        // You can also read those values from a GPS
+double longitude = -122.138611;
+double elevation = 97.46;
+
+/* Instantiate the serial console. */
+Serial pc(SERIAL_TX, SERIAL_RX);
+ 
+int main()
+{
+    /* Set the console terminal to 115200 bps. */
+    pc.baud(CONSOLE_BAUD);
+    
+    /* Instantiate the X-CUBE-MEMS Library. */
+    static X_CUBE_MEMS *mems_expansion_board = X_CUBE_MEMS::Instance();
+    
+    /* Read and output the humidity sensor id to confirm communication. */
+    uint8_t hts221_id = mems_expansion_board->hts221.ReadID();
+    
+    pc.printf("HTS221_ID = 0x%x\n\t\r", hts221_id);
+    
+    /**
+      * WIFI Setup
+      */
+    
+    /* Setup wiconnect serial interface configuration. */
+    
+    /**
+      * Here we only specify the rx buffer size and not rx buffer pointer, this means
+      * the serial RX buffer will be dynamically allocated.
+      */
+    SerialConfig serialConfig(WICONNECT_RX_PIN, WICONNECT_TX_PIN, 256, NULL);
+    
+    /* Instantiate WiConnect Library. */
+    
+    /**
+      * Here we only specify the buffer size and not buffer pointer, this means
+      * the internal buffer will be dynamically allocated.
+      */
+    Wiconnect wiconnect(serialConfig, 256, NULL, WICONNECT_RESET_PIN);
+    
+    /* Initiate Communication with WiFi Module. */
+    pc.printf("Initializing WiConnect Library...\r\n");
+    
+    WiconnectResult result;
+    
+    if(WICONNECT_FAILED(result, wiconnect.init(true)))
+    {
+        if(result == WICONNECT_FIRMWARE_OUTDATED)
+        {
+            pc.printf("** The WiFi firmware is not supported. Run the ota example to update the firmware:\r\n");
+            pc.printf("https://developer.mbed.org/teams/ACKme/code/wiconnect-ota_example\r\n\r\n");
+        }
+        else
+        {
+            pc.printf("Failed to initialize communication with WiFi module!\r\n"
+                      "Make sure the wires are connected correctly\r\n");
+        }
+        
+        return -1;
+    }
+    
+    /* Manually connected to the specified network (to ensure SDK backward compatibility. */
+    pc.printf("Setting network SSID: %s\r\n", NETWORK_SSID);
+    
+    if(WICONNECT_FAILED(result, wiconnect.setSetting("wlan.ssid", NETWORK_SSID)))
+    {
+        pc.printf("Failed to set wlan.ssid setting\r\n");
+        return -1;
+    }
+    
+    pc.printf("Setting network password\r\n");
+    
+    if(WICONNECT_FAILED(result, wiconnect.setSetting("wlan.passkey", NETWORK_PASSWORD)))
+    {
+        pc.printf("Failed to set wlan.passkey setting\r\n");
+        return -1;
+    }
+
+    pc.printf("Saving settings to Non-volatile Memory\r\n");
+    
+    if(WICONNECT_FAILED(result, wiconnect.saveSettings()))
+    {
+        pc.printf("Failed save settings\r\n");
+        return -1;
+    }
+    
+    pc.printf("IP Address: %s\r\n", wiconnect.getIpAddress());
+    pc.printf("Network joined!\r\n");
+    
+    /**
+      * M2X Setup
+      */
+    
+    /* Instantiate the M2X Stream Client. */
+    Client client;    
+    M2XStreamClient m2xClient(&client, key);
+    
+    /* Update device location. */
+    int m2x_response = m2xClient.updateLocation(feed, name, latitude, longitude, elevation);
+    
+    pc.printf("updateLocation response code: %d\r\n", m2x_response);
+    
+    /* Main loop */
+    while(1)
+    {
+        volatile float TEMPERATURE_Value;
+        volatile float HUMIDITY_Value;
+        volatile float PRESSURE_Value;
+        volatile AxesRaw_TypeDef MAG_Value;
+        volatile AxesRaw_TypeDef ACC_Value;
+        volatile AxesRaw_TypeDef GYR_Value;
+        
+        /* Update sensors.  */
+        mems_expansion_board->hts221.GetTemperature((float *)&TEMPERATURE_Value);
+        mems_expansion_board->hts221.GetHumidity((float *)&HUMIDITY_Value);
+        mems_expansion_board->lps25h.GetPressure((float *)&PRESSURE_Value);
+        mems_expansion_board->lis3mdl.GetAxes((AxesRaw_TypeDef *)&MAG_Value);
+        mems_expansion_board->lsm6ds0.Acc_GetAxes((AxesRaw_TypeDef *)&ACC_Value);
+        mems_expansion_board->lsm6ds0.Gyro_GetAxes((AxesRaw_TypeDef *)&GYR_Value);     
+        
+        /* Output sensor data. */
+        pc.printf("TEMP: %f HUMIDITY: %f PRESSURE: %f\t\r\n", TEMPERATURE_Value, HUMIDITY_Value, PRESSURE_Value);
+        pc.printf("X_MAG: %d, Y_MAG: %d, Z_MAG: %d\t\r\n", MAG_Value.AXIS_X, MAG_Value.AXIS_Y, MAG_Value.AXIS_Z);
+        pc.printf("X_ACC: %d, Y_ACC: %d, Z_ACC: %d\t\r\n", ACC_Value.AXIS_X, ACC_Value.AXIS_Y, ACC_Value.AXIS_Z);
+        pc.printf("X_GYR: %d, Y_GYR: %d, Z_GYR: %d\t\r\n\n", GYR_Value.AXIS_X, GYR_Value.AXIS_Y, GYR_Value.AXIS_Z);
+        
+        /* Convert temperature to degrees Farhenheit. */
+        float temperature_f = (1.8f * TEMPERATURE_Value) + 32.0f;
+        
+        /* Post temperature to the m2x stream. */
+        m2x_response = m2xClient.updateStreamValue(feed, tempStream, temperature_f);
+        
+        pc.printf("Temperature updateStreamValue response code: %d\r\n", m2x_response);
+        
+        if (m2x_response == -1) 
+        {
+            pc.printf("Temperature data transmit post error\n");
+        }
+        
+        /* Post humidity to the m2x stream. */
+        m2x_response = m2xClient.updateStreamValue(feed, humStream, HUMIDITY_Value);
+        
+        pc.printf("Humidity updateStreamValue response code: %d\r\n", m2x_response);
+        
+        if (m2x_response == -1) 
+        {
+            pc.printf("Humidity data transmit post error\n");
+        }
+        
+        /* Post acceleration (x-axis) to the m2x stream. */
+        m2x_response = m2xClient.updateStreamValue(feed, accStream, ACC_Value.AXIS_X);
+        
+        pc.printf("Acceleration updateStreamValue response code: %d\r\n", m2x_response);
+        
+        if (m2x_response == -1) 
+        {
+            pc.printf("Acceleration data transmit post error\n");
+        }
+        
+        pc.printf("\n");
+        
+        wait(30); // 30 s
+    }
+}
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 11 20:56:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target_config.h	Thu Dec 11 20:56:33 2014 +0000
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2014, ACKme Networks
+ * All Rights Reserved.
+ *
+ * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
+ * the contents of this file may not be disclosed to third parties, copied
+ * or duplicated in any form, in whole or in part, without the prior
+ * written permission of ACKme Networks.
+ */
+
+#pragma once
+
+
+// The BAUD rate your PC/MAC/Linux terminal uses with the eval board
+#define CONSOLE_BAUD 115200
+
+
+// Uncomment this to enable WiConnect serial interface hardware flow control
+// NOTE: your platform must support the serial flow control api functions
+//#define ENABLE_FLOW_CONTROL
+
+
+#define WICONNECT_INTERNAL_BUFFER_SIZE (4*1024)
+#define WICONNECT_SERIAL_RX_BUFFER_SIZE (4*1024)
+
+#define DEFAULT_CMD_GETCHAR_TIMEOUT 250
+#define DEFAULT_COMMAND_LINE_LENGTH_MAX 128
+#define DEFAULT_COMMAND_MAX_HISTORY 16
+#define DEFAULT_CMD_PROMPT_STR "> "
+#define DEFAULT_COMMAND_MAX_ARGV 16
+
+#define TEST_NONBLOCKING_API false
+#define TEST_BUFFER_LENGTH 4*1024
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Seabass Target Configuration
+#ifdef TARGET_SEABASS
+
+#define WICONNECT_TX_PIN PA_9
+#define WICONNECT_RX_PIN PA_10
+#define WICONNECT_RESET_PIN PB_0
+#define WICONNECT_WAKE_PIN NC
+
+#ifdef ENABLE_FLOW_CONTROL
+#define WICONNECT_CTS_PIN PA_11
+#define WICONNECT_RTS_PIN PA_12
+#else
+#define WICONNECT_CTS_PIN NC
+#define WICONNECT_RTS_PIN NC
+#endif
+
+#endif
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Nucleo F401RE Target Configuration
+//#ifdef TARGET_NUCLEO_F401RE
+#ifdef TARGET_NUCLEO_F411RE
+
+#define WICONNECT_TX_PIN PA_9
+#define WICONNECT_RX_PIN PA_10
+#define WICONNECT_RESET_PIN PC_7
+#define WICONNECT_WAKE_PIN NC
+
+#ifdef ENABLE_FLOW_CONTROL
+#define WICONNECT_CTS_PIN PA_11
+#define WICONNECT_RTS_PIN PA_12
+#else
+#define WICONNECT_CTS_PIN NC
+#define WICONNECT_RTS_PIN NC
+#endif
+
+#endif