adding resources firmware and 1/0/8

Dependencies:   Beep C12832_lcd EthernetInterface EthernetNetIf HTTPClient LM75B MMA7660 mbed-rtos mbed nsdl_lib

Fork of LWM2M_NanoService_Ethernet by MBED_DEMOS

Committer:
pnysten
Date:
Tue Oct 27 07:18:16 2015 +0000
Revision:
22:2fab757f9c2a
Parent:
21:978281bfb26e
Firmware and 1/0/8 resource

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pnysten 21:978281bfb26e 1 //Hello Pascal,
pnysten 21:978281bfb26e 2
pnysten 21:978281bfb26e 3 //to be able to support MDM in a clustered environment and permanent tcp connection with devices, we had to restrict the supported lwm2m scenario’s to the queued mode only.
pnysten 21:978281bfb26e 4 //This because jobs launched via the MDM console could be executed by a MDM node of the cluster that doesn’t have a tcp connection with the device.
pnysten 21:978281bfb26e 5 //With the latest lwm2m plugin, it is up to the device to come to the plugin with a lwm2m Register Update on one of the node and the Job waiting in shared MDM queue will execute.
pnysten 21:978281bfb26e 6
pnysten 21:978281bfb26e 7 //To show demo’s this is a bit embarrassing since updates are sent every time device lifetime expires and this could be long.
pnysten 21:978281bfb26e 8
pnysten 21:978281bfb26e 9 //So what we have introduced is the ability for the lwm2m plugin to send a Registration Update Trigger to the device if it has an available connection to it.
pnysten 21:978281bfb26e 10 //In a single node environment this is working fine.
pnysten 21:978281bfb26e 11
pnysten 21:978281bfb26e 12 //Can you please check if this registration update trigger can be implemented in the NXP and the freescale so we could upgrade our plugin when required.
pnysten 21:978281bfb26e 13 //All what is needed is to send a registration update message when then device receive an execute on resource 1/0/8.
pnysten 21:978281bfb26e 14
pnysten 21:978281bfb26e 15
pnysten 21:978281bfb26e 16
pnysten 21:978281bfb26e 17
terohoo 0:2edbfea18d23 18 #include "mbed.h"
terohoo 0:2edbfea18d23 19 #include "EthernetInterface.h"
terohoo 0:2edbfea18d23 20 #include "C12832_lcd.h"
bogdanm 2:7e489126fe7a 21 #include "nsdl_support.h"
bogdanm 2:7e489126fe7a 22 #include "dbg.h"
bogdanm 2:7e489126fe7a 23 // Include various resources
bogdanm 2:7e489126fe7a 24 #include "temperature.h"
bogdanm 2:7e489126fe7a 25 #include "light.h"
bogdanm 2:7e489126fe7a 26 #include "gps.h"
bogdanm 2:7e489126fe7a 27 #include "relay.h"
sstark 17:40ce3d963495 28 #include "rgb.h"
terohoo 0:2edbfea18d23 29
pnysten 21:978281bfb26e 30 #include "firmware.h"
pnysten 21:978281bfb26e 31 #include "firmware_result.h"
pnysten 21:978281bfb26e 32 #include "firmware_status.h"
pnysten 21:978281bfb26e 33
pnysten 21:978281bfb26e 34 #include "register_upd_trigger.h"
pnysten 21:978281bfb26e 35
bogdanm 2:7e489126fe7a 36 static C12832_LCD lcd;
pnysten 21:978281bfb26e 37 static PwmOut led1(LED1);
pnysten 21:978281bfb26e 38 static PwmOut led2(LED2);
pnysten 21:978281bfb26e 39 static PwmOut led3(LED3);
pnysten 21:978281bfb26e 40 static PwmOut led4(LED4);
pnysten 21:978281bfb26e 41
bogdanm 2:7e489126fe7a 42 Serial pc(USBTX, USBRX); // tx, rx
terohoo 0:2edbfea18d23 43
bogdanm 2:7e489126fe7a 44 // ****************************************************************************
bogdanm 2:7e489126fe7a 45 // Configuration section
bogdanm 2:7e489126fe7a 46
bogdanm 2:7e489126fe7a 47 // Ethernet configuration
terohoo 0:2edbfea18d23 48 /* Define this to enable DHCP, otherwise manual address configuration is used */
sstark 12:b695198175ee 49 #define DHCP 1
terohoo 0:2edbfea18d23 50
sstark 20:84ee332ba360 51 // Define this to enable the RGB LED resource
sstark 20:84ee332ba360 52 //#define USE_RGBLED 1
sstark 19:e5c0b6553c11 53
terohoo 0:2edbfea18d23 54 /* Manual IP configurations, if DHCP not defined */
terohoo 0:2edbfea18d23 55 #define IP "10.45.0.206"
terohoo 0:2edbfea18d23 56 #define MASK "255.255.255.0"
terohoo 0:2edbfea18d23 57 #define GW "10.45.0.1"
terohoo 0:2edbfea18d23 58
pnysten 21:978281bfb26e 59 // UDM configuration
terohoo 0:2edbfea18d23 60 /* Change this IP address to that of your NanoService Platform installation */
pnysten 21:978281bfb26e 61 //static const char* UDM_ADDRESS = "137.135.13.28"; /* demo UDM, web interface at http://red-hat-summit.cloudapp.net*/
pnysten 21:978281bfb26e 62 //static const char* UDM_ADDRESS = "137.117.164.225"; /* m2mcc02 */
pnysten 21:978281bfb26e 63 static const char* UDM_ADDRESS = "68.235.31.32";
pnysten 21:978281bfb26e 64 static const int UDM_PORT = 5684;
pnysten 21:978281bfb26e 65 //char endpoint_name[20] = "ntcmbed-ethernet-";
pnysten 21:978281bfb26e 66 char endpoint_name[20] = "NXP1768-";
zdshelby 13:b52d83adc1ab 67 char mbed_uid[33]; // for creating unique name for the board
zdshelby 8:f0ecb62bda47 68 uint8_t ep_type[] = {"mbed_lpc1768_appboard"};
zdshelby 8:f0ecb62bda47 69 uint8_t lifetime_ptr[] = {"60"};
pnysten 21:978281bfb26e 70
sstark 18:0872a05cae95 71 static const char* FIRMWARE_VER = "18"; // Committed revision number
zdshelby 13:b52d83adc1ab 72 char* mac;
zdshelby 13:b52d83adc1ab 73 char* ipAddr;
zdshelby 13:b52d83adc1ab 74 char* gateway;
zdshelby 13:b52d83adc1ab 75 char* nmask;
terohoo 0:2edbfea18d23 76
bogdanm 2:7e489126fe7a 77 // ****************************************************************************
bogdanm 2:7e489126fe7a 78 // Ethernet initialization
terohoo 0:2edbfea18d23 79
terohoo 0:2edbfea18d23 80 EthernetInterface eth;
terohoo 0:2edbfea18d23 81
bogdanm 2:7e489126fe7a 82 static void ethernet_init()
terohoo 0:2edbfea18d23 83 {
terohoo 0:2edbfea18d23 84
terohoo 0:2edbfea18d23 85 /* Initialize network */
terohoo 0:2edbfea18d23 86 #ifdef DHCP
zdshelby 13:b52d83adc1ab 87 NSDL_DEBUG("DHCP in use");
terohoo 0:2edbfea18d23 88 eth.init();
terohoo 0:2edbfea18d23 89 #else
terohoo 0:2edbfea18d23 90 eth.init(IP, MASK, GW);
terohoo 0:2edbfea18d23 91 #endif
pnysten 21:978281bfb26e 92 if(eth.connect(60000) == 0)
zdshelby 13:b52d83adc1ab 93 NSDL_DEBUG("Ethernet up");
terohoo 0:2edbfea18d23 94
zdshelby 13:b52d83adc1ab 95 mac = eth.getMACAddress();
zdshelby 13:b52d83adc1ab 96 ipAddr = eth.getIPAddress();
zdshelby 13:b52d83adc1ab 97 gateway = eth.getGateway();
zdshelby 13:b52d83adc1ab 98 nmask = eth.getNetworkMask();
zdshelby 13:b52d83adc1ab 99 NSDL_DEBUG("Network: mac=%s, ip=%s, gateway=%s, mask=%s", mac, ipAddr, gateway, nmask);
sstark 12:b695198175ee 100
terohoo 0:2edbfea18d23 101 mbed_interface_uid(mbed_uid);
terohoo 0:2edbfea18d23 102 mbed_uid[32] = '\0';
pnysten 21:978281bfb26e 103
sstark 16:12fe2f09fab5 104 NSDL_DEBUG("Full interface uid=%s", mbed_uid);
zdshelby 8:f0ecb62bda47 105 strncat(endpoint_name, mbed_uid + 27, 20 - strlen(endpoint_name));
pnysten 21:978281bfb26e 106
pnysten 21:978281bfb26e 107 // EP_NAME = (char*) malloc(strlen(endpoint_name)+1);
pnysten 21:978281bfb26e 108 // strcpy(EP_NAME, endpoint_name);
terohoo 0:2edbfea18d23 109
terohoo 0:2edbfea18d23 110 lcd.locate(0,11);
terohoo 0:2edbfea18d23 111 lcd.printf("IP:%s", eth.getIPAddress());
terohoo 0:2edbfea18d23 112
pnysten 21:978281bfb26e 113 }
bogdanm 2:7e489126fe7a 114
bogdanm 2:7e489126fe7a 115 // ****************************************************************************
pnysten 21:978281bfb26e 116 // UDM initialization
bogdanm 2:7e489126fe7a 117
bogdanm 2:7e489126fe7a 118 UDPSocket server;
pnysten 21:978281bfb26e 119 Endpoint udm;
bogdanm 2:7e489126fe7a 120
pnysten 21:978281bfb26e 121 static void udm_init()
bogdanm 2:7e489126fe7a 122 {
terohoo 0:2edbfea18d23 123 server.init();
pnysten 21:978281bfb26e 124 server.bind(UDM_PORT);
terohoo 0:2edbfea18d23 125
pnysten 21:978281bfb26e 126 udm.set_address(UDM_ADDRESS, UDM_PORT);
bogdanm 2:7e489126fe7a 127
bogdanm 2:7e489126fe7a 128 NSDL_DEBUG("name: %s", endpoint_name);
pnysten 21:978281bfb26e 129 NSDL_DEBUG("UDM=%s - port %d\n", UDM_ADDRESS, UDM_PORT);
terohoo 0:2edbfea18d23 130
terohoo 0:2edbfea18d23 131 lcd.locate(0,22);
zdshelby 8:f0ecb62bda47 132 lcd.printf("EP:%s\n", endpoint_name);
bogdanm 2:7e489126fe7a 133 }
terohoo 0:2edbfea18d23 134
bogdanm 2:7e489126fe7a 135 // ****************************************************************************
bogdanm 2:7e489126fe7a 136 // Resource creation
terohoo 0:2edbfea18d23 137
bogdanm 2:7e489126fe7a 138 static int create_resources()
bogdanm 2:7e489126fe7a 139 {
bogdanm 2:7e489126fe7a 140 sn_nsdl_resource_info_s *resource_ptr = NULL;
bogdanm 2:7e489126fe7a 141 sn_nsdl_ep_parameters_s *endpoint_ptr = NULL;
bogdanm 2:7e489126fe7a 142
bogdanm 2:7e489126fe7a 143 NSDL_DEBUG("Creating resources");
terohoo 0:2edbfea18d23 144
terohoo 0:2edbfea18d23 145 /* Create resources */
bogdanm 2:7e489126fe7a 146 resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s));
terohoo 0:2edbfea18d23 147 if(!resource_ptr)
terohoo 0:2edbfea18d23 148 return 0;
terohoo 0:2edbfea18d23 149 memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s));
terohoo 0:2edbfea18d23 150
bogdanm 2:7e489126fe7a 151 resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s));
terohoo 0:2edbfea18d23 152 if(!resource_ptr->resource_parameters_ptr)
terohoo 0:2edbfea18d23 153 {
bogdanm 2:7e489126fe7a 154 nsdl_free(resource_ptr);
terohoo 0:2edbfea18d23 155 return 0;
terohoo 0:2edbfea18d23 156 }
terohoo 0:2edbfea18d23 157 memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
terohoo 0:2edbfea18d23 158
bogdanm 2:7e489126fe7a 159 // Static resources
zdshelby 8:f0ecb62bda47 160 nsdl_create_static_resource(resource_ptr, sizeof("3/0/0")-1, (uint8_t*) "3/0/0", 0, 0, (uint8_t*) "ARM", sizeof("ARM")-1);
zdshelby 8:f0ecb62bda47 161 nsdl_create_static_resource(resource_ptr, sizeof("3/0/1")-1, (uint8_t*) "3/0/1", 0, 0, (uint8_t*) "LPC1768 App Board", sizeof("LPC1768 App Board")-1);
zdshelby 13:b52d83adc1ab 162 nsdl_create_static_resource(resource_ptr, sizeof("3/0/2")-1, (uint8_t*) "3/0/2", 0, 0, (uint8_t*) mbed_uid, sizeof(mbed_uid)-1);
zdshelby 15:db022645bcc1 163 nsdl_create_static_resource(resource_ptr, sizeof("3/0/3")-1, (uint8_t*) "3/0/3", 0, 0, (uint8_t*) FIRMWARE_VER, strlen(FIRMWARE_VER));
zdshelby 14:5acd59fec679 164 #ifdef DHCP
zdshelby 14:5acd59fec679 165 nsdl_create_static_resource(resource_ptr, sizeof("4/0/0")-1, (uint8_t*) "4/0/0", 0, 0, (uint8_t*) "Ethernet DHCP", sizeof("Ethernet DHCP")-1);
zdshelby 14:5acd59fec679 166 #else
zdshelby 14:5acd59fec679 167 nsdl_create_static_resource(resource_ptr, sizeof("4/0/0")-1, (uint8_t*) "4/0/0", 0, 0, (uint8_t*) "Ethernet Static", sizeof("Ethernet Static")-1);
zdshelby 14:5acd59fec679 168 #endif
zdshelby 14:5acd59fec679 169 nsdl_create_static_resource(resource_ptr, sizeof("4/0/1")-1, (uint8_t*) "4/0/1", 0, 0, (uint8_t*) "Ethernet (Static, DHCP)", sizeof("Ethernet (Static, DHCP)")-1);
zdshelby 14:5acd59fec679 170 nsdl_create_static_resource(resource_ptr, sizeof("4/0/4")-1, (uint8_t*) "4/0/4", 0, 0, (uint8_t*) ipAddr, strlen(ipAddr));
zdshelby 14:5acd59fec679 171 nsdl_create_static_resource(resource_ptr, sizeof("4/0/5")-1, (uint8_t*) "4/0/5", 0, 0, (uint8_t*) gateway, strlen(gateway));
zdshelby 13:b52d83adc1ab 172 nsdl_create_static_resource(resource_ptr, sizeof("3/0/16")-1, (uint8_t*) "3/0/16", 0, 0, (uint8_t*) "UDP", sizeof("UDP")-1);
terohoo 0:2edbfea18d23 173
bogdanm 2:7e489126fe7a 174 // Dynamic resources
bogdanm 2:7e489126fe7a 175 create_temperature_resource(resource_ptr);
bogdanm 2:7e489126fe7a 176 create_light_resource(resource_ptr);
bogdanm 2:7e489126fe7a 177 create_gps_resource(resource_ptr);
bogdanm 2:7e489126fe7a 178 create_relay_resource(resource_ptr);
pnysten 21:978281bfb26e 179 create_register_upd_trigger_resource(resource_ptr);
pnysten 21:978281bfb26e 180
pnysten 21:978281bfb26e 181 // Dynamic Firmware resources
pnysten 21:978281bfb26e 182 create_firmware_resource(resource_ptr);
pnysten 21:978281bfb26e 183 create_firmware_result_resource(resource_ptr);
pnysten 21:978281bfb26e 184 create_firmware_status_resource(resource_ptr);
pnysten 21:978281bfb26e 185
sstark 19:e5c0b6553c11 186 #ifdef USE_RGBLED
sstark 20:84ee332ba360 187 NSDL_DEBUG("Enabling RGB LED due to USE_RGBLED=%d\n", USE_RGBLED);
sstark 17:40ce3d963495 188 create_rgb_resource(resource_ptr);
sstark 19:e5c0b6553c11 189 #else
sstark 19:e5c0b6553c11 190 NSDL_DEBUG("Skipped RGB LED resource, change USE_RGBLED to 1 in main.cpp to test");
sstark 19:e5c0b6553c11 191 #endif
terohoo 0:2edbfea18d23 192
pnysten 21:978281bfb26e 193 /* Register with UDM */
bogdanm 2:7e489126fe7a 194 endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
terohoo 0:2edbfea18d23 195 if(sn_nsdl_register_endpoint(endpoint_ptr) != 0)
pnysten 21:978281bfb26e 196 pc.printf("UDM registering failed\r\n");
terohoo 0:2edbfea18d23 197 else
pnysten 21:978281bfb26e 198 pc.printf("UDM registering OK\r\n");
bogdanm 2:7e489126fe7a 199 nsdl_clean_register_endpoint(&endpoint_ptr);
terohoo 0:2edbfea18d23 200
bogdanm 2:7e489126fe7a 201 nsdl_free(resource_ptr->resource_parameters_ptr);
bogdanm 2:7e489126fe7a 202 nsdl_free(resource_ptr);
terohoo 0:2edbfea18d23 203 return 1;
terohoo 0:2edbfea18d23 204 }
terohoo 0:2edbfea18d23 205
bogdanm 2:7e489126fe7a 206 // ****************************************************************************
bogdanm 2:7e489126fe7a 207 // Program entry point
terohoo 0:2edbfea18d23 208
bogdanm 2:7e489126fe7a 209 int main()
terohoo 0:2edbfea18d23 210 {
pnysten 21:978281bfb26e 211 // strcpy((char*) ep_type, "mbed_lpc1768_appboard");
pnysten 21:978281bfb26e 212 strcpy((char*) lifetime_ptr, "60");
pnysten 21:978281bfb26e 213
bogdanm 2:7e489126fe7a 214 lcd.cls();
bogdanm 2:7e489126fe7a 215 lcd.locate(0,0);
pnysten 21:978281bfb26e 216 lcd.printf("NanoService LWM2M v%s", FIRMWARE_VER);
zdshelby 11:3e9c8d80891e 217 NSDL_DEBUG("NanoService LWM2M Demo for LPC1768 App Board\n");
pnysten 21:978281bfb26e 218 NSDL_DEBUG("NanoService LWM2M version %s\n", FIRMWARE_VER);
bogdanm 2:7e489126fe7a 219
bogdanm 2:7e489126fe7a 220 // Initialize Ethernet interface first
bogdanm 2:7e489126fe7a 221 ethernet_init();
terohoo 1:e35d7f10999a 222
pnysten 21:978281bfb26e 223 // Initialize UDM node
pnysten 21:978281bfb26e 224 udm_init();
bogdanm 2:7e489126fe7a 225
bogdanm 2:7e489126fe7a 226 // Initialize NSDL stack
bogdanm 2:7e489126fe7a 227 nsdl_init();
bogdanm 2:7e489126fe7a 228
bogdanm 2:7e489126fe7a 229 // Create NSDL resources
bogdanm 2:7e489126fe7a 230 create_resources();
pnysten 21:978281bfb26e 231
pnysten 21:978281bfb26e 232 //Version 18
pnysten 21:978281bfb26e 233 led3.write(0.1);
pnysten 21:978281bfb26e 234
pnysten 21:978281bfb26e 235 //Version 19
pnysten 21:978281bfb26e 236 // led2.write(0.5);
pnysten 21:978281bfb26e 237 // led3.write(0.5);
bogdanm 2:7e489126fe7a 238
bogdanm 2:7e489126fe7a 239 // Run the NSDL event loop (never returns)
bogdanm 2:7e489126fe7a 240 nsdl_event_loop();
terohoo 0:2edbfea18d23 241 }