
a
Dependencies: stm32l475e_iot01_gps BSP_B-L475E-IOT01
main.cpp@101:8d2cd7e4f3c1, 2021-01-15 (annotated)
- Committer:
- ctlee
- Date:
- Fri Jan 15 13:24:34 2021 +0000
- Revision:
- 101:8d2cd7e4f3c1
- Parent:
- 100:84aa1516022b
esys final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ctlee | 101:8d2cd7e4f3c1 | 1 | /* WiFi Example |
ctlee | 101:8d2cd7e4f3c1 | 2 | * Copyright (c) 2018 ARM Limited |
ctlee | 101:8d2cd7e4f3c1 | 3 | * |
ctlee | 101:8d2cd7e4f3c1 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ctlee | 101:8d2cd7e4f3c1 | 5 | * you may not use this file except in compliance with the License. |
ctlee | 101:8d2cd7e4f3c1 | 6 | * You may obtain a copy of the License at |
ctlee | 101:8d2cd7e4f3c1 | 7 | * |
ctlee | 101:8d2cd7e4f3c1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ctlee | 101:8d2cd7e4f3c1 | 9 | * |
ctlee | 101:8d2cd7e4f3c1 | 10 | * Unless required by applicable law or agreed to in writing, software |
ctlee | 101:8d2cd7e4f3c1 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
ctlee | 101:8d2cd7e4f3c1 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ctlee | 101:8d2cd7e4f3c1 | 13 | * See the License for the specific language governing permissions and |
ctlee | 101:8d2cd7e4f3c1 | 14 | * limitations under the License. |
ctlee | 101:8d2cd7e4f3c1 | 15 | */ |
ctlee | 101:8d2cd7e4f3c1 | 16 | |
ctlee | 101:8d2cd7e4f3c1 | 17 | |
ctlee | 101:8d2cd7e4f3c1 | 18 | |
ctlee | 101:8d2cd7e4f3c1 | 19 | #include "ThisThread.h" |
ctlee | 101:8d2cd7e4f3c1 | 20 | #include "mbed.h" |
ctlee | 101:8d2cd7e4f3c1 | 21 | #include "TCPSocket.h" |
ctlee | 101:8d2cd7e4f3c1 | 22 | //#include "TCPServer.h" |
ctlee | 101:8d2cd7e4f3c1 | 23 | #include "stm32l475e_iot01_accelero.h" |
ctlee | 101:8d2cd7e4f3c1 | 24 | #include "stm32l475e_iot01_gps.h" |
ctlee | 101:8d2cd7e4f3c1 | 25 | |
ctlee | 101:8d2cd7e4f3c1 | 26 | |
ctlee | 101:8d2cd7e4f3c1 | 27 | #define WIFI_IDW0XX1 2 |
ctlee | 101:8d2cd7e4f3c1 | 28 | |
ctlee | 101:8d2cd7e4f3c1 | 29 | #if (defined(TARGET_DISCO_L475VG_IOT01A) || defined(TARGET_DISCO_F413ZH)) |
ctlee | 101:8d2cd7e4f3c1 | 30 | #include "ISM43362Interface.h" |
ctlee | 101:8d2cd7e4f3c1 | 31 | ISM43362Interface wifi( false); |
ctlee | 101:8d2cd7e4f3c1 | 32 | |
ctlee | 101:8d2cd7e4f3c1 | 33 | #else // External WiFi modules |
ctlee | 101:8d2cd7e4f3c1 | 34 | |
ctlee | 101:8d2cd7e4f3c1 | 35 | #if MBED_CONF_APP_WIFI_SHIELD == WIFI_IDW0XX1 |
ctlee | 101:8d2cd7e4f3c1 | 36 | #include "SpwfSAInterface.h" |
ctlee | 101:8d2cd7e4f3c1 | 37 | SpwfSAInterface wifi(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX); |
ctlee | 101:8d2cd7e4f3c1 | 38 | #endif // MBED_CONF_APP_WIFI_SHIELD == WIFI_IDW0XX1 |
ctlee | 101:8d2cd7e4f3c1 | 39 | |
ctlee | 101:8d2cd7e4f3c1 | 40 | #endif |
ctlee | 101:8d2cd7e4f3c1 | 41 | |
ctlee | 101:8d2cd7e4f3c1 | 42 | #define SCALE_MULTIPLIER 0.004 |
ctlee | 101:8d2cd7e4f3c1 | 43 | |
ctlee | 101:8d2cd7e4f3c1 | 44 | |
ctlee | 101:8d2cd7e4f3c1 | 45 | GPS* gps=new GPS(D1,D0); |
ctlee | 101:8d2cd7e4f3c1 | 46 | |
ctlee | 101:8d2cd7e4f3c1 | 47 | const char *sec2str(nsapi_security_t sec) |
ctlee | 101:8d2cd7e4f3c1 | 48 | { |
ctlee | 101:8d2cd7e4f3c1 | 49 | switch (sec) { |
ctlee | 101:8d2cd7e4f3c1 | 50 | case NSAPI_SECURITY_NONE: |
ctlee | 101:8d2cd7e4f3c1 | 51 | return "None"; |
ctlee | 101:8d2cd7e4f3c1 | 52 | case NSAPI_SECURITY_WEP: |
ctlee | 101:8d2cd7e4f3c1 | 53 | return "WEP"; |
ctlee | 101:8d2cd7e4f3c1 | 54 | case NSAPI_SECURITY_WPA: |
ctlee | 101:8d2cd7e4f3c1 | 55 | return "WPA"; |
ctlee | 101:8d2cd7e4f3c1 | 56 | case NSAPI_SECURITY_WPA2: |
ctlee | 101:8d2cd7e4f3c1 | 57 | return "WPA2"; |
ctlee | 101:8d2cd7e4f3c1 | 58 | case NSAPI_SECURITY_WPA_WPA2: |
ctlee | 101:8d2cd7e4f3c1 | 59 | return "WPA/WPA2"; |
ctlee | 101:8d2cd7e4f3c1 | 60 | case NSAPI_SECURITY_UNKNOWN: |
ctlee | 101:8d2cd7e4f3c1 | 61 | default: |
ctlee | 101:8d2cd7e4f3c1 | 62 | return "Unknown"; |
ctlee | 101:8d2cd7e4f3c1 | 63 | } |
ctlee | 101:8d2cd7e4f3c1 | 64 | } |
ctlee | 101:8d2cd7e4f3c1 | 65 | |
ctlee | 101:8d2cd7e4f3c1 | 66 | int scan_demo(WiFiInterface *wifi) |
ctlee | 101:8d2cd7e4f3c1 | 67 | { |
ctlee | 101:8d2cd7e4f3c1 | 68 | WiFiAccessPoint *ap; |
ctlee | 101:8d2cd7e4f3c1 | 69 | |
ctlee | 101:8d2cd7e4f3c1 | 70 | printf("Scan:\n"); |
ctlee | 101:8d2cd7e4f3c1 | 71 | |
ctlee | 101:8d2cd7e4f3c1 | 72 | int count = wifi->scan(NULL,0); |
ctlee | 101:8d2cd7e4f3c1 | 73 | printf("%d networks available.\n", count); |
ctlee | 101:8d2cd7e4f3c1 | 74 | |
ctlee | 101:8d2cd7e4f3c1 | 75 | /* Limit number of network arbitrary to 15 */ |
ctlee | 101:8d2cd7e4f3c1 | 76 | count = count < 15 ? count : 15; |
ctlee | 101:8d2cd7e4f3c1 | 77 | |
ctlee | 101:8d2cd7e4f3c1 | 78 | ap = new WiFiAccessPoint[count]; |
ctlee | 101:8d2cd7e4f3c1 | 79 | count = wifi->scan(ap, count); |
ctlee | 101:8d2cd7e4f3c1 | 80 | for (int i = 0; i < count; i++) |
ctlee | 101:8d2cd7e4f3c1 | 81 | { |
ctlee | 101:8d2cd7e4f3c1 | 82 | printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(), |
ctlee | 101:8d2cd7e4f3c1 | 83 | sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2], |
ctlee | 101:8d2cd7e4f3c1 | 84 | ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel()); |
ctlee | 101:8d2cd7e4f3c1 | 85 | } |
ctlee | 101:8d2cd7e4f3c1 | 86 | |
ctlee | 101:8d2cd7e4f3c1 | 87 | delete[] ap; |
ctlee | 101:8d2cd7e4f3c1 | 88 | return count; |
ctlee | 101:8d2cd7e4f3c1 | 89 | } |
ctlee | 101:8d2cd7e4f3c1 | 90 | |
ctlee | 101:8d2cd7e4f3c1 | 91 | void acc_server(NetworkInterface *net) |
ctlee | 101:8d2cd7e4f3c1 | 92 | { |
ctlee | 101:8d2cd7e4f3c1 | 93 | /* |
ctlee | 101:8d2cd7e4f3c1 | 94 | TCPServer socket; |
ctlee | 101:8d2cd7e4f3c1 | 95 | TCPSocket* client;*/ |
ctlee | 101:8d2cd7e4f3c1 | 96 | TCPSocket socket; |
ctlee | 101:8d2cd7e4f3c1 | 97 | SocketAddress addr("192.168.43.163",65431); |
ctlee | 101:8d2cd7e4f3c1 | 98 | nsapi_error_t response; |
ctlee | 101:8d2cd7e4f3c1 | 99 | |
ctlee | 101:8d2cd7e4f3c1 | 100 | int16_t pDataXYZ[3] = {0}; |
ctlee | 101:8d2cd7e4f3c1 | 101 | char recv_buffer[9]; |
ctlee | 101:8d2cd7e4f3c1 | 102 | char acc_json[64]; |
ctlee | 101:8d2cd7e4f3c1 | 103 | int sample_num = 0; |
ctlee | 101:8d2cd7e4f3c1 | 104 | |
ctlee | 101:8d2cd7e4f3c1 | 105 | //analyze |
ctlee | 101:8d2cd7e4f3c1 | 106 | float bufX[80], bufY[80], bufZ[80]; |
ctlee | 101:8d2cd7e4f3c1 | 107 | int saX[80]={0}, saY[80]={0}, saZ[80]={0}; |
ctlee | 101:8d2cd7e4f3c1 | 108 | int fuzX[3]={80,0,0}, fuzY[3]={80,0,0}, fuzZ[3]={80,0,0}; |
ctlee | 101:8d2cd7e4f3c1 | 109 | int stX=0, stY=0, stZ=0; |
ctlee | 101:8d2cd7e4f3c1 | 110 | int ptr=0; |
ctlee | 101:8d2cd7e4f3c1 | 111 | int i=0; |
ctlee | 101:8d2cd7e4f3c1 | 112 | /* |
ctlee | 101:8d2cd7e4f3c1 | 113 | for(i=0;i<80;i++){ |
ctlee | 101:8d2cd7e4f3c1 | 114 | saX[i]=0; |
ctlee | 101:8d2cd7e4f3c1 | 115 | saY[i]=0; |
ctlee | 101:8d2cd7e4f3c1 | 116 | saZ[i]=0; |
ctlee | 101:8d2cd7e4f3c1 | 117 | } |
ctlee | 101:8d2cd7e4f3c1 | 118 | */ |
ctlee | 101:8d2cd7e4f3c1 | 119 | |
ctlee | 101:8d2cd7e4f3c1 | 120 | // Open a socket on the network interface, and create a TCP connection to addr |
ctlee | 101:8d2cd7e4f3c1 | 121 | response = socket.open(net); |
ctlee | 101:8d2cd7e4f3c1 | 122 | if (0 != response){ |
ctlee | 101:8d2cd7e4f3c1 | 123 | printf("Error opening: %d\n", response); |
ctlee | 101:8d2cd7e4f3c1 | 124 | } |
ctlee | 101:8d2cd7e4f3c1 | 125 | response = socket.connect(addr); |
ctlee | 101:8d2cd7e4f3c1 | 126 | |
ctlee | 101:8d2cd7e4f3c1 | 127 | if (0 != response){ |
ctlee | 101:8d2cd7e4f3c1 | 128 | printf("Error connecting: %d\n", response); |
ctlee | 101:8d2cd7e4f3c1 | 129 | } |
ctlee | 101:8d2cd7e4f3c1 | 130 | |
ctlee | 101:8d2cd7e4f3c1 | 131 | |
ctlee | 101:8d2cd7e4f3c1 | 132 | socket.set_blocking(1); |
ctlee | 101:8d2cd7e4f3c1 | 133 | while (1){ |
ctlee | 101:8d2cd7e4f3c1 | 134 | ptr=sample_num%80; |
ctlee | 101:8d2cd7e4f3c1 | 135 | ++sample_num; |
ctlee | 101:8d2cd7e4f3c1 | 136 | BSP_ACCELERO_AccGetXYZ(pDataXYZ); |
ctlee | 101:8d2cd7e4f3c1 | 137 | float x = pDataXYZ[0]*SCALE_MULTIPLIER, y = pDataXYZ[1]*SCALE_MULTIPLIER, z = pDataXYZ[2]*SCALE_MULTIPLIER; |
ctlee | 101:8d2cd7e4f3c1 | 138 | int len; |
ctlee | 101:8d2cd7e4f3c1 | 139 | |
ctlee | 101:8d2cd7e4f3c1 | 140 | bufX[ptr]=x; |
ctlee | 101:8d2cd7e4f3c1 | 141 | bufY[ptr]=y; |
ctlee | 101:8d2cd7e4f3c1 | 142 | bufZ[ptr]=z; |
ctlee | 101:8d2cd7e4f3c1 | 143 | |
ctlee | 101:8d2cd7e4f3c1 | 144 | fuzX[saX[ptr]]-=1; |
ctlee | 101:8d2cd7e4f3c1 | 145 | if(x>1){ |
ctlee | 101:8d2cd7e4f3c1 | 146 | saX[ptr]=2; |
ctlee | 101:8d2cd7e4f3c1 | 147 | fuzX[2]+=1; |
ctlee | 101:8d2cd7e4f3c1 | 148 | }else if(x>-1){ |
ctlee | 101:8d2cd7e4f3c1 | 149 | saX[ptr]=1; |
ctlee | 101:8d2cd7e4f3c1 | 150 | fuzX[1]+=1; |
ctlee | 101:8d2cd7e4f3c1 | 151 | }else{ |
ctlee | 101:8d2cd7e4f3c1 | 152 | saX[ptr]=0; |
ctlee | 101:8d2cd7e4f3c1 | 153 | fuzX[0]+=1; |
ctlee | 101:8d2cd7e4f3c1 | 154 | } |
ctlee | 101:8d2cd7e4f3c1 | 155 | fuzY[saX[ptr]]-=1; |
ctlee | 101:8d2cd7e4f3c1 | 156 | if(y>1){ |
ctlee | 101:8d2cd7e4f3c1 | 157 | saY[ptr]=2; |
ctlee | 101:8d2cd7e4f3c1 | 158 | fuzY[2]+=1; |
ctlee | 101:8d2cd7e4f3c1 | 159 | }else if(y>-1){ |
ctlee | 101:8d2cd7e4f3c1 | 160 | saY[ptr]=1; |
ctlee | 101:8d2cd7e4f3c1 | 161 | fuzY[1]+=1; |
ctlee | 101:8d2cd7e4f3c1 | 162 | }else{ |
ctlee | 101:8d2cd7e4f3c1 | 163 | saY[ptr]=0; |
ctlee | 101:8d2cd7e4f3c1 | 164 | fuzY[0]+=1; |
ctlee | 101:8d2cd7e4f3c1 | 165 | } |
ctlee | 101:8d2cd7e4f3c1 | 166 | fuzZ[saX[ptr]]-=1; |
ctlee | 101:8d2cd7e4f3c1 | 167 | if(z>5){ |
ctlee | 101:8d2cd7e4f3c1 | 168 | saZ[ptr]=2; |
ctlee | 101:8d2cd7e4f3c1 | 169 | fuzZ[2]+=1; |
ctlee | 101:8d2cd7e4f3c1 | 170 | }else if(z>3){ |
ctlee | 101:8d2cd7e4f3c1 | 171 | saZ[ptr]=1; |
ctlee | 101:8d2cd7e4f3c1 | 172 | fuzZ[1]+=1; |
ctlee | 101:8d2cd7e4f3c1 | 173 | }else{ |
ctlee | 101:8d2cd7e4f3c1 | 174 | saZ[ptr]=0; |
ctlee | 101:8d2cd7e4f3c1 | 175 | fuzZ[0]+=1; |
ctlee | 101:8d2cd7e4f3c1 | 176 | } |
ctlee | 101:8d2cd7e4f3c1 | 177 | |
ctlee | 101:8d2cd7e4f3c1 | 178 | //fuzzy |
ctlee | 101:8d2cd7e4f3c1 | 179 | //X |
ctlee | 101:8d2cd7e4f3c1 | 180 | if(fuzX[2]>64 || fuzX[0]>64){ |
ctlee | 101:8d2cd7e4f3c1 | 181 | if(stX!=3){ |
ctlee | 101:8d2cd7e4f3c1 | 182 | len = sprintf(acc_json,"x3\n"); |
ctlee | 101:8d2cd7e4f3c1 | 183 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 184 | int v=gps->sample(); |
ctlee | 101:8d2cd7e4f3c1 | 185 | if(v){len=sprintf(acc_json,"%f,%f",gps->longitude,gps->latitude);} |
ctlee | 101:8d2cd7e4f3c1 | 186 | else{len=sprintf(acc_json,"N");} |
ctlee | 101:8d2cd7e4f3c1 | 187 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 188 | stX=3; |
ctlee | 101:8d2cd7e4f3c1 | 189 | } |
ctlee | 101:8d2cd7e4f3c1 | 190 | }else if((fuzX[2]>32 || fuzX[0]>32) && fuzX[1]>32){ |
ctlee | 101:8d2cd7e4f3c1 | 191 | if(stX!=2){ |
ctlee | 101:8d2cd7e4f3c1 | 192 | len = sprintf(acc_json,"x2\n"); |
ctlee | 101:8d2cd7e4f3c1 | 193 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 194 | int v=gps->sample(); |
ctlee | 101:8d2cd7e4f3c1 | 195 | if(v){len=sprintf(acc_json,"%f,%f",gps->longitude,gps->latitude);} |
ctlee | 101:8d2cd7e4f3c1 | 196 | else{len=sprintf(acc_json,"N");} |
ctlee | 101:8d2cd7e4f3c1 | 197 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 198 | stX=2; |
ctlee | 101:8d2cd7e4f3c1 | 199 | } |
ctlee | 101:8d2cd7e4f3c1 | 200 | }else if(fuzX[2]>32 && fuzX[0]>32){ |
ctlee | 101:8d2cd7e4f3c1 | 201 | if(stX!=1){ |
ctlee | 101:8d2cd7e4f3c1 | 202 | len = sprintf(acc_json,"x1\n"); |
ctlee | 101:8d2cd7e4f3c1 | 203 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 204 | int v=gps->sample(); |
ctlee | 101:8d2cd7e4f3c1 | 205 | if(v){len=sprintf(acc_json,"%f,%f",gps->longitude,gps->latitude);} |
ctlee | 101:8d2cd7e4f3c1 | 206 | else{len=sprintf(acc_json,"N");} |
ctlee | 101:8d2cd7e4f3c1 | 207 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 208 | stX=1; |
ctlee | 101:8d2cd7e4f3c1 | 209 | } |
ctlee | 101:8d2cd7e4f3c1 | 210 | }else if(fuzX[1]>64){ |
ctlee | 101:8d2cd7e4f3c1 | 211 | stX=0; |
ctlee | 101:8d2cd7e4f3c1 | 212 | } |
ctlee | 101:8d2cd7e4f3c1 | 213 | //Y |
ctlee | 101:8d2cd7e4f3c1 | 214 | if(fuzY[2]>64 || fuzY[0]>64){ |
ctlee | 101:8d2cd7e4f3c1 | 215 | if(stY!=3){ |
ctlee | 101:8d2cd7e4f3c1 | 216 | len = sprintf(acc_json,"y3\n"); |
ctlee | 101:8d2cd7e4f3c1 | 217 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 218 | int v=gps->sample(); |
ctlee | 101:8d2cd7e4f3c1 | 219 | if(v){len=sprintf(acc_json,"%f,%f",gps->longitude,gps->latitude);} |
ctlee | 101:8d2cd7e4f3c1 | 220 | else{len=sprintf(acc_json,"N");} |
ctlee | 101:8d2cd7e4f3c1 | 221 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 222 | stY=3; |
ctlee | 101:8d2cd7e4f3c1 | 223 | } |
ctlee | 101:8d2cd7e4f3c1 | 224 | }else if((fuzY[2]>32 || fuzY[0]>32) && fuzY[1]>32){ |
ctlee | 101:8d2cd7e4f3c1 | 225 | if(stY!=2){ |
ctlee | 101:8d2cd7e4f3c1 | 226 | len = sprintf(acc_json,"y2\n"); |
ctlee | 101:8d2cd7e4f3c1 | 227 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 228 | int v=gps->sample(); |
ctlee | 101:8d2cd7e4f3c1 | 229 | if(v){len=sprintf(acc_json,"%f,%f",gps->longitude,gps->latitude);} |
ctlee | 101:8d2cd7e4f3c1 | 230 | else{len=sprintf(acc_json,"N");} |
ctlee | 101:8d2cd7e4f3c1 | 231 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 232 | stY=2; |
ctlee | 101:8d2cd7e4f3c1 | 233 | } |
ctlee | 101:8d2cd7e4f3c1 | 234 | }else if(fuzY[2]>32 && fuzY[0]>32){ |
ctlee | 101:8d2cd7e4f3c1 | 235 | if(stY!=1){ |
ctlee | 101:8d2cd7e4f3c1 | 236 | len = sprintf(acc_json,"y1\n"); |
ctlee | 101:8d2cd7e4f3c1 | 237 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 238 | int v=gps->sample(); |
ctlee | 101:8d2cd7e4f3c1 | 239 | if(v){len=sprintf(acc_json,"%f,%f",gps->longitude,gps->latitude);} |
ctlee | 101:8d2cd7e4f3c1 | 240 | else{len=sprintf(acc_json,"N");} |
ctlee | 101:8d2cd7e4f3c1 | 241 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 242 | stY=1; |
ctlee | 101:8d2cd7e4f3c1 | 243 | } |
ctlee | 101:8d2cd7e4f3c1 | 244 | }else if(fuzY[1]>64){ |
ctlee | 101:8d2cd7e4f3c1 | 245 | stY=0; |
ctlee | 101:8d2cd7e4f3c1 | 246 | } |
ctlee | 101:8d2cd7e4f3c1 | 247 | //Z |
ctlee | 101:8d2cd7e4f3c1 | 248 | if(fuzZ[2]>64 || fuzZ[0]>64){ |
ctlee | 101:8d2cd7e4f3c1 | 249 | if(stZ!=3){ |
ctlee | 101:8d2cd7e4f3c1 | 250 | len = sprintf(acc_json,"z3\n"); |
ctlee | 101:8d2cd7e4f3c1 | 251 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 252 | int v=gps->sample(); |
ctlee | 101:8d2cd7e4f3c1 | 253 | if(v){len=sprintf(acc_json,"%f,%f",gps->longitude,gps->latitude);} |
ctlee | 101:8d2cd7e4f3c1 | 254 | else{len=sprintf(acc_json,"N");} |
ctlee | 101:8d2cd7e4f3c1 | 255 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 256 | stZ=3; |
ctlee | 101:8d2cd7e4f3c1 | 257 | } |
ctlee | 101:8d2cd7e4f3c1 | 258 | }else if((fuzZ[2]>32 || fuzZ[0]>32) && fuzZ[1]>32){ |
ctlee | 101:8d2cd7e4f3c1 | 259 | if(stZ!=2){ |
ctlee | 101:8d2cd7e4f3c1 | 260 | len = sprintf(acc_json,"z2\n"); |
ctlee | 101:8d2cd7e4f3c1 | 261 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 262 | int v=gps->sample(); |
ctlee | 101:8d2cd7e4f3c1 | 263 | if(v){len=sprintf(acc_json,"%f,%f",gps->longitude,gps->latitude);} |
ctlee | 101:8d2cd7e4f3c1 | 264 | else{len=sprintf(acc_json,"N");} |
ctlee | 101:8d2cd7e4f3c1 | 265 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 266 | stZ=2; |
ctlee | 101:8d2cd7e4f3c1 | 267 | } |
ctlee | 101:8d2cd7e4f3c1 | 268 | }else if(fuzZ[2]>32 && fuzZ[0]>32){ |
ctlee | 101:8d2cd7e4f3c1 | 269 | if(stZ!=1){ |
ctlee | 101:8d2cd7e4f3c1 | 270 | len = sprintf(acc_json,"z1\n"); |
ctlee | 101:8d2cd7e4f3c1 | 271 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 272 | int v=gps->sample(); |
ctlee | 101:8d2cd7e4f3c1 | 273 | if(v){len=sprintf(acc_json,"%f,%f",gps->longitude,gps->latitude);} |
ctlee | 101:8d2cd7e4f3c1 | 274 | else{len=sprintf(acc_json,"N");} |
ctlee | 101:8d2cd7e4f3c1 | 275 | response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 276 | stZ=1; |
ctlee | 101:8d2cd7e4f3c1 | 277 | } |
ctlee | 101:8d2cd7e4f3c1 | 278 | }else if(fuzZ[1]>64){ |
ctlee | 101:8d2cd7e4f3c1 | 279 | stZ=0; |
ctlee | 101:8d2cd7e4f3c1 | 280 | } |
ctlee | 101:8d2cd7e4f3c1 | 281 | |
ctlee | 101:8d2cd7e4f3c1 | 282 | //int len = sprintf(acc_json,"%f,%f,%f,%d,%d\n",(float)((int)(x*10000))/10000, |
ctlee | 101:8d2cd7e4f3c1 | 283 | // (float)((int)(y*10000))/10000, (float)((int)(z*10000))/10000, sample_num, ptr); |
ctlee | 101:8d2cd7e4f3c1 | 284 | |
ctlee | 101:8d2cd7e4f3c1 | 285 | |
ctlee | 101:8d2cd7e4f3c1 | 286 | //response = socket.send(acc_json,len); |
ctlee | 101:8d2cd7e4f3c1 | 287 | if (0 >= response){ |
ctlee | 101:8d2cd7e4f3c1 | 288 | printf("Error seding: %d\n", response); |
ctlee | 101:8d2cd7e4f3c1 | 289 | } |
ctlee | 101:8d2cd7e4f3c1 | 290 | ThisThread::sleep_for(0.1); |
ctlee | 101:8d2cd7e4f3c1 | 291 | |
ctlee | 101:8d2cd7e4f3c1 | 292 | |
ctlee | 101:8d2cd7e4f3c1 | 293 | } |
ctlee | 101:8d2cd7e4f3c1 | 294 | |
ctlee | 101:8d2cd7e4f3c1 | 295 | |
ctlee | 101:8d2cd7e4f3c1 | 296 | socket.close(); |
ctlee | 101:8d2cd7e4f3c1 | 297 | } |
ctlee | 101:8d2cd7e4f3c1 | 298 | |
ctlee | 101:8d2cd7e4f3c1 | 299 | int main() |
ctlee | 101:8d2cd7e4f3c1 | 300 | { |
ctlee | 101:8d2cd7e4f3c1 | 301 | |
ctlee | 101:8d2cd7e4f3c1 | 302 | printf("\nConnecting to %s...\n", MBED_CONF_APP_WIFI_SSID); |
ctlee | 101:8d2cd7e4f3c1 | 303 | //wifi.set_network("192.168.130.105","255.255.255.0","192.168.130.254"); |
ctlee | 101:8d2cd7e4f3c1 | 304 | int ret = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2); |
ctlee | 101:8d2cd7e4f3c1 | 305 | if (ret != 0) { |
ctlee | 101:8d2cd7e4f3c1 | 306 | printf("\nConnection error\n"); |
ctlee | 101:8d2cd7e4f3c1 | 307 | return -1; |
ctlee | 101:8d2cd7e4f3c1 | 308 | } |
ctlee | 101:8d2cd7e4f3c1 | 309 | |
ctlee | 101:8d2cd7e4f3c1 | 310 | printf("Success\n\n"); |
ctlee | 101:8d2cd7e4f3c1 | 311 | printf("MAC: %s\n", wifi.get_mac_address()); |
ctlee | 101:8d2cd7e4f3c1 | 312 | printf("IP: %s\n", wifi.get_ip_address()); |
ctlee | 101:8d2cd7e4f3c1 | 313 | printf("Netmask: %s\n", wifi.get_netmask()); |
ctlee | 101:8d2cd7e4f3c1 | 314 | printf("Gateway: %s\n", wifi.get_gateway()); |
ctlee | 101:8d2cd7e4f3c1 | 315 | printf("RSSI: %d\n\n", wifi.get_rssi()); |
ctlee | 101:8d2cd7e4f3c1 | 316 | |
ctlee | 101:8d2cd7e4f3c1 | 317 | |
ctlee | 101:8d2cd7e4f3c1 | 318 | |
ctlee | 101:8d2cd7e4f3c1 | 319 | BSP_ACCELERO_Init(); |
ctlee | 101:8d2cd7e4f3c1 | 320 | |
ctlee | 101:8d2cd7e4f3c1 | 321 | |
ctlee | 101:8d2cd7e4f3c1 | 322 | acc_server(&wifi); |
ctlee | 101:8d2cd7e4f3c1 | 323 | |
ctlee | 101:8d2cd7e4f3c1 | 324 | |
ctlee | 101:8d2cd7e4f3c1 | 325 | |
ctlee | 101:8d2cd7e4f3c1 | 326 | } |