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