ok connect ethernet http://nanoservice-demo.mbed.org/ logout login name/password: demo demo see unique id on LCD click on that on that SAME id on web page interact with it: led on/off temp buzzer etc.
Dependencies: Beep C12832_lcd EthernetInterface LM75B MMA7660 mbed-rtos mbed nsdl_lib
Fork of NSDL_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "C12832_lcd.h" 00004 #include "nsdl_support.h" 00005 #include "dbg.h" 00006 // Include various resources 00007 #include "temperature.h" 00008 #include "light.h" 00009 #include "gps.h" 00010 #include "relay.h" 00011 00012 static C12832_LCD lcd; 00013 Serial pc(USBTX, USBRX); // tx, rx 00014 00015 // **************************************************************************** 00016 // Configuration section 00017 00018 // Ethernet configuration 00019 /* Define this to enable DHCP, otherwise manual address configuration is used */ 00020 #define DHCP 00021 00022 /* Manual IP configurations, if DHCP not defined */ 00023 #define IP "10.45.0.206" 00024 #define MASK "255.255.255.0" 00025 #define GW "10.45.0.1" 00026 00027 // NSP configuration 00028 /* Change this IP address to that of your NanoService Platform installation */ 00029 //static const char* NSP_ADDRESS = "217.140.101.20"; /* demo NSP, web interface at http://nanoservice-demo.mbed.org*/ 00030 static const char* NSP_ADDRESS = "208.111.39.69"; /* avnish NSP - see IT folder */ 00031 static const int NSP_PORT = 5683; 00032 char endpoint_name[16] = "mbed-"; 00033 uint8_t ep_type[] = {"mbed_device"}; 00034 uint8_t lifetime_ptr[] = {"1200"}; 00035 00036 // **************************************************************************** 00037 // Ethernet initialization 00038 00039 EthernetInterface eth; 00040 00041 static void ethernet_init() 00042 { 00043 char mbed_uid[33]; // for creating unique name for the board 00044 00045 /* Initialize network */ 00046 #ifdef DHCP 00047 NSDL_DEBUG("DHCP in use\r\n"); 00048 eth.init(); 00049 #else 00050 eth.init(IP, MASK, GW); 00051 #endif 00052 if(eth.connect(30000) == 0) 00053 pc.printf("Connect OK\n\r"); 00054 00055 mbed_interface_uid(mbed_uid); 00056 mbed_uid[32] = '\0'; 00057 strncat(endpoint_name, mbed_uid + 27, 15 - strlen(endpoint_name)); 00058 00059 lcd.locate(0,11); 00060 lcd.printf("IP:%s", eth.getIPAddress()); 00061 00062 NSDL_DEBUG("IP Address:%s ", eth.getIPAddress()); 00063 } 00064 00065 // **************************************************************************** 00066 // NSP initialization 00067 00068 UDPSocket server; 00069 Endpoint nsp; 00070 00071 static void nsp_init() 00072 { 00073 server.init(); 00074 server.bind(NSP_PORT); 00075 00076 nsp.set_address(NSP_ADDRESS, NSP_PORT); 00077 00078 NSDL_DEBUG("name: %s", endpoint_name); 00079 NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT); 00080 00081 lcd.locate(0,22); 00082 lcd.printf("EP name:%s\n", endpoint_name); 00083 } 00084 00085 // **************************************************************************** 00086 // Resource creation 00087 00088 static int create_resources() 00089 { 00090 sn_nsdl_resource_info_s *resource_ptr = NULL; 00091 sn_nsdl_ep_parameters_s *endpoint_ptr = NULL; 00092 00093 NSDL_DEBUG("Creating resources"); 00094 00095 /* Create resources */ 00096 resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s)); 00097 if(!resource_ptr) 00098 return 0; 00099 memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s)); 00100 00101 resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s)); 00102 if(!resource_ptr->resource_parameters_ptr) 00103 { 00104 nsdl_free(resource_ptr); 00105 return 0; 00106 } 00107 memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00108 00109 // Static resources 00110 nsdl_create_static_resource(resource_ptr, sizeof("dev/mfg")-1, (uint8_t*) "dev/mfg", 0, 0, (uint8_t*) "Sensinode", sizeof("Sensinode")-1); 00111 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); 00112 00113 // Dynamic resources 00114 create_temperature_resource(resource_ptr); 00115 create_light_resource(resource_ptr); 00116 create_gps_resource(resource_ptr); 00117 create_relay_resource(resource_ptr); 00118 00119 /* Register with NSP */ 00120 endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr); 00121 if(sn_nsdl_register_endpoint(endpoint_ptr) != 0) 00122 pc.printf("NSP registering failed\r\n"); 00123 else 00124 pc.printf("NSP registering OK\r\n"); 00125 nsdl_clean_register_endpoint(&endpoint_ptr); 00126 00127 nsdl_free(resource_ptr->resource_parameters_ptr); 00128 nsdl_free(resource_ptr); 00129 return 1; 00130 } 00131 00132 // **************************************************************************** 00133 // Program entry point 00134 00135 int main() 00136 { 00137 lcd.cls(); 00138 lcd.locate(0,0); 00139 lcd.printf("mbed NanoService demo"); 00140 NSDL_DEBUG("mbed NanoService Example App 0.1\n"); 00141 00142 // Initialize Ethernet interface first 00143 ethernet_init(); 00144 00145 // Initialize NSP node 00146 nsp_init(); 00147 00148 // Initialize NSDL stack 00149 nsdl_init(); 00150 00151 // Create NSDL resources 00152 create_resources(); 00153 00154 // Run the NSDL event loop (never returns) 00155 nsdl_event_loop(); 00156 }
Generated on Thu Jul 14 2022 20:49:36 by 1.7.2