Nespresso RGB Sensor / Mbed 2 deprecated EnvoyNespressoEndpointColorDetectorV2

Dependencies:   ColorDetectorV2 ExternalFlashClient SNICInterface mbed-rtos mbed nsdl

Fork of EnvoyNespressoEndpoint by Nespresso RGB Sensor

Files at this revision

API Documentation at this revision

Comitter:
mbedAustin
Date:
Thu Jul 02 02:24:14 2015 +0000
Parent:
11:b68a79810fdb
Child:
13:0edc42397e44
Commit message:
moved from Ethernet -> Murata Wifi Module

Changed in this revision

EthernetInterface.lib Show diff for this revision Revisions of this file
SNICInterface.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-rtos.lib 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
nsdl_support.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.lib	Thu Jul 02 01:44:16 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SNICInterface.lib	Thu Jul 02 02:24:14 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/murata/code/SNICInterface/#b53ccb9989c4
--- a/main.cpp	Thu Jul 02 01:44:16 2015 +0000
+++ b/main.cpp	Thu Jul 02 02:24:14 2015 +0000
@@ -1,11 +1,14 @@
 #include "mbed.h"
-#include "EthernetInterface.h"
+//#include "EthernetInterface.h"
+#include "SNIC_WifiInterface.h"
 #include "nsdl_support.h"
 #include "dbg.h"
 #include "GroveColourSensor.h"
 #include "ColorDetector.h"
 #include "color_detector.h"
 #include <cmath>
+#include "Endpoint.h"
+#include "UDPSocket.h"
 
 Serial pc(USBTX, USBRX); // tx, rx
 
@@ -25,31 +28,56 @@
 #define MASK    "255.255.255.0"
 #define GW      "0.0.0.0"
 
+#define DEMO_AP_SSID                  "mbed"
+#define DEMO_AP_SECURITY_TYPE         e_SEC_WPA2_AES
+#define DEMO_AP_SECUTIRY_KEY          "mbed.org"
+#define DEMO_AP_SECUTIRY_KEY_LEN      8
+
 // NSP configuration
 /* Change this IP address to that of your mbed Device Server installation */
 static const char* NSP_ADDRESS = "23.99.11.204";
 static const int NSP_PORT = 5683;
-char endpoint_name[] = "nespresso-machine-1";
+char endpoint_name[] = "AustinRocksWifi";
 uint8_t ep_type[] = {"nespresso-endpoint"};
 char nsp_domain[] = "56645321f5e24c49908e42f4d71b9ccb";
 uint8_t lifetime_ptr[] = {"1200"};
 
 // ****************************************************************************
 // Ethernet initialization
-
-EthernetInterface eth;
+C_SNIC_WifiInterface  eth( D1, D0, NC, NC, D3 );
+//EthernetInterface eth;
 
 static void ethernet_init()
 {
-    // Initialize network
-#ifdef DHCP
-    NSDL_DEBUG("DHCP in use\r\n");
-    eth.init();
-#else
-    eth.init(IP, MASK, GW);
-#endif
-    if(eth.connect(30000) == 0)
-        pc.printf("Connect OK\n\r");
+// Initialize Wi-Fi interface
+    int s = eth.init();
+
+    NSDL_DEBUG("init();\r\n");
+
+    if( s != 0 ) {
+        NSDL_DEBUG( "Could not initialise wifi\n\r" );
+        //return -1;
+    }
+    wait(0.5);
+    s = eth.disconnect();
+    NSDL_DEBUG("disconnect();\r\n");
+    if( s != 0 ) {
+        NSDL_DEBUG( "disconnect failed\r\n" );
+        //return -1;
+    }
+
+    wait(0.3);
+    // Connect AP
+    eth.connect( DEMO_AP_SSID
+                 , strlen(DEMO_AP_SSID)
+                 , DEMO_AP_SECURITY_TYPE
+                 , DEMO_AP_SECUTIRY_KEY
+                 , DEMO_AP_SECUTIRY_KEY_LEN );
+    NSDL_DEBUG("connect();\r\n");
+    wait(0.5);
+
+    NSDL_DEBUG("IP Config();\r\n");
+    eth.setIPConfig( true );
 
     NSDL_DEBUG("IP Address:%s ", eth.getIPAddress());
 }
@@ -66,7 +94,7 @@
     server.bind(NSP_PORT);
 
     nsp.set_address(NSP_ADDRESS, NSP_PORT);
-    
+
     NSDL_DEBUG("name: %s", endpoint_name);
     NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
 }
@@ -77,7 +105,7 @@
 static int create_resources()
 {
     sn_nsdl_resource_info_s *resource_ptr = NULL;
-    
+
     NSDL_DEBUG("Creating resources");
 
     // Create resources
@@ -87,8 +115,7 @@
     memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s));
 
     resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s));
-    if(!resource_ptr->resource_parameters_ptr)
-    {
+    if(!resource_ptr->resource_parameters_ptr) {
         nsdl_free(resource_ptr);
         return 0;
     }
@@ -96,7 +123,7 @@
 
     // Dynamic resources
     create_color_detector_resource(resource_ptr);
-    
+
     // Register with NSP
     register_endpoint(true);
 
@@ -111,53 +138,53 @@
 int main()
 {
     NSDL_DEBUG("mbed Nespresso Demo\n");
-    
+
     // Begin Color Sensor init
-    
+
     // First, ensure I2C bus is released by toggling clock (fixes reset errors)
     DigitalOut scl_dummy(COLOR_SENSOR_SCL);
-    
+
     for (int i = 0; i < 100; i++) {
         scl_dummy = !scl_dummy;
         wait_us(2);
     }
-    
+
     // Next, initialize I2C
     I2C i2c(COLOR_SENSOR_SDA, COLOR_SENSOR_SCL);
-    
+
     // Create color sensor instance
     GroveColourSensor colorSensor(&i2c);
-    
+
     // Various config
     colorSensor.powerUp();
     colorSensor.setGain(1);
     colorSensor.setBlockRead();
-    
+
     // Create color detector
     ColorDetector detector(&colorSensor, 15, 3, 2, 256, 4);
     detector.setBaseline();
-    
+
     // Pass reference to color detector
     set_color_detector(&detector);
-    
+
     // Initialize Ethernet interface first
     ethernet_init();
-    
+
     // Initialize NSP node
     nsp_init();
-    
+
     // Initialize NSDL stack
     nsdl_init();
-    
+
     // Create NSDL resources
     create_resources();
-    
+
     nsdl_event_loop_init();
-    
+
     while(true) {
         // Check if any nsdl events need to be handled
         nsdl_event_loop_run_once();
-        
+
         // Sample the color detector and potentially send samples to mDS
         run_color_detector();
     }
--- a/mbed-rtos.lib	Thu Jul 02 01:44:16 2015 +0000
+++ b/mbed-rtos.lib	Thu Jul 02 02:24:14 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#2db19f47c2ba
+http://mbed.org/users/mbed_official/code/mbed-rtos/#58c3b7759abf
--- a/mbed.bld	Thu Jul 02 01:44:16 2015 +0000
+++ b/mbed.bld	Thu Jul 02 02:24:14 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/dbbf35b96557
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file
--- a/nsdl_support.cpp	Thu Jul 02 01:44:16 2015 +0000
+++ b/nsdl_support.cpp	Thu Jul 02 02:24:14 2015 +0000
@@ -4,10 +4,13 @@
 #include "nsdl_support.h"
 #include "mbed.h"
 #include "rtos.h"
-#include "EthernetInterface.h"
+//#include "EthernetInterface.h"
+#include "SNIC_WifiInterface.h"
+#include "Endpoint.h"
+#include "UDPSocket.h"
 
 extern Serial pc;
-extern EthernetInterface eth;
+extern C_SNIC_WifiInterface eth;
 extern Endpoint nsp;
 extern UDPSocket server;
 extern char endpoint_name[16];