This program connects to a few sensors via I2C and sends the data collected to a WNC Cellular Module which is located on an Avnet WNC-Shield card.

Dependencies:   FXOS8700CQ MODSERIAL mbed

/media/uploads/kevinkeryk/avnet_logo_tagline_rgb.png

Avnet Cellular IoT Instructions

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

Useful Links

Adding Additional Sensors

The FLOW_DEVICE_NAME field must contain the name of the instance of the Virtual Starter Kit in FLOW you will be communicating with. Usually this is "vstarterkit001", but if you have problems communicating you can verify this is correct. Note: 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 as the DEVICE SERIAL field under Devices as in the image below. /media/uploads/JMF/vstarterkit.png

Sensors: When executing, the FRDM-K64F board uploads 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 reports 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 onboard 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 are 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” are also sent. To enable all these sensors, change the assignment to: iSensorsToReport = TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS;

Connecting 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 followed:

SignalJ10ShieldPMOD Color in the image below
VCCPin 6Pin 6Red
GNDPin 5Pin 5Black
SDAPin4Pin 3Green
SCLPin3Pin 2Yellow

/media/uploads/JMF/xyz.jpg

AT&T M2X and FLOW Instructions

M2X & FLOW Instructions

Link to AT&T M2X

M2X

Link to AT&T Flow

FLOW

Avnet WNC-Shield Information

Getting Started with the Avnet WNC-Shield 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

Inside the mbed Avnet_ATT_Cellular_IOT project, the parameters needed to customize your board are in the config_me.h file.

  • FLOW parameters: This project assumes you are using a fork of the Starter Kit Base project, which is a reference design created using AT&T’s FLOW (https://flow.att.com) that allows the creation of online 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, URL information that is specific to your instance is displayed. 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. The rest of the base URL, in green above, 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 compiles your project and links 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:
Sun Jul 10 09:12:33 2016 +0000
Revision:
3:26b3cc155f39
Parent:
2:0e2ef866af95
Child:
4:f83bedd9cab4
Stefan added:; 1) Flow_parameters.h; 2) ms timer tick currently expires every 5 seconds; 3) function to parse values into sensor structure

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 0:9d5134074d84 1 #include "mbed.h"
JMF 0:9d5134074d84 2 #include <cctype>
JMF 0:9d5134074d84 3 #include <string>
JMF 0:9d5134074d84 4 #include "SerialBuffered.h"
JMF 0:9d5134074d84 5 #include "HTS221.h"
JMF 2:0e2ef866af95 6 #include "config_me.h"
JMF 2:0e2ef866af95 7 #include "wnc_control.h"
JMF 2:0e2ef866af95 8
JMF 0:9d5134074d84 9
JMF 0:9d5134074d84 10 // comment out the following line if color is not supported on the terminal
JMF 0:9d5134074d84 11 #define USE_COLOR
JMF 0:9d5134074d84 12 #ifdef USE_COLOR
JMF 0:9d5134074d84 13 #define BLK "\033[30m"
JMF 0:9d5134074d84 14 #define RED "\033[31m"
JMF 0:9d5134074d84 15 #define GRN "\033[32m"
JMF 0:9d5134074d84 16 #define YEL "\033[33m"
JMF 0:9d5134074d84 17 #define BLU "\033[34m"
JMF 0:9d5134074d84 18 #define MAG "\033[35m"
JMF 0:9d5134074d84 19 #define CYN "\033[36m"
JMF 0:9d5134074d84 20 #define WHT "\033[37m"
JMF 0:9d5134074d84 21 #define DEF "\033[39m"
JMF 0:9d5134074d84 22 #else
JMF 0:9d5134074d84 23 #define BLK
JMF 0:9d5134074d84 24 #define RED
JMF 0:9d5134074d84 25 #define GRN
JMF 0:9d5134074d84 26 #define YEL
JMF 0:9d5134074d84 27 #define BLU
JMF 0:9d5134074d84 28 #define MAG
JMF 0:9d5134074d84 29 #define CYN
JMF 0:9d5134074d84 30 #define WHT
JMF 0:9d5134074d84 31 #define DEF
JMF 0:9d5134074d84 32 #endif
JMF 0:9d5134074d84 33
JMF 0:9d5134074d84 34 #define MDM_DBG_OFF 0
JMF 0:9d5134074d84 35 #define MDM_DBG_AT_CMDS (1 << 0)
JMF 0:9d5134074d84 36 int mdm_dbgmask = MDM_DBG_OFF;
JMF 0:9d5134074d84 37
JMF 0:9d5134074d84 38 Serial pc(USBTX, USBRX);
JMF 0:9d5134074d84 39 SerialBuffered mdm(PTD3, PTD2, 128);
JMF 0:9d5134074d84 40 DigitalOut led_red(LED_RED);
JMF 0:9d5134074d84 41 DigitalOut led_green(LED_GREEN);
JMF 0:9d5134074d84 42
JMF 0:9d5134074d84 43 DigitalOut mdm_uart2_rx_boot_mode_sel(PTC17); // on powerup, 0 = boot mode, 1 = normal boot
JMF 0:9d5134074d84 44 DigitalOut mdm_power_on(PTB9); // 0 = turn modem on, 1 = turn modem off (should be held high for >5 seconds to cycle modem)
JMF 0:9d5134074d84 45 DigitalOut mdm_wakeup_in(PTC2); // 0 = let modem sleep, 1 = keep modem awake -- Note: pulled high on shield
JMF 0:9d5134074d84 46
JMF 0:9d5134074d84 47 DigitalOut shield_3v3_1v8_sig_trans_ena(PTC4); // 0 = disabled (all signals high impedence, 1 = translation active
JMF 0:9d5134074d84 48 DigitalOut mdm_uart1_cts(PTD0);
JMF 0:9d5134074d84 49
JMF 0:9d5134074d84 50 #define TOUPPER(a) (a) //toupper(a)
JMF 0:9d5134074d84 51
JMF 0:9d5134074d84 52 const char ok_str[] = "OK";
JMF 0:9d5134074d84 53 const char error_str[] = "ERROR";
JMF 0:9d5134074d84 54
JMF 0:9d5134074d84 55 #define MDM_OK 0
JMF 0:9d5134074d84 56 #define MDM_ERR_TIMEOUT -1
JMF 0:9d5134074d84 57
JMF 0:9d5134074d84 58 #define MAX_AT_RSP_LEN 255
JMF 0:9d5134074d84 59
JMF 0:9d5134074d84 60 ssize_t mdm_getline(char *buff, size_t size, int timeout_ms) {
JMF 0:9d5134074d84 61 int cin = -1;
JMF 0:9d5134074d84 62 int cin_last;
JMF 0:9d5134074d84 63
JMF 0:9d5134074d84 64 if (NULL == buff || size == 0) {
JMF 0:9d5134074d84 65 return -1;
JMF 0:9d5134074d84 66 }
JMF 0:9d5134074d84 67
JMF 0:9d5134074d84 68 size_t len = 0;
JMF 0:9d5134074d84 69 Timer timer;
JMF 0:9d5134074d84 70 timer.start();
JMF 0:9d5134074d84 71 while ((len < (size-1)) && (timer.read_ms() < timeout_ms)) {
JMF 0:9d5134074d84 72 if (mdm.readable()) {
JMF 0:9d5134074d84 73 cin_last = cin;
JMF 0:9d5134074d84 74 cin = mdm.getc();
JMF 0:9d5134074d84 75 if (isprint(cin)) {
JMF 0:9d5134074d84 76 buff[len++] = (char)cin;
JMF 0:9d5134074d84 77 continue;
JMF 0:9d5134074d84 78 } else if (('\r' == cin_last) && ('\n' == cin)) {
JMF 0:9d5134074d84 79 break;
JMF 0:9d5134074d84 80 }
JMF 0:9d5134074d84 81 }
JMF 0:9d5134074d84 82 wait_ms(1);
JMF 0:9d5134074d84 83 }
JMF 2:0e2ef866af95 84 buff[len] = (char)NULL;
JMF 0:9d5134074d84 85
JMF 0:9d5134074d84 86 return len;
JMF 0:9d5134074d84 87 }
JMF 0:9d5134074d84 88
JMF 0:9d5134074d84 89 int mdm_sendAtCmd(const char *cmd, const char **rsp_list, int timeout_ms) {
JMF 0:9d5134074d84 90 if (cmd && strlen(cmd) > 0) {
JMF 0:9d5134074d84 91 if (mdm_dbgmask & MDM_DBG_AT_CMDS) {
JMF 0:9d5134074d84 92 printf(MAG "ATCMD: " DEF "--> " GRN "%s" DEF "\n", cmd);
JMF 0:9d5134074d84 93 }
JMF 0:9d5134074d84 94 mdm.printf("%s\r\n", cmd);
JMF 0:9d5134074d84 95 }
JMF 0:9d5134074d84 96
JMF 0:9d5134074d84 97 if (rsp_list) {
JMF 0:9d5134074d84 98 Timer timer;
JMF 0:9d5134074d84 99 char rsp[MAX_AT_RSP_LEN+1];
JMF 0:9d5134074d84 100 int len;
JMF 0:9d5134074d84 101
JMF 0:9d5134074d84 102 timer.start();
JMF 0:9d5134074d84 103 while (timer.read_ms() < timeout_ms) {
JMF 0:9d5134074d84 104 len = mdm_getline(rsp, sizeof(rsp), timeout_ms - timer.read_ms());
JMF 0:9d5134074d84 105
JMF 0:9d5134074d84 106 if (len < 0)
JMF 0:9d5134074d84 107 return MDM_ERR_TIMEOUT;
JMF 0:9d5134074d84 108
JMF 0:9d5134074d84 109 if (len == 0)
JMF 0:9d5134074d84 110 continue;
JMF 0:9d5134074d84 111
JMF 0:9d5134074d84 112 if (mdm_dbgmask & MDM_DBG_AT_CMDS) {
JMF 0:9d5134074d84 113 printf(MAG "ATRSP: " DEF "<-- " CYN "%s" DEF "\n", rsp);
JMF 0:9d5134074d84 114 }
JMF 0:9d5134074d84 115
JMF 0:9d5134074d84 116 if (rsp_list) {
JMF 0:9d5134074d84 117 int rsp_idx = 0;
JMF 0:9d5134074d84 118 while (rsp_list[rsp_idx]) {
JMF 0:9d5134074d84 119 if (strcasecmp(rsp, rsp_list[rsp_idx]) == 0) {
JMF 0:9d5134074d84 120 return rsp_idx;
JMF 0:9d5134074d84 121 }
JMF 0:9d5134074d84 122 rsp_idx++;
JMF 0:9d5134074d84 123 }
JMF 0:9d5134074d84 124 }
JMF 0:9d5134074d84 125 }
JMF 0:9d5134074d84 126 return MDM_ERR_TIMEOUT;
JMF 0:9d5134074d84 127 }
JMF 0:9d5134074d84 128 return MDM_OK;
JMF 0:9d5134074d84 129 }
JMF 0:9d5134074d84 130
JMF 0:9d5134074d84 131 int mdm_init(void) {
JMF 0:9d5134074d84 132 // disable signal level translator
JMF 0:9d5134074d84 133 shield_3v3_1v8_sig_trans_ena = 0;
JMF 0:9d5134074d84 134
JMF 0:9d5134074d84 135 // power modem on //off
JMF 0:9d5134074d84 136 mdm_power_on = 0; //1;
JMF 0:9d5134074d84 137
JMF 0:9d5134074d84 138 // insure modem boots into normal operating mode
JMF 0:9d5134074d84 139 // and does not go to sleep when powered on
JMF 0:9d5134074d84 140 mdm_uart2_rx_boot_mode_sel = 1;
JMF 0:9d5134074d84 141 mdm_wakeup_in = 1;
JMF 0:9d5134074d84 142
JMF 0:9d5134074d84 143 // initialze comm with the modem
JMF 0:9d5134074d84 144 mdm.baud(115200);
JMF 2:0e2ef866af95 145 // clear out potential garbage
JMF 2:0e2ef866af95 146 while (mdm.readable())
JMF 2:0e2ef866af95 147 mdm.getc();
JMF 2:0e2ef866af95 148
JMF 0:9d5134074d84 149 mdm_uart1_cts = 0;
JMF 0:9d5134074d84 150
JMF 0:9d5134074d84 151 // enable the signal level translator to start
JMF 0:9d5134074d84 152 // modem reset process (modem will be powered down)
JMF 0:9d5134074d84 153 shield_3v3_1v8_sig_trans_ena = 1;
JMF 0:9d5134074d84 154
JMF 0:9d5134074d84 155 // Give the modem 60 secons to start responding by
JMF 0:9d5134074d84 156 // sending simple 'AT' commands to modem once per second.
JMF 0:9d5134074d84 157 Timer timer;
JMF 0:9d5134074d84 158 timer.start();
JMF 0:9d5134074d84 159 while (timer.read() < 60) {
JMF 0:9d5134074d84 160 const char * rsp_lst[] = { ok_str, error_str, NULL };
JMF 0:9d5134074d84 161 int rc = mdm_sendAtCmd("AT", rsp_lst, 500);
JMF 0:9d5134074d84 162 if (rc == 0)
JMF 0:9d5134074d84 163 return timer.read();
JMF 0:9d5134074d84 164 wait_ms(1000 - (timer.read_ms() % 1000));
JMF 0:9d5134074d84 165 pc.printf("\r%d",timer.read_ms()/1000);
JMF 0:9d5134074d84 166 }
JMF 0:9d5134074d84 167 return false;
JMF 0:9d5134074d84 168 }
JMF 0:9d5134074d84 169
JMF 2:0e2ef866af95 170 int mdm_sendAtCmdRsp(const char *cmd, const char **rsp_list, int timeout_ms, string * rsp, int * len) {
JMF 2:0e2ef866af95 171
JMF 2:0e2ef866af95 172 static char cmd_buf[3200]; // Need enough room for the WNC sockreads (over 3000 chars)
JMF 2:0e2ef866af95 173
JMF 2:0e2ef866af95 174 if (cmd && strlen(cmd) > 0) {
JMF 2:0e2ef866af95 175 if (mdm_dbgmask & MDM_DBG_AT_CMDS) {
JMF 2:0e2ef866af95 176 printf(MAG "ATCMD: " DEF "--> " GRN "%s" DEF "\n", cmd);
JMF 2:0e2ef866af95 177 }
JMF 2:0e2ef866af95 178 mdm.printf("%s\r\n", cmd);
JMF 2:0e2ef866af95 179 }
JMF 2:0e2ef866af95 180
JMF 2:0e2ef866af95 181 if (rsp_list) {
JMF 2:0e2ef866af95 182 rsp->erase(); // Clean up from prior cmd response
JMF 2:0e2ef866af95 183 *len = 0;
JMF 2:0e2ef866af95 184 Timer timer;
JMF 2:0e2ef866af95 185 timer.start();
JMF 2:0e2ef866af95 186 while (timer.read_ms() < timeout_ms) {
JMF 2:0e2ef866af95 187 int lenCmd = mdm_getline(cmd_buf, sizeof(cmd_buf), timeout_ms - timer.read_ms());
JMF 2:0e2ef866af95 188
JMF 2:0e2ef866af95 189 if (lenCmd == 0)
JMF 2:0e2ef866af95 190 continue;
JMF 2:0e2ef866af95 191
JMF 2:0e2ef866af95 192 if (lenCmd < 0)
JMF 2:0e2ef866af95 193 return MDM_ERR_TIMEOUT;
JMF 2:0e2ef866af95 194 else {
JMF 2:0e2ef866af95 195 *len += lenCmd;
JMF 2:0e2ef866af95 196 *rsp += cmd_buf;
JMF 2:0e2ef866af95 197 }
JMF 2:0e2ef866af95 198
JMF 2:0e2ef866af95 199 if (mdm_dbgmask & MDM_DBG_AT_CMDS) {
JMF 2:0e2ef866af95 200 printf(MAG "ATRSP: " DEF "<-- " CYN "%s" DEF "\n", cmd_buf);
JMF 2:0e2ef866af95 201 }
JMF 2:0e2ef866af95 202
JMF 2:0e2ef866af95 203 int rsp_idx = 0;
JMF 2:0e2ef866af95 204 while (rsp_list[rsp_idx]) {
JMF 2:0e2ef866af95 205 if (strcasecmp(cmd_buf, rsp_list[rsp_idx]) == 0) {
JMF 2:0e2ef866af95 206 return rsp_idx;
JMF 2:0e2ef866af95 207 }
JMF 2:0e2ef866af95 208 rsp_idx++;
JMF 2:0e2ef866af95 209 }
JMF 2:0e2ef866af95 210 }
JMF 2:0e2ef866af95 211 return MDM_ERR_TIMEOUT;
JMF 2:0e2ef866af95 212 }
JMF 2:0e2ef866af95 213 pc.printf("D %s",rsp);
JMF 2:0e2ef866af95 214 return MDM_OK;
JMF 2:0e2ef866af95 215 }
JMF 2:0e2ef866af95 216
JMF 2:0e2ef866af95 217 void reinitialize_mdm(void)
JMF 2:0e2ef866af95 218 {
JMF 2:0e2ef866af95 219 // Initialize the modem
JMF 2:0e2ef866af95 220 printf(GRN "Modem RE-initializing..." DEF "\r\n");
JMF 2:0e2ef866af95 221 if (!mdm_init()) {
JMF 2:0e2ef866af95 222 printf(RED "\n\rModem RE-initialization failed!" DEF "\n");
JMF 2:0e2ef866af95 223 }
JMF 2:0e2ef866af95 224 printf("\r\n");
JMF 2:0e2ef866af95 225 }
JMF 2:0e2ef866af95 226 // These are built on the fly
JMF 2:0e2ef866af95 227 string MyServerIpAddress;
JMF 2:0e2ef866af95 228 string MySocketData;
JMF 2:0e2ef866af95 229
JMF 2:0e2ef866af95 230 // These are to be built on the fly
JMF 2:0e2ef866af95 231 string my_temp;
JMF 2:0e2ef866af95 232 string my_humidity;
JMF 2:0e2ef866af95 233
JMF 0:9d5134074d84 234 #define CTOF(x) ((x)*1.8+32)
JMF 0:9d5134074d84 235
stefanrousseau 3:26b3cc155f39 236 #include "Flow_parameters.h"
stefanrousseau 3:26b3cc155f39 237 //********************************************************************************************************************************************
stefanrousseau 3:26b3cc155f39 238 //* Create string that can be sent to flow as an HTTP get
stefanrousseau 3:26b3cc155f39 239 //********************************************************************************************************************************************
stefanrousseau 3:26b3cc155f39 240 static K64F_Sensors_t SENSOR_DATA =
stefanrousseau 3:26b3cc155f39 241 {
stefanrousseau 3:26b3cc155f39 242 .Temperature = "0",
stefanrousseau 3:26b3cc155f39 243 .Humidity = "0",
stefanrousseau 3:26b3cc155f39 244 .AccelX = "0",
stefanrousseau 3:26b3cc155f39 245 .AccelY = "0",
stefanrousseau 3:26b3cc155f39 246 .AccelZ = "0",
stefanrousseau 3:26b3cc155f39 247 .AmbientLight = "0",
stefanrousseau 3:26b3cc155f39 248 .UVindex = "0",
stefanrousseau 3:26b3cc155f39 249 .Proximity = "0"
stefanrousseau 3:26b3cc155f39 250 };
stefanrousseau 3:26b3cc155f39 251 static Flow_datapoint_t FLOW_DATAPOINT =
stefanrousseau 3:26b3cc155f39 252 {
stefanrousseau 3:26b3cc155f39 253 .URL_start = FLOW_CALLBACK_URL_START,
stefanrousseau 3:26b3cc155f39 254 .URL_end = FLOW_CALLBACK_URL_END,
stefanrousseau 3:26b3cc155f39 255 .Device_ID = FLOW_DEVICE_ID
stefanrousseau 3:26b3cc155f39 256 };
stefanrousseau 3:26b3cc155f39 257 void GenerateModemString(char * modem_string)
stefanrousseau 3:26b3cc155f39 258 {
stefanrousseau 3:26b3cc155f39 259 sprintf(modem_string, "%s?deviceID=%s&temp=%s&humidity=%s %s", FLOW_DATAPOINT.URL_start, FLOW_DATAPOINT.Device_ID, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, FLOW_DATAPOINT.URL_end);
stefanrousseau 3:26b3cc155f39 260 } //GenerateModemString
stefanrousseau 3:26b3cc155f39 261
stefanrousseau 3:26b3cc155f39 262
stefanrousseau 3:26b3cc155f39 263 //Periodic timer
stefanrousseau 3:26b3cc155f39 264 Ticker OneMsTicker;
stefanrousseau 3:26b3cc155f39 265 volatile bool bTimerExpiredFlag = false;
stefanrousseau 3:26b3cc155f39 266 int OneMsTicks = 0;
stefanrousseau 3:26b3cc155f39 267 int iTimer1Interval_ms = 1000;
stefanrousseau 3:26b3cc155f39 268 //********************************************************************************************************************************************
stefanrousseau 3:26b3cc155f39 269 //* Periodic 1ms timer tick
stefanrousseau 3:26b3cc155f39 270 //********************************************************************************************************************************************
stefanrousseau 3:26b3cc155f39 271 void OneMsFunction()
stefanrousseau 3:26b3cc155f39 272 {
stefanrousseau 3:26b3cc155f39 273 OneMsTicks++;
stefanrousseau 3:26b3cc155f39 274 if ((OneMsTicks % iTimer1Interval_ms) == 0)
stefanrousseau 3:26b3cc155f39 275 {
stefanrousseau 3:26b3cc155f39 276 bTimerExpiredFlag = true;
stefanrousseau 3:26b3cc155f39 277 }
stefanrousseau 3:26b3cc155f39 278 } //OneMsFunction()
stefanrousseau 3:26b3cc155f39 279
JMF 0:9d5134074d84 280 int main() {
JMF 2:0e2ef866af95 281 int i;
JMF 0:9d5134074d84 282 HTS221 hts221;
JMF 0:9d5134074d84 283 pc.baud(115200);
JMF 0:9d5134074d84 284
JMF 0:9d5134074d84 285 void hts221_init(void);
JMF 0:9d5134074d84 286
JMF 1:af7a42f7d465 287 pc.printf(BLU "Hello World from AT&T Shape!\r\n\n\r");
JMF 0:9d5134074d84 288 pc.printf(GRN "Initialize the HTS221\n\r");
JMF 0:9d5134074d84 289
JMF 0:9d5134074d84 290 i = hts221.begin();
JMF 0:9d5134074d84 291 if( i )
JMF 0:9d5134074d84 292 pc.printf(BLU "HTS221 Detected! (0x%02X)\n\r",i);
JMF 0:9d5134074d84 293 else
JMF 0:9d5134074d84 294 pc.printf(RED "HTS221 NOT DETECTED!!\n\r");
JMF 0:9d5134074d84 295
JMF 0:9d5134074d84 296 printf("Temp is: %0.2f F \n\r",CTOF(hts221.readTemperature()));
JMF 0:9d5134074d84 297 printf("Humid is: %02d %%\n\r",hts221.readHumidity());
JMF 0:9d5134074d84 298
JMF 0:9d5134074d84 299 // Initialize the modem
JMF 0:9d5134074d84 300 printf(GRN "Modem initializing... will take up to 60 seconds" DEF "\r\n");
JMF 0:9d5134074d84 301 i=mdm_init();
JMF 0:9d5134074d84 302 if (!i) {
JMF 0:9d5134074d84 303 pc.printf(RED "Modem initialization failed!" DEF "\n");
JMF 0:9d5134074d84 304 while (1);
JMF 0:9d5134074d84 305 }
JMF 0:9d5134074d84 306
JMF 2:0e2ef866af95 307 //Software init
JMF 2:0e2ef866af95 308 software_init_mdm();
JMF 2:0e2ef866af95 309
JMF 2:0e2ef866af95 310 // Resolve URL to IP address to connect to
JMF 2:0e2ef866af95 311 resolve_mdm();
JMF 0:9d5134074d84 312
stefanrousseau 3:26b3cc155f39 313 //Create a 1ms timer tick function:
stefanrousseau 3:26b3cc155f39 314 OneMsTicker.attach(OneMsFunction, 0.001f) ;
stefanrousseau 3:26b3cc155f39 315 iTimer1Interval_ms = 5000; //5 seconds
stefanrousseau 3:26b3cc155f39 316
JMF 2:0e2ef866af95 317 // Send and receive data perpetually
JMF 2:0e2ef866af95 318 while(1) {
stefanrousseau 3:26b3cc155f39 319 if (bTimerExpiredFlag)
stefanrousseau 3:26b3cc155f39 320 {
stefanrousseau 3:26b3cc155f39 321 bTimerExpiredFlag = false;
stefanrousseau 3:26b3cc155f39 322 sprintf(SENSOR_DATA.Temperature, "%0.2f", CTOF(hts221.readTemperature()));
stefanrousseau 3:26b3cc155f39 323 sprintf(SENSOR_DATA.Humidity, "%02d", hts221.readHumidity());
stefanrousseau 3:26b3cc155f39 324
stefanrousseau 3:26b3cc155f39 325 sockopen_mdm();
stefanrousseau 3:26b3cc155f39 326
stefanrousseau 3:26b3cc155f39 327 char modem_string[512];
stefanrousseau 3:26b3cc155f39 328 GenerateModemString(&modem_string[0]);
stefanrousseau 3:26b3cc155f39 329 printf(DEF "Sending to modem : %s\n", modem_string);
stefanrousseau 3:26b3cc155f39 330 //sockwrite_mdm("GET /f653d97537235/a31c2684a02c/d35e42196968fd6/in/flow/climate?deviceID=e5ee19804bd500c8fe69a809342384c2&temp=41.0&humidity=87.33 HTTP/1.1 Host: run-east.att.io:80 Accept: */*\r\n\r\n");
stefanrousseau 3:26b3cc155f39 331
stefanrousseau 3:26b3cc155f39 332 sockwrite_mdm(modem_string);
stefanrousseau 3:26b3cc155f39 333 sockread_mdm(&MySocketData, 1024, 20);
stefanrousseau 3:26b3cc155f39 334 sockclose_mdm();
stefanrousseau 3:26b3cc155f39 335 } //bTimerExpiredFlag
stefanrousseau 3:26b3cc155f39 336 } //forever loop
JMF 2:0e2ef866af95 337
JMF 2:0e2ef866af95 338 string * pStr;
JMF 2:0e2ef866af95 339 while (1)
JMF 2:0e2ef866af95 340 {
JMF 2:0e2ef866af95 341 send_wnc_cmd("AT", &pStr, WNC_TIMEOUT_MS);
JMF 0:9d5134074d84 342 }
JMF 0:9d5134074d84 343 }