Demo application of SNICInterface library for Murata TypeYD, which reports sensor data periodically to Xively cloud server . Hardware platform: mbed application board (https://mbed.org/cookbook/mbed-application-board), mbed LPC1768 (https://mbed.org/platforms/mbed-LPC1768/) and TypeYD.
Dependencies: C12832 LM75B MMA7660 SNICInterface libxively mbed-rtos mbed
main.cpp@25:39099b3b173f, 2014-09-19 (annotated)
- Committer:
- kishino
- Date:
- Fri Sep 19 01:46:21 2014 +0000
- Revision:
- 25:39099b3b173f
- Parent:
- 24:3d150ff59276
- Child:
- 27:6949291ca38d
It was supported to the FRDM-KL46Z platform.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kishino | 21:25b85cbbdd82 | 1 | /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License |
kishino | 23:39cf9f03b076 | 2 | * muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART. |
kishino | 21:25b85cbbdd82 | 3 | * |
kishino | 21:25b85cbbdd82 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kishino | 21:25b85cbbdd82 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
kishino | 21:25b85cbbdd82 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
kishino | 21:25b85cbbdd82 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
kishino | 21:25b85cbbdd82 | 8 | * furnished to do so, subject to the following conditions: |
kishino | 21:25b85cbbdd82 | 9 | * |
kishino | 21:25b85cbbdd82 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
kishino | 21:25b85cbbdd82 | 11 | * substantial portions of the Software. |
kishino | 21:25b85cbbdd82 | 12 | * |
kishino | 21:25b85cbbdd82 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kishino | 21:25b85cbbdd82 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kishino | 21:25b85cbbdd82 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kishino | 21:25b85cbbdd82 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kishino | 21:25b85cbbdd82 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kishino | 21:25b85cbbdd82 | 18 | */ |
xively | 0:efdea27c3b81 | 19 | #include "mbed.h" |
kishino | 14:6d58d3855feb | 20 | #include "SNIC_WifiInterface.h" |
xively | 7:0eff5db44b8b | 21 | |
kishino | 14:6d58d3855feb | 22 | #define XI_FEED_ID 1056160623 // set Xively Feed ID (numerical, no quoutes) |
kishino | 14:6d58d3855feb | 23 | #define XI_API_KEY "Wg7CfZDrj7VjIIpiYzdDrMow6wdENAOGjkIfQ0fUjJh6DAw2" // set Xively API key (double-quoted string) |
errordeveloper | 10:86ffba646df1 | 24 | |
errordeveloper | 10:86ffba646df1 | 25 | #include "app_board_io.h" |
xively | 7:0eff5db44b8b | 26 | |
xively | 0:efdea27c3b81 | 27 | #include "xively.h" |
xively | 0:efdea27c3b81 | 28 | #include "xi_err.h" |
xively | 0:efdea27c3b81 | 29 | |
errordeveloper | 10:86ffba646df1 | 30 | #include "MMA7660.h" |
errordeveloper | 10:86ffba646df1 | 31 | #include "LM75B.h" |
kishino | 22:e567f0d4b05d | 32 | #include "C12832.h" |
errordeveloper | 10:86ffba646df1 | 33 | |
kishino | 22:e567f0d4b05d | 34 | #if defined(TARGET_LPC1768) |
kishino | 16:ed9b9c28f860 | 35 | #include "PowerControl/EthernetPowerControl.h" |
kishino | 22:e567f0d4b05d | 36 | C12832 lcd(p5, p7, p6, p8, p11); |
xively | 0:efdea27c3b81 | 37 | MMA7660 axl(p28, p27); |
xively | 3:7ad3f6543b6e | 38 | LM75B tmp(p28, p27); |
kishino | 25:39099b3b173f | 39 | #elif defined(TARGET_KL46Z) |
kishino | 22:e567f0d4b05d | 40 | C12832 lcd(D11, D13, D12, D7, D10); |
kishino | 25:39099b3b173f | 41 | MMA7660 axl(I2C_SDA, I2C_SCL); |
kishino | 25:39099b3b173f | 42 | LM75B tmp(I2C_SDA, I2C_SCL); |
kishino | 22:e567f0d4b05d | 43 | #endif |
errordeveloper | 11:bdf601a405fc | 44 | |
errordeveloper | 11:bdf601a405fc | 45 | #include "logo.h" |
xively | 0:efdea27c3b81 | 46 | |
kishino | 24:3d150ff59276 | 47 | #define DEMO_AP_SSID "AP_SSID" |
kishino | 17:0bf3c49a83d5 | 48 | #define DEMO_AP_SECURITY_TYPE e_SEC_WPA2_AES |
kishino | 24:3d150ff59276 | 49 | #define DEMO_AP_SECUTIRY_KEY "WPA2_PASSPHRASE" |
kishino | 24:3d150ff59276 | 50 | #define DEMO_AP_SECUTIRY_KEY_LEN 15 |
kishino | 19:4e2900daad59 | 51 | |
kishino | 14:6d58d3855feb | 52 | /** Wi-Fi SNIC UART Interface*/ |
kishino | 22:e567f0d4b05d | 53 | #if defined(TARGET_LPC1768) |
kishino | 14:6d58d3855feb | 54 | C_SNIC_WifiInterface mSNICwifi( p9, p10, NC, NC, p30 ); |
kishino | 25:39099b3b173f | 55 | #elif defined(TARGET_KL46Z) |
kishino | 25:39099b3b173f | 56 | C_SNIC_WifiInterface mSNICwifi( D1, D0, NC, NC, D3 ); |
kishino | 22:e567f0d4b05d | 57 | #endif |
kishino | 17:0bf3c49a83d5 | 58 | |
xively | 0:efdea27c3b81 | 59 | int main() { |
kishino | 16:ed9b9c28f860 | 60 | |
kishino | 22:e567f0d4b05d | 61 | #if defined(TARGET_LPC1768) |
kishino | 16:ed9b9c28f860 | 62 | PHY_PowerDown(); |
kishino | 22:e567f0d4b05d | 63 | #endif |
kishino | 25:39099b3b173f | 64 | #ifdef _DEBUG |
kishino | 14:6d58d3855feb | 65 | pc.baud( 115200 ); |
kishino | 25:39099b3b173f | 66 | #endif |
kishino | 22:e567f0d4b05d | 67 | DEBUG_PRINT("main\r\n"); |
errordeveloper | 11:bdf601a405fc | 68 | lcd_print_xively_logo(); |
xively | 0:efdea27c3b81 | 69 | |
kishino | 14:6d58d3855feb | 70 | // Initialize Wi-Fi interface |
kishino | 14:6d58d3855feb | 71 | int s = mSNICwifi.init(); |
xively | 0:efdea27c3b81 | 72 | |
kishino | 14:6d58d3855feb | 73 | lcd_printf("init();\r\n"); |
kishino | 14:6d58d3855feb | 74 | |
kishino | 14:6d58d3855feb | 75 | if( s != 0 ) |
xively | 0:efdea27c3b81 | 76 | { |
xively | 7:0eff5db44b8b | 77 | lcd_printf( "Could not initialise. Will halt!\n" ); |
kishino | 14:6d58d3855feb | 78 | return -1; |
xively | 0:efdea27c3b81 | 79 | } |
kishino | 20:f0c7f5ca7e8a | 80 | wait(0.5); |
kishino | 20:f0c7f5ca7e8a | 81 | s = mSNICwifi.disconnect(); |
kishino | 14:6d58d3855feb | 82 | lcd_printf("disconnect();\r\n"); |
kishino | 20:f0c7f5ca7e8a | 83 | if( s != 0 ) |
kishino | 20:f0c7f5ca7e8a | 84 | { |
kishino | 20:f0c7f5ca7e8a | 85 | printf( "disconnect failed\r\n" ); |
kishino | 20:f0c7f5ca7e8a | 86 | return -1; |
kishino | 20:f0c7f5ca7e8a | 87 | } |
xively | 0:efdea27c3b81 | 88 | |
kishino | 19:4e2900daad59 | 89 | wait(0.3); |
kishino | 14:6d58d3855feb | 90 | // Connect AP |
kishino | 19:4e2900daad59 | 91 | mSNICwifi.connect( DEMO_AP_SSID |
kishino | 14:6d58d3855feb | 92 | , strlen(DEMO_AP_SSID) |
kishino | 14:6d58d3855feb | 93 | , DEMO_AP_SECURITY_TYPE |
kishino | 14:6d58d3855feb | 94 | , DEMO_AP_SECUTIRY_KEY |
kishino | 14:6d58d3855feb | 95 | , DEMO_AP_SECUTIRY_KEY_LEN ); |
kishino | 14:6d58d3855feb | 96 | lcd_printf("connect();\r\n"); |
kishino | 19:4e2900daad59 | 97 | wait(0.5); |
kishino | 19:4e2900daad59 | 98 | |
kishino | 19:4e2900daad59 | 99 | lcd_printf("IP Config();\r\n"); |
kishino | 19:4e2900daad59 | 100 | mSNICwifi.setIPConfig( true ); |
kishino | 19:4e2900daad59 | 101 | |
kishino | 14:6d58d3855feb | 102 | wait(0.5); |
kishino | 14:6d58d3855feb | 103 | |
xively | 0:efdea27c3b81 | 104 | xi_feed_t feed; |
xively | 0:efdea27c3b81 | 105 | memset( &feed, NULL, sizeof( xi_feed_t ) ); |
xively | 0:efdea27c3b81 | 106 | |
xively | 0:efdea27c3b81 | 107 | feed.feed_id = XI_FEED_ID; |
xively | 3:7ad3f6543b6e | 108 | feed.datastream_count = 3; |
xively | 0:efdea27c3b81 | 109 | |
xively | 0:efdea27c3b81 | 110 | feed.datastreams[0].datapoint_count = 1; |
xively | 0:efdea27c3b81 | 111 | xi_datastream_t* orientation_datastream = &feed.datastreams[0]; |
xively | 0:efdea27c3b81 | 112 | strcpy( orientation_datastream->datastream_id, "orientation" ); |
xively | 0:efdea27c3b81 | 113 | xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0]; |
xively | 0:efdea27c3b81 | 114 | |
xively | 0:efdea27c3b81 | 115 | feed.datastreams[1].datapoint_count = 1; |
xively | 0:efdea27c3b81 | 116 | xi_datastream_t* side_rotation_datastream = &feed.datastreams[1]; |
xively | 0:efdea27c3b81 | 117 | strcpy( side_rotation_datastream->datastream_id, "side_rotation" ); |
xively | 0:efdea27c3b81 | 118 | xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0]; |
xively | 0:efdea27c3b81 | 119 | |
xively | 3:7ad3f6543b6e | 120 | feed.datastreams[2].datapoint_count = 1; |
xively | 3:7ad3f6543b6e | 121 | xi_datastream_t* temperature_datastream = &feed.datastreams[2]; |
xively | 3:7ad3f6543b6e | 122 | strcpy( temperature_datastream->datastream_id, "temperature" ); |
xively | 3:7ad3f6543b6e | 123 | xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0]; |
xively | 3:7ad3f6543b6e | 124 | |
xively | 0:efdea27c3b81 | 125 | // create the cosm library context |
xively | 0:efdea27c3b81 | 126 | xi_context_t* xi_context |
xively | 0:efdea27c3b81 | 127 | = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id ); |
xively | 0:efdea27c3b81 | 128 | |
xively | 0:efdea27c3b81 | 129 | // check if everything works |
xively | 0:efdea27c3b81 | 130 | if( xi_context == NULL ) |
xively | 0:efdea27c3b81 | 131 | { |
xively | 0:efdea27c3b81 | 132 | return -1; |
xively | 0:efdea27c3b81 | 133 | } |
xively | 0:efdea27c3b81 | 134 | |
xively | 0:efdea27c3b81 | 135 | while(1) { |
xively | 0:efdea27c3b81 | 136 | switch( axl.getSide() ) { |
xively | 0:efdea27c3b81 | 137 | case MMA7660::Front: |
xively | 0:efdea27c3b81 | 138 | xi_set_value_str( current_side_rotation, "front" ); |
xively | 0:efdea27c3b81 | 139 | break; |
xively | 0:efdea27c3b81 | 140 | case MMA7660::Back: |
xively | 0:efdea27c3b81 | 141 | xi_set_value_str( current_side_rotation, "back" ); |
xively | 0:efdea27c3b81 | 142 | break; |
xively | 0:efdea27c3b81 | 143 | default: |
xively | 0:efdea27c3b81 | 144 | xi_set_value_str( current_side_rotation, "unknown" ); |
xively | 0:efdea27c3b81 | 145 | break; |
xively | 0:efdea27c3b81 | 146 | } |
xively | 0:efdea27c3b81 | 147 | |
xively | 0:efdea27c3b81 | 148 | switch( axl.getOrientation() ) { |
xively | 0:efdea27c3b81 | 149 | case MMA7660::Down: |
xively | 0:efdea27c3b81 | 150 | xi_set_value_str( current_orientation, "down" ); |
xively | 0:efdea27c3b81 | 151 | break; |
xively | 0:efdea27c3b81 | 152 | case MMA7660::Up: |
xively | 0:efdea27c3b81 | 153 | xi_set_value_str( current_orientation, "up" ); |
xively | 0:efdea27c3b81 | 154 | break; |
xively | 0:efdea27c3b81 | 155 | case MMA7660::Right: |
xively | 0:efdea27c3b81 | 156 | xi_set_value_str( current_orientation, "right" ); |
xively | 0:efdea27c3b81 | 157 | break; |
xively | 0:efdea27c3b81 | 158 | case MMA7660::Left: |
xively | 0:efdea27c3b81 | 159 | xi_set_value_str( current_orientation, "left" ); |
xively | 0:efdea27c3b81 | 160 | break; |
xively | 0:efdea27c3b81 | 161 | default: |
xively | 0:efdea27c3b81 | 162 | xi_set_value_str( current_orientation, "unknown" ); |
xively | 0:efdea27c3b81 | 163 | break; |
xively | 0:efdea27c3b81 | 164 | } |
xively | 3:7ad3f6543b6e | 165 | |
xively | 3:7ad3f6543b6e | 166 | xi_set_value_f32( current_temperature, tmp.read() ); |
xively | 4:e7ca62a11595 | 167 | |
xively | 7:0eff5db44b8b | 168 | lcd_printf( "update...\n" ); |
errordeveloper | 11:bdf601a405fc | 169 | xi_feed_update( xi_context, &feed ); |
xively | 7:0eff5db44b8b | 170 | lcd_printf( "done...\n" ); |
xively | 3:7ad3f6543b6e | 171 | |
kishino | 14:6d58d3855feb | 172 | wait( 1.0 ); |
xively | 0:efdea27c3b81 | 173 | } |
Ilya Dmitrichenko |
6:9e4f4a8c1829 | 174 | } |