cellular port

Dependencies:   Beep C027_Support C12832 LM75B MMA7660 mbed-rtos mbed nsdl_lib

This is a port of the NSDL HelloWorld for cellular.

To run the example you need a C027 and the ARM mbed application shield. The example uses cellular instead of ethernet and takes the true position from the GPS instead of using a fixed position.

Committer:
mazgch
Date:
Tue May 20 15:24:18 2014 +0000
Revision:
8:bd9096c4784c
Parent:
7:6b068978be9a
Child:
9:e4c916c6cb02
use restructured lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
terohoo 0:2edbfea18d23 1 #include "mbed.h"
mazgch 8:bd9096c4784c 2 #include "C12832.h"
bogdanm 2:7e489126fe7a 3 #include "nsdl_support.h"
bogdanm 2:7e489126fe7a 4 #include "dbg.h"
bogdanm 2:7e489126fe7a 5 // Include various resources
bogdanm 2:7e489126fe7a 6 #include "temperature.h"
bogdanm 2:7e489126fe7a 7 #include "light.h"
bogdanm 2:7e489126fe7a 8 #include "gps.h"
bogdanm 2:7e489126fe7a 9 #include "relay.h"
terohoo 0:2edbfea18d23 10
mazgch 8:bd9096c4784c 11 #include "UDPSocket.h"
mazgch 8:bd9096c4784c 12 #include "Endpoint.h"
mazgch 8:bd9096c4784c 13
mazgch 8:bd9096c4784c 14 //------------------------------------------------------------------------------------
mazgch 8:bd9096c4784c 15 // You need to configure these cellular modem / SIM parameters.
mazgch 8:bd9096c4784c 16 // These parameters are ignored for LISA-C200 variants and can be left NULL.
mazgch 8:bd9096c4784c 17 //------------------------------------------------------------------------------------
mazgch 8:bd9096c4784c 18 #include "MDM.h"
mazgch 8:bd9096c4784c 19 //! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual.
mazgch 8:bd9096c4784c 20 #define SIMPIN NULL
mazgch 8:bd9096c4784c 21 /*! The APN of your network operator SIM, sometimes it is "internet" check your
mazgch 8:bd9096c4784c 22 contract with the network operator. You can also try to look-up your settings in
mazgch 8:bd9096c4784c 23 google: https://www.google.de/search?q=APN+list */
mazgch 8:bd9096c4784c 24 #define APN "gprs.swisscom.ch"
mazgch 8:bd9096c4784c 25 //! Set the user name for your APN, or NULL if not needed
mazgch 8:bd9096c4784c 26 #define USERNAME NULL
mazgch 8:bd9096c4784c 27 //! Set the password for your APN, or NULL if not needed
mazgch 8:bd9096c4784c 28 #define PASSWORD NULL
mazgch 8:bd9096c4784c 29 //------------------------------------------------------------------------------------
mazgch 8:bd9096c4784c 30
mazgch 8:bd9096c4784c 31 static C12832 lcd(D11, D13, D12, D7, D10);
terohoo 0:2edbfea18d23 32
bogdanm 2:7e489126fe7a 33 // ****************************************************************************
bogdanm 2:7e489126fe7a 34 // Configuration section
bogdanm 2:7e489126fe7a 35
bogdanm 2:7e489126fe7a 36 // NSP configuration
terohoo 0:2edbfea18d23 37 /* Change this IP address to that of your NanoService Platform installation */
mazgch 8:bd9096c4784c 38 static const char* NSP_ADDRESS = "nanoservice-demo.mbed.org"; /* demo NSP, web interface at http://nanoservice-demo.mbed.org*/
bogdanm 2:7e489126fe7a 39 static const int NSP_PORT = 5683;
bogdanm 7:6b068978be9a 40 char endpoint_name[16] = "mbed-";
bogdanm 2:7e489126fe7a 41 uint8_t ep_type[] = {"mbed_device"};
bogdanm 2:7e489126fe7a 42 uint8_t lifetime_ptr[] = {"1200"};
terohoo 0:2edbfea18d23 43
bogdanm 2:7e489126fe7a 44 // ****************************************************************************
bogdanm 2:7e489126fe7a 45 // NSP initialization
bogdanm 2:7e489126fe7a 46
bogdanm 2:7e489126fe7a 47 UDPSocket server;
bogdanm 2:7e489126fe7a 48 Endpoint nsp;
bogdanm 2:7e489126fe7a 49
bogdanm 2:7e489126fe7a 50 static void nsp_init()
bogdanm 2:7e489126fe7a 51 {
terohoo 0:2edbfea18d23 52 server.init();
terohoo 0:2edbfea18d23 53 server.bind(NSP_PORT);
terohoo 0:2edbfea18d23 54
bogdanm 2:7e489126fe7a 55 nsp.set_address(NSP_ADDRESS, NSP_PORT);
bogdanm 2:7e489126fe7a 56
bogdanm 2:7e489126fe7a 57 NSDL_DEBUG("name: %s", endpoint_name);
bogdanm 2:7e489126fe7a 58 NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
mazgch 8:bd9096c4784c 59 NSDL_DEBUG("NSDL Demo Portal\n Website: http://%s\n Username: demo\n Password: demo\n", NSP_ADDRESS);
mazgch 8:bd9096c4784c 60
terohoo 0:2edbfea18d23 61 lcd.locate(0,22);
bogdanm 3:52c1b649eb04 62 lcd.printf("EP name:%s\n", endpoint_name);
bogdanm 2:7e489126fe7a 63 }
terohoo 0:2edbfea18d23 64
bogdanm 2:7e489126fe7a 65 // ****************************************************************************
bogdanm 2:7e489126fe7a 66 // Resource creation
terohoo 0:2edbfea18d23 67
bogdanm 2:7e489126fe7a 68 static int create_resources()
bogdanm 2:7e489126fe7a 69 {
bogdanm 2:7e489126fe7a 70 sn_nsdl_resource_info_s *resource_ptr = NULL;
bogdanm 2:7e489126fe7a 71 sn_nsdl_ep_parameters_s *endpoint_ptr = NULL;
bogdanm 2:7e489126fe7a 72
bogdanm 2:7e489126fe7a 73 NSDL_DEBUG("Creating resources");
terohoo 0:2edbfea18d23 74
terohoo 0:2edbfea18d23 75 /* Create resources */
bogdanm 2:7e489126fe7a 76 resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s));
terohoo 0:2edbfea18d23 77 if(!resource_ptr)
terohoo 0:2edbfea18d23 78 return 0;
terohoo 0:2edbfea18d23 79 memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s));
terohoo 0:2edbfea18d23 80
bogdanm 2:7e489126fe7a 81 resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s));
terohoo 0:2edbfea18d23 82 if(!resource_ptr->resource_parameters_ptr)
terohoo 0:2edbfea18d23 83 {
bogdanm 2:7e489126fe7a 84 nsdl_free(resource_ptr);
terohoo 0:2edbfea18d23 85 return 0;
terohoo 0:2edbfea18d23 86 }
terohoo 0:2edbfea18d23 87 memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
terohoo 0:2edbfea18d23 88
bogdanm 2:7e489126fe7a 89 // Static resources
bogdanm 2:7e489126fe7a 90 nsdl_create_static_resource(resource_ptr, sizeof("dev/mfg")-1, (uint8_t*) "dev/mfg", 0, 0, (uint8_t*) "Sensinode", sizeof("Sensinode")-1);
bogdanm 2:7e489126fe7a 91 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);
terohoo 0:2edbfea18d23 92
bogdanm 2:7e489126fe7a 93 // Dynamic resources
bogdanm 2:7e489126fe7a 94 create_temperature_resource(resource_ptr);
bogdanm 2:7e489126fe7a 95 create_light_resource(resource_ptr);
bogdanm 2:7e489126fe7a 96 create_gps_resource(resource_ptr);
bogdanm 2:7e489126fe7a 97 create_relay_resource(resource_ptr);
terohoo 0:2edbfea18d23 98
terohoo 0:2edbfea18d23 99 /* Register with NSP */
bogdanm 2:7e489126fe7a 100 endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
terohoo 0:2edbfea18d23 101 if(sn_nsdl_register_endpoint(endpoint_ptr) != 0)
mazgch 8:bd9096c4784c 102 printf("NSP registering failed\r\n");
terohoo 0:2edbfea18d23 103 else
mazgch 8:bd9096c4784c 104 printf("NSP registering OK\r\n");
bogdanm 2:7e489126fe7a 105 nsdl_clean_register_endpoint(&endpoint_ptr);
terohoo 0:2edbfea18d23 106
bogdanm 2:7e489126fe7a 107 nsdl_free(resource_ptr->resource_parameters_ptr);
bogdanm 2:7e489126fe7a 108 nsdl_free(resource_ptr);
terohoo 0:2edbfea18d23 109 return 1;
terohoo 0:2edbfea18d23 110 }
terohoo 0:2edbfea18d23 111
bogdanm 2:7e489126fe7a 112 // ****************************************************************************
bogdanm 2:7e489126fe7a 113 // Program entry point
terohoo 0:2edbfea18d23 114
bogdanm 2:7e489126fe7a 115 int main()
terohoo 0:2edbfea18d23 116 {
bogdanm 2:7e489126fe7a 117 lcd.cls();
bogdanm 2:7e489126fe7a 118 lcd.locate(0,0);
bogdanm 2:7e489126fe7a 119 lcd.printf("mbed NanoService demo");
bogdanm 2:7e489126fe7a 120 NSDL_DEBUG("mbed NanoService Example App 0.1\n");
bogdanm 2:7e489126fe7a 121
mazgch 8:bd9096c4784c 122 MDMSerial mdm;
mazgch 8:bd9096c4784c 123 //mdm.setDebug(4); // enable this for debugging issues
mazgch 8:bd9096c4784c 124 if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD))
mazgch 8:bd9096c4784c 125 return -1;
mazgch 8:bd9096c4784c 126
mazgch 8:bd9096c4784c 127 lcd.locate(0,11);
mazgch 8:bd9096c4784c 128
bogdanm 2:7e489126fe7a 129 // Initialize NSP node
bogdanm 2:7e489126fe7a 130 nsp_init();
bogdanm 2:7e489126fe7a 131
bogdanm 2:7e489126fe7a 132 // Initialize NSDL stack
bogdanm 2:7e489126fe7a 133 nsdl_init();
bogdanm 2:7e489126fe7a 134
bogdanm 2:7e489126fe7a 135 // Create NSDL resources
bogdanm 2:7e489126fe7a 136 create_resources();
bogdanm 2:7e489126fe7a 137
bogdanm 2:7e489126fe7a 138 // Run the NSDL event loop (never returns)
bogdanm 2:7e489126fe7a 139 nsdl_event_loop();
mazgch 8:bd9096c4784c 140
mazgch 8:bd9096c4784c 141 mdm.disconnect();
mazgch 8:bd9096c4784c 142 mdm.powerOff();
mazgch 8:bd9096c4784c 143
mazgch 8:bd9096c4784c 144 while(true);
mazgch 8:bd9096c4784c 145
terohoo 0:2edbfea18d23 146 }