This program simply connects to a HTS221 I2C device to read Temperature & Humidity, and a WNC Cellular Module both of which are on the Avnet WNC Shield.

Dependencies:   mbed FXOS8700CQ

/media/uploads/JMF/avnet_logo.gif

AT&T Shape Hackathon QuickStart Instructions

  • One area that has been problematic is setting the the MY_SERVER_URL. When you copy the URL from the flow, you must make sure that the MY_SERVER_URL is also set to the appropirate server. It can be either "run-east.att.io" or "run-west.att.io", so be sure to check this.

Useful Links

Adding Additional Sensors

The FLOW_DEVICE_NAME field must contain the name of the instance of the Virtual Starter kit in FLOW that you will be communicating with. Usually this will be "vstarterkit001", but if you have problems communicating you can verify that this is indeed correct. Note that this device will not be created until you click the “Initialize” input on the Virtual Device tab of the Starter Kit project in FLOW. At that point it becomes available in M2X and you can see it there, as the DEVICE SERIAL field under Devices as in the image below.

Sensors: When executing, the FRDM-K64F board will upload sensor measurements to AT&T’s Flow environment every 5 seconds, using the Cellular shield board. You can adjust how often you want to do this by editing the SENSOR_UPDATE_INTERVAL_MS value in the header file. Temperature and humidity: By default the board will report readings from the HTS221 temperature and humidity sensor. These two values are sent to the HTTP IN /climate port in FLOW with field names “temp” and “humidity”. Temperature is in degrees Fahrenheit and humidity is a %. This default assignment is: iSensorsToReport = TEMP_HUMIDITY_ONLY;

Accelerometer: If you want to expand and use the on-board motion sensor, you can also send 3-axis accelerometer information from the board as “accelX”, “accelY” and “accelZ”. This is useful if you want to know the stationary position of the board with regards to gravity, or whether it is in motion. These readings are in g’s. To send these values, change the assignment to: iSensorsToReport = TEMP_HUMIDITY_ACCELEROMETER;

PMOD Sensors: If you have a Silicon Labs sensor module that can plug into the PMOD connector on the Cellular shield, you will also be able to measure proximity, UV light, ambient visible and infrared light from the Si1145 sensor. This PMOD also has a temperature and humidity sensor, but in this case it is redundant. When enabled, the fields “proximity”, “light_uv”, “light_vis” and “light_ir” will also be sent. To enable all these sensors, change the assignment to: iSensorsToReport = TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS;

Connecting up the PMOD sensors: Because the pinouts do not align, the SiLabs PMOD sensor board cannot be plugged into the J10 PMOD receptacle on the shield directly. The following wiring instructions must be used:

Signal=J10=(Shield) PMOD=Color in the image below
VCCPin 6Pin 6Red
GNDPin 5Pin 5Black
SDAPin4Pin 3Green
SCLPin3Pin 2Yellow

Link to AT&T M2X

M2X

Link to AT&T Flow

FLOW

Avnet WNC-Shield Information

Getting Started with the Avnet WNC-Shield & Hackathon software

  • This project uses Revision 119 of the MBED library because of I2C implementation differences with the tip (Revision 121)
  • This project uses Revision 4 of the FXOS8700CQ library for sensors

Easily modifiable parameters in source code

Inside the mbed “AvnetATT_shape_hackathon” project, the parameters that are needed to customize your board are in the config_me.h file.

  • FLOW parameters: This project assumes that you are using a fork of the “Starter Kit Base” project, which is a reference design that was created using AT&T’s FLOW (https://flow.att.com) that allows the creation of on-line virtualization and other IoT functionality. The default parameters in the config_me.h file are done for a specific instance of this project. When you fork the original project, you get your own instance and it will have its own base address. At the bottom of the FLOW environment, when you click on the “Endpoints” tab, you will see the URL information that is specific to your instance. Of note is the Base URL. In the example below (as in the default mbed project), the Base URL is: https://run-west.att.io/1e464b19cdcde/774c88d68202/86694923d5bf28a/in/flow You have to take note of two parts of this address. The run-west.att.io part is the server URL, and you have to make sure the
  • MY_SERVER_URL field in config_me.h matches this. Then there is the rest of the base URL, in green above, that needs to be pasted into the FLOW_BASE_URL field.

There is also a FLOW_INPUT_NAME field. This should match the name of the HTTP IN port in the FLOW project that you want to send sensor data to. The default is "/climate", as in the FLOW image below.

/media/uploads/JMF/sf.png

Where is the binary I compiled

When the COMPILE button is pressed, it will compile your project and link it. The result is placed in the DOWNLOAD folder you use when downloading files from the internet. It will be called AvnetATT_shape_hackathon_K64F.bin.

Additional information on compiling/configuring

Comprehensive instructions can be found at: Quick Start Instructions

Committer:
stefanrousseau
Date:
Sat Jul 23 01:10:53 2016 +0000
Revision:
34:029e07b67a41
Parent:
33:eaf45dab650a
Fixed the char to be * char myJsonResponse[512];;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 2:0e2ef866af95 1 #include "mbed.h"
JMF 2:0e2ef866af95 2 #include <cctype>
JMF 2:0e2ef866af95 3 #include <string>
JMF 2:0e2ef866af95 4 #include "config_me.h"
JMF 2:0e2ef866af95 5 #include "SerialBuffered.h"
JMF 2:0e2ef866af95 6 #include "wnc_control.h"
JMF 2:0e2ef866af95 7
JMF 2:0e2ef866af95 8 extern Serial pc;
JMF 2:0e2ef866af95 9 extern Serial mdm;
JMF 2:0e2ef866af95 10 extern string MyServerIpAddress;
JMF 2:0e2ef866af95 11 extern string MySocketData;
JMF 2:0e2ef866af95 12
JMF 2:0e2ef866af95 13 int reinitialize_mdm(void);
JMF 2:0e2ef866af95 14
JMF 2:0e2ef866af95 15 enum WNC_ERR_e {
JMF 2:0e2ef866af95 16 WNC_OK =0,
JMF 2:0e2ef866af95 17 WNC_CMD_ERR = -1,
JMF 2:0e2ef866af95 18 WNC_NO_RESPONSE = -2
JMF 2:0e2ef866af95 19 };
JMF 2:0e2ef866af95 20
JMF 2:0e2ef866af95 21 // Contains result of last call to send_wnc_cmd(..)
JMF 2:0e2ef866af95 22 WNC_ERR_e WNC_MDM_ERR = WNC_OK;
JMF 2:0e2ef866af95 23
JMF 2:0e2ef866af95 24 // Contains the RAW WNC UART responses
JMF 2:0e2ef866af95 25 static string wncStr;
fkellermavnet 10:df54436ecd38 26 static int socketOpen = 0;
JMF 2:0e2ef866af95 27
JMF 2:0e2ef866af95 28 void software_init_mdm(void)
JMF 2:0e2ef866af95 29 {
JMF 2:0e2ef866af95 30 do
JMF 2:0e2ef866af95 31 {
JMF 2:0e2ef866af95 32 WNC_MDM_ERR = WNC_OK;
JMF 2:0e2ef866af95 33 at_init_wnc();
JMF 2:0e2ef866af95 34 if (WNC_MDM_ERR != WNC_OK)
JMF 2:0e2ef866af95 35 reinitialize_mdm();
JMF 2:0e2ef866af95 36 } while (WNC_MDM_ERR != WNC_OK);
JMF 2:0e2ef866af95 37 }
JMF 2:0e2ef866af95 38
JMF 2:0e2ef866af95 39 void resolve_mdm(void)
JMF 2:0e2ef866af95 40 {
JMF 2:0e2ef866af95 41 do
JMF 2:0e2ef866af95 42 {
JMF 2:0e2ef866af95 43 WNC_MDM_ERR = WNC_OK;
JMF 2:0e2ef866af95 44 at_dnsresolve_wnc(MY_SERVER_URL, &MyServerIpAddress);
JMF 2:0e2ef866af95 45 if (WNC_MDM_ERR == WNC_NO_RESPONSE)
JMF 2:0e2ef866af95 46 {
JMF 2:0e2ef866af95 47 reinitialize_mdm();
JMF 2:0e2ef866af95 48 software_init_mdm();
JMF 2:0e2ef866af95 49 }
JMF 2:0e2ef866af95 50 else if (WNC_MDM_ERR == WNC_CMD_ERR)
JMF 2:0e2ef866af95 51 {
JMF 2:0e2ef866af95 52 pc.puts("Bad URL!!!!!!\r\n");
JMF 2:0e2ef866af95 53 MyServerIpAddress = "192.168.0.1";
JMF 2:0e2ef866af95 54 WNC_MDM_ERR = WNC_OK;
JMF 2:0e2ef866af95 55 }
JMF 2:0e2ef866af95 56 } while (WNC_MDM_ERR != WNC_OK);
JMF 2:0e2ef866af95 57
fkellermavnet 32:8ba73eab6c72 58 pc.printf("My Server IP: %s\r\n", MyServerIpAddress.c_str());
JMF 2:0e2ef866af95 59 }
JMF 2:0e2ef866af95 60
JMF 2:0e2ef866af95 61 void sockopen_mdm(void)
JMF 2:0e2ef866af95 62 {
JMF 2:0e2ef866af95 63 do
JMF 2:0e2ef866af95 64 {
fkellermavnet 19:f89baed3bd6f 65 at_at_wnc();
fkellermavnet 19:f89baed3bd6f 66 at_at_wnc();
JMF 2:0e2ef866af95 67 WNC_MDM_ERR = WNC_OK;
JMF 2:0e2ef866af95 68 at_sockopen_wnc(MyServerIpAddress, MY_PORT_STR);
JMF 2:0e2ef866af95 69 if (WNC_MDM_ERR == WNC_NO_RESPONSE)
JMF 2:0e2ef866af95 70 {
JMF 2:0e2ef866af95 71 reinitialize_mdm();
JMF 2:0e2ef866af95 72 software_init_mdm();
JMF 2:0e2ef866af95 73 }
JMF 2:0e2ef866af95 74 else if (WNC_MDM_ERR == WNC_CMD_ERR)
JMF 2:0e2ef866af95 75 pc.puts("Socket open fail!!!!\r\n");
fkellermavnet 10:df54436ecd38 76 else
fkellermavnet 10:df54436ecd38 77 socketOpen = 1;
JMF 2:0e2ef866af95 78 } while (WNC_MDM_ERR != WNC_OK);
JMF 2:0e2ef866af95 79 }
JMF 2:0e2ef866af95 80
JMF 2:0e2ef866af95 81 void sockwrite_mdm(const char * s)
JMF 2:0e2ef866af95 82 {
fkellermavnet 10:df54436ecd38 83 if (socketOpen == 1)
fkellermavnet 10:df54436ecd38 84 {
JMF 2:0e2ef866af95 85 do
JMF 2:0e2ef866af95 86 {
JMF 2:0e2ef866af95 87 WNC_MDM_ERR = WNC_OK;
JMF 2:0e2ef866af95 88 at_sockwrite_wnc(s);
JMF 2:0e2ef866af95 89 if (WNC_MDM_ERR == WNC_NO_RESPONSE)
JMF 2:0e2ef866af95 90 {
JMF 2:0e2ef866af95 91 reinitialize_mdm();
JMF 2:0e2ef866af95 92 software_init_mdm();
JMF 2:0e2ef866af95 93 }
JMF 2:0e2ef866af95 94 else if (WNC_MDM_ERR == WNC_CMD_ERR)
JMF 2:0e2ef866af95 95 {
JMF 2:0e2ef866af95 96 pc.puts("Socket Write fail!!!\r\n");
JMF 2:0e2ef866af95 97 // Have seen when write fails modem gets stuck in bad state, try to recover
JMF 2:0e2ef866af95 98 reinitialize_mdm();
JMF 2:0e2ef866af95 99 software_init_mdm();
JMF 2:0e2ef866af95 100 }
JMF 2:0e2ef866af95 101 } while (WNC_MDM_ERR != WNC_OK);
fkellermavnet 10:df54436ecd38 102 }
fkellermavnet 10:df54436ecd38 103 else
fkellermavnet 10:df54436ecd38 104 puts("Socket is closed for write!\r\n");
JMF 2:0e2ef866af95 105 }
JMF 2:0e2ef866af95 106
fkellermavnet 33:eaf45dab650a 107 unsigned sockread_mdm(string * sockData, int len, int retries)
JMF 2:0e2ef866af95 108 {
fkellermavnet 33:eaf45dab650a 109 // Clear out any possible old data
fkellermavnet 33:eaf45dab650a 110 sockData->erase();
fkellermavnet 10:df54436ecd38 111 if (socketOpen == 1)
fkellermavnet 10:df54436ecd38 112 {
JMF 2:0e2ef866af95 113 do
JMF 2:0e2ef866af95 114 {
JMF 2:0e2ef866af95 115 WNC_MDM_ERR = WNC_OK;
JMF 2:0e2ef866af95 116 at_sockread_wnc(sockData, len, retries);
JMF 2:0e2ef866af95 117 if (WNC_MDM_ERR == WNC_NO_RESPONSE)
JMF 2:0e2ef866af95 118 {
JMF 2:0e2ef866af95 119 reinitialize_mdm();
JMF 2:0e2ef866af95 120 software_init_mdm();
JMF 2:0e2ef866af95 121 }
JMF 2:0e2ef866af95 122 else if (WNC_MDM_ERR == WNC_CMD_ERR)
JMF 2:0e2ef866af95 123 puts("Sock read fail!!!!\r\n");
JMF 2:0e2ef866af95 124 } while (WNC_MDM_ERR != WNC_OK);
fkellermavnet 10:df54436ecd38 125 }
fkellermavnet 10:df54436ecd38 126 else
fkellermavnet 10:df54436ecd38 127 puts("Socket is closed for read\r\n");
fkellermavnet 33:eaf45dab650a 128
fkellermavnet 33:eaf45dab650a 129 return (sockData->size());
JMF 2:0e2ef866af95 130 }
JMF 2:0e2ef866af95 131
JMF 2:0e2ef866af95 132 void sockclose_mdm(void)
JMF 2:0e2ef866af95 133 {
JMF 2:0e2ef866af95 134 do
JMF 2:0e2ef866af95 135 {
JMF 2:0e2ef866af95 136 WNC_MDM_ERR = WNC_OK;
JMF 2:0e2ef866af95 137 at_sockclose_wnc();
fkellermavnet 10:df54436ecd38 138 // Assume close happened even if it went bad
fkellermavnet 10:df54436ecd38 139 // going bad will result in a re-init anyways and if close
fkellermavnet 10:df54436ecd38 140 // fails we're pretty much in bad state and not much can do
fkellermavnet 10:df54436ecd38 141 socketOpen = 0;
JMF 2:0e2ef866af95 142 if (WNC_MDM_ERR == WNC_NO_RESPONSE)
JMF 2:0e2ef866af95 143 {
JMF 2:0e2ef866af95 144 reinitialize_mdm();
JMF 2:0e2ef866af95 145 software_init_mdm();
JMF 2:0e2ef866af95 146 }
JMF 2:0e2ef866af95 147 else if (WNC_MDM_ERR == WNC_CMD_ERR)
JMF 2:0e2ef866af95 148 puts("Sock close fail!!!\r\n");
JMF 2:0e2ef866af95 149 } while (WNC_MDM_ERR != WNC_OK);
JMF 2:0e2ef866af95 150 }
JMF 2:0e2ef866af95 151
JMF 2:0e2ef866af95 152 /**
JMF 2:0e2ef866af95 153 * C++ version 0.4 char* style "itoa":
JMF 2:0e2ef866af95 154 * Written by Lukás Chmela
JMF 2:0e2ef866af95 155 * Released under GPLv3.
JMF 2:0e2ef866af95 156 */
JMF 2:0e2ef866af95 157
JMF 2:0e2ef866af95 158 char* itoa(int value, char* result, int base)
JMF 2:0e2ef866af95 159 {
JMF 2:0e2ef866af95 160 // check that the base if valid
JMF 2:0e2ef866af95 161 if ( base < 2 || base > 36 ) {
JMF 2:0e2ef866af95 162 *result = '\0';
JMF 2:0e2ef866af95 163 return result;
JMF 2:0e2ef866af95 164 }
JMF 2:0e2ef866af95 165
JMF 2:0e2ef866af95 166 char* ptr = result, *ptr1 = result, tmp_char;
JMF 2:0e2ef866af95 167 int tmp_value;
JMF 2:0e2ef866af95 168
JMF 2:0e2ef866af95 169 do {
JMF 2:0e2ef866af95 170 tmp_value = value;
JMF 2:0e2ef866af95 171 value /= base;
JMF 2:0e2ef866af95 172 *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)];
JMF 2:0e2ef866af95 173 } while ( value );
JMF 2:0e2ef866af95 174
JMF 2:0e2ef866af95 175 // Apply negative sign
JMF 2:0e2ef866af95 176 if ( tmp_value < 0 )
JMF 2:0e2ef866af95 177 *ptr++ = '-';
JMF 2:0e2ef866af95 178 *ptr-- = '\0';
JMF 2:0e2ef866af95 179
JMF 2:0e2ef866af95 180 while ( ptr1 < ptr ) {
JMF 2:0e2ef866af95 181 tmp_char = *ptr;
JMF 2:0e2ef866af95 182 *ptr-- = *ptr1;
JMF 2:0e2ef866af95 183 *ptr1++ = tmp_char;
JMF 2:0e2ef866af95 184 }
JMF 2:0e2ef866af95 185
JMF 2:0e2ef866af95 186 return result;
JMF 2:0e2ef866af95 187 }
JMF 2:0e2ef866af95 188
JMF 2:0e2ef866af95 189 extern int mdm_sendAtCmdRsp(const char *cmd, const char **rsp_list, int timeout_ms, string * rsp, int * len);
JMF 2:0e2ef866af95 190
JMF 2:0e2ef866af95 191 // Sets a global with failure or success, assumes 1 thread all the time
JMF 2:0e2ef866af95 192 int send_wnc_cmd(const char * s, string ** r, int ms_timeout)
JMF 2:0e2ef866af95 193 {
JMF 2:0e2ef866af95 194 static const char * rsp_lst[] = { "OK", "ERROR", NULL };
JMF 2:0e2ef866af95 195 int len;
JMF 2:0e2ef866af95 196
JMF 2:0e2ef866af95 197 pc.printf("Send: %s\r\n",s);
JMF 2:0e2ef866af95 198 int res = mdm_sendAtCmdRsp(s, rsp_lst, ms_timeout, &wncStr, &len);
JMF 2:0e2ef866af95 199 *r = &wncStr; // Return a pointer to the static string
JMF 2:0e2ef866af95 200
JMF 2:0e2ef866af95 201 if (res >= 0)
JMF 2:0e2ef866af95 202 {
JMF 2:0e2ef866af95 203 pc.puts("[");
fkellermavnet 32:8ba73eab6c72 204 pc.puts(wncStr.c_str());
JMF 2:0e2ef866af95 205 pc.puts("]\n\r");
JMF 2:0e2ef866af95 206 if (res > 0)
JMF 2:0e2ef866af95 207 {
JMF 2:0e2ef866af95 208 if (WNC_MDM_ERR != WNC_NO_RESPONSE)
JMF 2:0e2ef866af95 209 WNC_MDM_ERR = WNC_CMD_ERR;
JMF 2:0e2ef866af95 210 return -1;
JMF 2:0e2ef866af95 211 }
JMF 2:0e2ef866af95 212 else
JMF 2:0e2ef866af95 213 return 0;
JMF 2:0e2ef866af95 214 }
JMF 2:0e2ef866af95 215 else
JMF 2:0e2ef866af95 216 {
JMF 2:0e2ef866af95 217 WNC_MDM_ERR = WNC_NO_RESPONSE;
JMF 2:0e2ef866af95 218 pc.puts("No response from WNC!\n\r");
JMF 2:0e2ef866af95 219 return -2;
JMF 2:0e2ef866af95 220 }
JMF 2:0e2ef866af95 221 }
JMF 2:0e2ef866af95 222
fkellermavnet 19:f89baed3bd6f 223 void at_at_wnc(void)
fkellermavnet 19:f89baed3bd6f 224 {
fkellermavnet 19:f89baed3bd6f 225 string * pRespStr;
fkellermavnet 19:f89baed3bd6f 226 send_wnc_cmd("AT", &pRespStr, WNC_TIMEOUT_MS); // Heartbeat?
fkellermavnet 19:f89baed3bd6f 227 }
fkellermavnet 19:f89baed3bd6f 228
JMF 2:0e2ef866af95 229 void at_init_wnc(void)
JMF 2:0e2ef866af95 230 {
JMF 2:0e2ef866af95 231 string * pRespStr;
JMF 2:0e2ef866af95 232 send_wnc_cmd("AT", &pRespStr, WNC_TIMEOUT_MS); // Heartbeat?
JMF 2:0e2ef866af95 233 send_wnc_cmd("ATE1", &pRespStr, WNC_TIMEOUT_MS); // Echo ON
JMF 2:0e2ef866af95 234 string cmd_str("AT%PDNSET=1,");
JMF 2:0e2ef866af95 235 cmd_str += MY_APN_STR;
JMF 2:0e2ef866af95 236 cmd_str += ",IP";
fkellermavnet 32:8ba73eab6c72 237 send_wnc_cmd(cmd_str.c_str(), &pRespStr, 2*WNC_TIMEOUT_MS); // Set APN, cmd seems to take a little longer sometimes
JMF 2:0e2ef866af95 238 send_wnc_cmd("AT@INTERNET=1", &pRespStr, WNC_TIMEOUT_MS); // Internet services enabled
JMF 2:0e2ef866af95 239 send_wnc_cmd("AT@SOCKDIAL=1", &pRespStr, WNC_TIMEOUT_MS);
JMF 2:0e2ef866af95 240 }
JMF 2:0e2ef866af95 241
JMF 2:0e2ef866af95 242 void at_sockopen_wnc(const string & ipStr, const char * port )
JMF 2:0e2ef866af95 243 {
JMF 2:0e2ef866af95 244 string * pRespStr;
JMF 2:0e2ef866af95 245 send_wnc_cmd("AT@SOCKCREAT=1", &pRespStr, WNC_TIMEOUT_MS);
JMF 2:0e2ef866af95 246 string cmd_str("AT@SOCKCONN=1,\"");
JMF 2:0e2ef866af95 247 cmd_str += ipStr;
JMF 2:0e2ef866af95 248 cmd_str += "\",";
JMF 2:0e2ef866af95 249 cmd_str += port;
fkellermavnet 32:8ba73eab6c72 250 send_wnc_cmd(cmd_str.c_str(), &pRespStr, WNC_TIMEOUT_MS);
JMF 2:0e2ef866af95 251 }
JMF 2:0e2ef866af95 252
JMF 2:0e2ef866af95 253 void at_sockclose_wnc(void)
JMF 2:0e2ef866af95 254 {
JMF 2:0e2ef866af95 255 string * pRespStr;
JMF 2:0e2ef866af95 256 send_wnc_cmd("AT@SOCKCLOSE=1", &pRespStr, WNC_TIMEOUT_MS);
JMF 2:0e2ef866af95 257 }
JMF 2:0e2ef866af95 258
JMF 2:0e2ef866af95 259 int at_dnsresolve_wnc(const char * s, string * ipStr)
JMF 2:0e2ef866af95 260 {
JMF 2:0e2ef866af95 261 string * pRespStr;
JMF 2:0e2ef866af95 262 string str(s);
JMF 2:0e2ef866af95 263 str = "AT@DNSRESVDON=\"" + str;
JMF 2:0e2ef866af95 264 str += "\"\r\n";
fkellermavnet 32:8ba73eab6c72 265 if (send_wnc_cmd(str.c_str(), &pRespStr, WNC_TIMEOUT_MS) == 0)
JMF 2:0e2ef866af95 266 {
JMF 2:0e2ef866af95 267 size_t pos_start = pRespStr->find(":\"") + 2;
JMF 2:0e2ef866af95 268 if (pos_start != string::npos)
JMF 2:0e2ef866af95 269 {
JMF 2:0e2ef866af95 270 size_t pos_end = pRespStr->rfind("\"") - 1;
JMF 2:0e2ef866af95 271 if (pos_end != string::npos)
JMF 2:0e2ef866af95 272 {
JMF 2:0e2ef866af95 273 if (pos_end > pos_start)
JMF 2:0e2ef866af95 274 {
JMF 2:0e2ef866af95 275 // Make a copy for use later (the source string is re-used)
JMF 2:0e2ef866af95 276 *ipStr = pRespStr->substr(pos_start, pos_end - pos_start + 1);
JMF 2:0e2ef866af95 277 return 1;
JMF 2:0e2ef866af95 278 }
JMF 2:0e2ef866af95 279 else
JMF 2:0e2ef866af95 280 pc.puts("URL Resolve fail, substr Err\r\n");
JMF 2:0e2ef866af95 281 }
JMF 2:0e2ef866af95 282 else
JMF 2:0e2ef866af95 283 pc.puts("URL Resolve fail, no 2nd quote\r\n");
JMF 2:0e2ef866af95 284 }
JMF 2:0e2ef866af95 285 else
JMF 2:0e2ef866af95 286 pc.puts("URL Resolve fail, no quotes\r\n");
JMF 2:0e2ef866af95 287 }
JMF 2:0e2ef866af95 288 else
JMF 2:0e2ef866af95 289 pc.puts("URL Resolve fail, WNC cmd fail\r\n");
JMF 2:0e2ef866af95 290
JMF 2:0e2ef866af95 291 return -1;
JMF 2:0e2ef866af95 292 }
JMF 2:0e2ef866af95 293
JMF 2:0e2ef866af95 294 void at_sockwrite_wnc(const char * s)
JMF 2:0e2ef866af95 295 {
JMF 2:0e2ef866af95 296 string * pRespStr;
JMF 2:0e2ef866af95 297 char num2str[6];
JMF 2:0e2ef866af95 298 size_t sLen = strlen(s);
JMF 2:0e2ef866af95 299 if (sLen <= 99999)
JMF 2:0e2ef866af95 300 {
JMF 2:0e2ef866af95 301 string cmd_str("AT@SOCKWRITE=1,");
JMF 2:0e2ef866af95 302 itoa(sLen, num2str, 10);
JMF 2:0e2ef866af95 303 cmd_str += num2str;
JMF 2:0e2ef866af95 304 cmd_str += ",\"";
JMF 2:0e2ef866af95 305 while(*s != '\0')
JMF 2:0e2ef866af95 306 {
JMF 2:0e2ef866af95 307 itoa((int)*s++, num2str, 16);
JMF 2:0e2ef866af95 308 // Always 2-digit ascii hex:
JMF 2:0e2ef866af95 309 if (strlen(num2str) == 1)
JMF 2:0e2ef866af95 310 {
JMF 2:0e2ef866af95 311 num2str[2] = '\0';
JMF 2:0e2ef866af95 312 num2str[1] = num2str[0];
JMF 2:0e2ef866af95 313 num2str[0] = '0';
JMF 2:0e2ef866af95 314 }
JMF 2:0e2ef866af95 315 cmd_str += num2str;
JMF 2:0e2ef866af95 316 }
JMF 2:0e2ef866af95 317 cmd_str += "\"";
fkellermavnet 32:8ba73eab6c72 318 send_wnc_cmd(cmd_str.c_str(), &pRespStr, WNC_TIMEOUT_MS);
JMF 2:0e2ef866af95 319 }
JMF 2:0e2ef866af95 320 else
JMF 2:0e2ef866af95 321 pc.puts("sockwrite Err, string to long\r\n");
JMF 2:0e2ef866af95 322 }
JMF 2:0e2ef866af95 323
JMF 2:0e2ef866af95 324 unsigned at_sockread_wnc(string * pS, unsigned n, unsigned retries = 0)
JMF 2:0e2ef866af95 325 {
JMF 2:0e2ef866af95 326 unsigned i;
JMF 2:0e2ef866af95 327 string * pRespStr;
JMF 2:0e2ef866af95 328 string cmd_str("AT@SOCKREAD=1,");
fkellermavnet 33:eaf45dab650a 329
fkellermavnet 33:eaf45dab650a 330 // Don't assume clean slate:
fkellermavnet 33:eaf45dab650a 331 pS->erase();
fkellermavnet 33:eaf45dab650a 332
JMF 2:0e2ef866af95 333 if (n <= 1500)
JMF 2:0e2ef866af95 334 {
JMF 2:0e2ef866af95 335 char num2str[6];
fkellermavnet 22:41e6c417ace1 336
JMF 2:0e2ef866af95 337 itoa(n, num2str, 10);
JMF 2:0e2ef866af95 338 cmd_str += num2str;
JMF 2:0e2ef866af95 339 retries += 1;
JMF 2:0e2ef866af95 340 while (retries--)
JMF 2:0e2ef866af95 341 {
fkellermavnet 22:41e6c417ace1 342 // Assuming someone is sending then calling this to receive response, invoke
fkellermavnet 22:41e6c417ace1 343 // a pause to give the response some time to come back and then also
fkellermavnet 22:41e6c417ace1 344 // between each retry.
fkellermavnet 22:41e6c417ace1 345 wait_ms(10);
fkellermavnet 22:41e6c417ace1 346
fkellermavnet 32:8ba73eab6c72 347 send_wnc_cmd(cmd_str.c_str(), &pRespStr, WNC_TIMEOUT_MS);
JMF 2:0e2ef866af95 348 size_t pos_start = pRespStr->find("\"") + 1;
JMF 2:0e2ef866af95 349 size_t pos_end = pRespStr->rfind("\"") - 1;
JMF 2:0e2ef866af95 350 i = pos_end - pos_start + 1;
JMF 2:0e2ef866af95 351 if (i > 0)
JMF 2:0e2ef866af95 352 {
JMF 2:0e2ef866af95 353 retries = 0; // If any data found stop retrying
JMF 2:0e2ef866af95 354 string byte;
JMF 2:0e2ef866af95 355 while (pos_start < pos_end)
JMF 2:0e2ef866af95 356 {
JMF 2:0e2ef866af95 357 byte = pRespStr->substr(pos_start, 2);
fkellermavnet 32:8ba73eab6c72 358 *pS += (char)strtol(byte.c_str(), NULL, 16);
JMF 2:0e2ef866af95 359 pos_start += 2;
JMF 2:0e2ef866af95 360 }
JMF 2:0e2ef866af95 361 return i;
JMF 2:0e2ef866af95 362 }
JMF 2:0e2ef866af95 363 }
JMF 2:0e2ef866af95 364 }
JMF 2:0e2ef866af95 365 else
JMF 2:0e2ef866af95 366 pc.puts("sockread Err, to many to read\r\n");
JMF 2:0e2ef866af95 367
JMF 2:0e2ef866af95 368 return 0;
JMF 2:0e2ef866af95 369 }