Nespresso coffee demo working on the Arch Pro

Dependencies:   EthernetInterface mbed-rtos mbed nsdl rgb_sensor_buffer

Fork of mbed_nsdl by Nespresso RGB Sensor

Committer:
bjblazkowicz
Date:
Mon Jun 30 09:44:00 2014 +0000
Revision:
3:8e1117ec91ba
Parent:
2:88a30cc88a86
Child:
4:ab3c8d25260e
Added dummy do_detection function.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GeofferyOmlette 0:345864e9ee85 1 #include "mbed.h"
GeofferyOmlette 0:345864e9ee85 2 #include "EthernetInterface.h"
GeofferyOmlette 0:345864e9ee85 3 #include "C12832_lcd.h"
GeofferyOmlette 0:345864e9ee85 4 #include "nsdl_support.h"
GeofferyOmlette 0:345864e9ee85 5 #include "dbg.h"
GeofferyOmlette 0:345864e9ee85 6 // Include various resources
GeofferyOmlette 0:345864e9ee85 7 #include "temperature.h"
GeofferyOmlette 0:345864e9ee85 8 #include "light.h"
GeofferyOmlette 0:345864e9ee85 9 #include "gps.h"
GeofferyOmlette 0:345864e9ee85 10 #include "relay.h"
GeofferyOmlette 2:88a30cc88a86 11 #include "nespresso.h"
GeofferyOmlette 0:345864e9ee85 12
GeofferyOmlette 0:345864e9ee85 13 static C12832_LCD lcd;
GeofferyOmlette 0:345864e9ee85 14 Serial pc(USBTX, USBRX); // tx, rx
GeofferyOmlette 0:345864e9ee85 15
GeofferyOmlette 0:345864e9ee85 16 // ****************************************************************************
GeofferyOmlette 0:345864e9ee85 17 // Configuration section
GeofferyOmlette 0:345864e9ee85 18
GeofferyOmlette 0:345864e9ee85 19 // Ethernet configuration
GeofferyOmlette 0:345864e9ee85 20 /* Define this to enable DHCP, otherwise manual address configuration is used */
GeofferyOmlette 0:345864e9ee85 21 #define DHCP
GeofferyOmlette 0:345864e9ee85 22
GeofferyOmlette 0:345864e9ee85 23 /* Manual IP configurations, if DHCP not defined */
GeofferyOmlette 0:345864e9ee85 24 #define IP "10.45.0.206"
GeofferyOmlette 0:345864e9ee85 25 #define MASK "255.255.255.0"
GeofferyOmlette 0:345864e9ee85 26 #define GW "10.45.0.1"
GeofferyOmlette 0:345864e9ee85 27
GeofferyOmlette 0:345864e9ee85 28 // NSP configuration
GeofferyOmlette 0:345864e9ee85 29 /* Change this IP address to that of your NanoService Platform installation */
bjblazkowicz 3:8e1117ec91ba 30 static const char* NSP_ADDRESS = "23.97.218.184"; /* demo NSP, web interface at http://nanoservice-demo.mbed.org*/
GeofferyOmlette 0:345864e9ee85 31 static const int NSP_PORT = 5683;
GeofferyOmlette 0:345864e9ee85 32 char endpoint_name[16] = "mbed-";
GeofferyOmlette 0:345864e9ee85 33 uint8_t ep_type[] = {"mbed_device"};
GeofferyOmlette 0:345864e9ee85 34 uint8_t lifetime_ptr[] = {"1200"};
GeofferyOmlette 0:345864e9ee85 35
GeofferyOmlette 0:345864e9ee85 36 // ****************************************************************************
GeofferyOmlette 0:345864e9ee85 37 // Ethernet initialization
GeofferyOmlette 0:345864e9ee85 38
GeofferyOmlette 0:345864e9ee85 39 EthernetInterface eth;
GeofferyOmlette 0:345864e9ee85 40
GeofferyOmlette 0:345864e9ee85 41 static void ethernet_init()
GeofferyOmlette 0:345864e9ee85 42 {
GeofferyOmlette 0:345864e9ee85 43 char mbed_uid[33]; // for creating unique name for the board
GeofferyOmlette 0:345864e9ee85 44
GeofferyOmlette 0:345864e9ee85 45 /* Initialize network */
GeofferyOmlette 0:345864e9ee85 46 #ifdef DHCP
GeofferyOmlette 0:345864e9ee85 47 NSDL_DEBUG("DHCP in use\r\n");
GeofferyOmlette 0:345864e9ee85 48 eth.init();
GeofferyOmlette 0:345864e9ee85 49 #else
GeofferyOmlette 0:345864e9ee85 50 eth.init(IP, MASK, GW);
GeofferyOmlette 0:345864e9ee85 51 #endif
GeofferyOmlette 0:345864e9ee85 52 if(eth.connect(30000) == 0)
GeofferyOmlette 0:345864e9ee85 53 pc.printf("Connect OK\n\r");
GeofferyOmlette 0:345864e9ee85 54
GeofferyOmlette 0:345864e9ee85 55 mbed_interface_uid(mbed_uid);
GeofferyOmlette 0:345864e9ee85 56 mbed_uid[32] = '\0';
GeofferyOmlette 0:345864e9ee85 57 strncat(endpoint_name, mbed_uid + 27, 15 - strlen(endpoint_name));
GeofferyOmlette 0:345864e9ee85 58
GeofferyOmlette 0:345864e9ee85 59 lcd.locate(0,11);
GeofferyOmlette 0:345864e9ee85 60 lcd.printf("IP:%s", eth.getIPAddress());
GeofferyOmlette 0:345864e9ee85 61
GeofferyOmlette 0:345864e9ee85 62 NSDL_DEBUG("IP Address:%s ", eth.getIPAddress());
GeofferyOmlette 0:345864e9ee85 63 }
GeofferyOmlette 0:345864e9ee85 64
GeofferyOmlette 0:345864e9ee85 65 // ****************************************************************************
GeofferyOmlette 0:345864e9ee85 66 // NSP initialization
GeofferyOmlette 0:345864e9ee85 67
GeofferyOmlette 0:345864e9ee85 68 UDPSocket server;
GeofferyOmlette 0:345864e9ee85 69 Endpoint nsp;
GeofferyOmlette 0:345864e9ee85 70
GeofferyOmlette 0:345864e9ee85 71 static void nsp_init()
GeofferyOmlette 0:345864e9ee85 72 {
GeofferyOmlette 0:345864e9ee85 73 server.init();
GeofferyOmlette 0:345864e9ee85 74 server.bind(NSP_PORT);
GeofferyOmlette 0:345864e9ee85 75
GeofferyOmlette 0:345864e9ee85 76 nsp.set_address(NSP_ADDRESS, NSP_PORT);
GeofferyOmlette 0:345864e9ee85 77
GeofferyOmlette 0:345864e9ee85 78 NSDL_DEBUG("name: %s", endpoint_name);
GeofferyOmlette 0:345864e9ee85 79 NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
GeofferyOmlette 0:345864e9ee85 80
GeofferyOmlette 0:345864e9ee85 81 lcd.locate(0,22);
GeofferyOmlette 0:345864e9ee85 82 lcd.printf("EP name:%s\n", endpoint_name);
GeofferyOmlette 0:345864e9ee85 83 }
GeofferyOmlette 0:345864e9ee85 84
GeofferyOmlette 0:345864e9ee85 85 // ****************************************************************************
GeofferyOmlette 0:345864e9ee85 86 // Resource creation
GeofferyOmlette 0:345864e9ee85 87
GeofferyOmlette 0:345864e9ee85 88 static int create_resources()
GeofferyOmlette 0:345864e9ee85 89 {
GeofferyOmlette 0:345864e9ee85 90 sn_nsdl_resource_info_s *resource_ptr = NULL;
GeofferyOmlette 0:345864e9ee85 91 sn_nsdl_ep_parameters_s *endpoint_ptr = NULL;
GeofferyOmlette 0:345864e9ee85 92
GeofferyOmlette 0:345864e9ee85 93 NSDL_DEBUG("Creating resources");
GeofferyOmlette 0:345864e9ee85 94
GeofferyOmlette 0:345864e9ee85 95 /* Create resources */
GeofferyOmlette 0:345864e9ee85 96 resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s));
GeofferyOmlette 0:345864e9ee85 97 if(!resource_ptr)
GeofferyOmlette 0:345864e9ee85 98 return 0;
GeofferyOmlette 0:345864e9ee85 99 memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s));
GeofferyOmlette 0:345864e9ee85 100
GeofferyOmlette 0:345864e9ee85 101 resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s));
GeofferyOmlette 0:345864e9ee85 102 if(!resource_ptr->resource_parameters_ptr)
GeofferyOmlette 0:345864e9ee85 103 {
GeofferyOmlette 0:345864e9ee85 104 nsdl_free(resource_ptr);
GeofferyOmlette 0:345864e9ee85 105 return 0;
GeofferyOmlette 0:345864e9ee85 106 }
GeofferyOmlette 0:345864e9ee85 107 memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
GeofferyOmlette 0:345864e9ee85 108
GeofferyOmlette 0:345864e9ee85 109 // Static resources
GeofferyOmlette 0:345864e9ee85 110 nsdl_create_static_resource(resource_ptr, sizeof("dev/mfg")-1, (uint8_t*) "dev/mfg", 0, 0, (uint8_t*) "Sensinode", sizeof("Sensinode")-1);
GeofferyOmlette 0:345864e9ee85 111 nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0, (uint8_t*) "NSDL-C mbed device", sizeof("NSDL-C mbed device")-1);
GeofferyOmlette 0:345864e9ee85 112
GeofferyOmlette 0:345864e9ee85 113 // Dynamic resources
GeofferyOmlette 0:345864e9ee85 114 create_temperature_resource(resource_ptr);
GeofferyOmlette 0:345864e9ee85 115 create_light_resource(resource_ptr);
GeofferyOmlette 0:345864e9ee85 116 create_gps_resource(resource_ptr);
GeofferyOmlette 0:345864e9ee85 117 create_relay_resource(resource_ptr);
bjblazkowicz 3:8e1117ec91ba 118 // create_nespresso_resource(resource_ptr);
GeofferyOmlette 0:345864e9ee85 119
GeofferyOmlette 2:88a30cc88a86 120 /* Register with NSP */
GeofferyOmlette 0:345864e9ee85 121 endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
GeofferyOmlette 0:345864e9ee85 122 if(sn_nsdl_register_endpoint(endpoint_ptr) != 0)
GeofferyOmlette 0:345864e9ee85 123 pc.printf("NSP registering failed\r\n");
GeofferyOmlette 0:345864e9ee85 124 else
GeofferyOmlette 0:345864e9ee85 125 pc.printf("NSP registering OK\r\n");
GeofferyOmlette 0:345864e9ee85 126 nsdl_clean_register_endpoint(&endpoint_ptr);
GeofferyOmlette 0:345864e9ee85 127
GeofferyOmlette 0:345864e9ee85 128 nsdl_free(resource_ptr->resource_parameters_ptr);
GeofferyOmlette 0:345864e9ee85 129 nsdl_free(resource_ptr);
GeofferyOmlette 0:345864e9ee85 130 return 1;
GeofferyOmlette 0:345864e9ee85 131 }
GeofferyOmlette 0:345864e9ee85 132
GeofferyOmlette 0:345864e9ee85 133 // ****************************************************************************
GeofferyOmlette 0:345864e9ee85 134 // Program entry point
GeofferyOmlette 0:345864e9ee85 135
GeofferyOmlette 0:345864e9ee85 136 int main()
GeofferyOmlette 0:345864e9ee85 137 {
GeofferyOmlette 0:345864e9ee85 138 lcd.cls();
GeofferyOmlette 0:345864e9ee85 139 lcd.locate(0,0);
GeofferyOmlette 0:345864e9ee85 140 lcd.printf("mbed NanoService demo");
GeofferyOmlette 0:345864e9ee85 141 NSDL_DEBUG("mbed NanoService Example App 0.1\n");
GeofferyOmlette 0:345864e9ee85 142
GeofferyOmlette 0:345864e9ee85 143 // Initialize Ethernet interface first
GeofferyOmlette 0:345864e9ee85 144 ethernet_init();
GeofferyOmlette 0:345864e9ee85 145
GeofferyOmlette 0:345864e9ee85 146 // Initialize NSP node
GeofferyOmlette 0:345864e9ee85 147 nsp_init();
GeofferyOmlette 0:345864e9ee85 148
GeofferyOmlette 0:345864e9ee85 149 // Initialize NSDL stack
GeofferyOmlette 0:345864e9ee85 150 nsdl_init();
GeofferyOmlette 0:345864e9ee85 151
GeofferyOmlette 0:345864e9ee85 152 // Create NSDL resources
GeofferyOmlette 0:345864e9ee85 153 create_resources();
GeofferyOmlette 0:345864e9ee85 154
GeofferyOmlette 0:345864e9ee85 155 // Run the NSDL event loop (never returns)
GeofferyOmlette 0:345864e9ee85 156 nsdl_event_loop();
GeofferyOmlette 0:345864e9ee85 157 }