Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of AvnetATT_shape_hackathon by
Revision 41:85a736a9b900, committed 2016-10-04
- Comitter:
- elmkom
- Date:
- Tue Oct 04 20:29:31 2016 +0000
- Parent:
- 40:45e4636d20cc
- Child:
- 42:8500f0cb2ea5
- Commit message:
- Make proximity optional
Changed in this revision
| config_me.h | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/config_me.h Thu Sep 29 14:19:53 2016 +0000 +++ b/config_me.h Tue Oct 04 20:29:31 2016 +0000 @@ -6,12 +6,13 @@ // This is the server's base URL name. Example "www.google.com" // Note that when you Fork a FLOW, it will typically assign either // "run-east.att.io" or "run-west.att.io", so be sure to check this. -static const char * MY_SERVER_URL = "run-east.att.io"; - +//static const char * MY_SERVER_URL = "run-east.att.io"; +static const char * MY_SERVER_URL = "108.244.165.22"; // These are FLOW fields from the Endpoints tab: -#define FLOW_BASE_URL "/a80556051c438/f4cd2ed65f73/7ecb40fcd115f7a/in/flow" +//#define FLOW_BASE_URL "/a80556051c438/f4cd2ed65f73/7ecb40fcd115f7a/in/flow" +//#define FLOW_INPUT_NAME "/shelf" +#define FLOW_BASE_URL "" #define FLOW_INPUT_NAME "/shelf" - // Unless you want to use a different protocol, this field should be left as is: #define FLOW_URL_TYPE " HTTP/1.1\r\nHost: " @@ -33,12 +34,13 @@ #define TEMP_HUMIDITY_ACCELEROMETER 2 #define TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS 3 #define PROXIMITY_ONLY 4 +#define SWITCH_ONLY 5 static int iSensorsToReport = PROXIMITY_ONLY; //TEMP_HUMIDITY_ONLY; //modify this to change your selection // This is the APN name for the cellular network, you will need to change this, check the instructions included with your SIM card kit: static const char * MY_APN_STR = "m2m.com.attz"; //This is for normal HTTP. If you want to use TCP to a specific port, change that here: -static const char * MY_PORT_STR = "80"; +static const char * MY_PORT_STR = "5005"; #endif
--- a/main.cpp Thu Sep 29 14:19:53 2016 +0000
+++ b/main.cpp Tue Oct 04 20:29:31 2016 +0000
@@ -10,7 +10,12 @@
#include "hardware.h"
I2C i2c(PTC11, PTC10); //SDA, SCL -- define the I2C pins being used
+
+#define PROXIMITYON 0
+
+#if PROXIMITYON == 1
Proximity proximityStrip;
+#endif
// comment out the following line if color is not supported on the terminal
#define USE_COLOR
@@ -42,6 +47,8 @@
#define MUXADDRESS 0x70
#define PROXIMITYADDRESS 0x39
+
+
int mdm_dbgmask = MDM_DBG_OFF;
Serial pc(USBTX, USBRX);
@@ -59,6 +66,18 @@
DigitalOut shield_3v3_1v8_sig_trans_ena(PTC4); // 0 = disabled (all signals high impedence, 1 = translation active
DigitalOut mdm_uart1_cts(PTD0);
+
+DigitalIn slot1(PTB3,PullUp);
+DigitalIn slot2(PTB10,PullUp);
+DigitalIn slot3(PTB11,PullUp);
+//int slot1 = 0;
+//int slot2 = 1;
+//int slot3 = 1;
+int lastSlot1;
+int lastSlot2;
+int lastSlot3;
+string iccid;
+
#define TOUPPER(a) (a) //toupper(a)
const char ok_str[] = "OK";
@@ -71,7 +90,8 @@
bool proximityChange = false;
bool powerSave = false;
-
+bool toggleLed = false;
+int seqNum;
@@ -481,14 +501,26 @@
.Humidity_Si7020 = "0"
};
-void GenerateModemString(char * modem_string)
+void GenerateModemString(char * modem_string,int sensor)
{
- switch(iSensorsToReport)
+ switch(sensor)
{
+#if PROXIMITYON == 1
case PROXIMITY_ONLY:
{
+
char* data = proximityStrip.getDataStr();
- sprintf(modem_string, "GET %s%s?serial=%s&data=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, data, FLOW_URL_TYPE, MY_SERVER_URL);
+ seqNum++;
+ sprintf(modem_string, "GET %s%s?serial=%s&seq=%d&data=%s %s%s\r\n\r\n", FLOW_BASE_URL, "/shelf", iccid.c_str(), seqNum, data, FLOW_URL_TYPE, MY_SERVER_URL);
+ break;
+ }
+#endif
+ case SWITCH_ONLY:
+ {
+ char data[32];
+ sprintf(data,"[{\"p\":%d},{\"p\":%d},{\"p\":%d}]",lastSlot1*26,lastSlot2*26,lastSlot3*26);
+ seqNum++;
+ sprintf(modem_string, "GET %s%s?serial=%s&seq=%d&data=%s %s%s\r\n\r\n", FLOW_BASE_URL, "/car", iccid.c_str(), seqNum, data, FLOW_URL_TYPE, MY_SERVER_URL);
break;
}
case TEMP_HUMIDITY_ONLY:
@@ -687,10 +719,68 @@
}
}
+bool getIccid(string * iccid)
+{
+ string * respStr;
+
+ iccid->erase();
+
+ send_wnc_cmd("AT%CCID", &respStr, WNC_TIMEOUT_MS);
+
+ size_t pos = respStr->find("AT%CCID");
+ if (pos == string::npos)
+ return (false);
+
+ size_t posOK = respStr->rfind("OK");
+ if (posOK == string::npos)
+ return (false);
+
+ pos += 7; // Advanced to the number
+ *iccid = respStr->substr(pos, posOK - pos);
+
+ return (true);
+}
+
+void check_wnc(void)
+{
+ string * pRespStr;
+ send_wnc_cmd("AT", &pRespStr, WNC_TIMEOUT_MS); // Heartbeat?
+ send_wnc_cmd("ATE1", &pRespStr, WNC_TIMEOUT_MS); // Echo ON
+ string cmd_str("AT+CGDCONT=1,\"IP\",");
+ cmd_str += "\"";
+ cmd_str += MY_APN_STR;
+ cmd_str += "\"";
+
+ send_wnc_cmd(cmd_str.c_str(), &pRespStr, 2*WNC_TIMEOUT_MS); // Set APN, cmd seems to take a little longer sometimes
+ send_wnc_cmd("AT+CGACT=1,1", &pRespStr, WNC_TIMEOUT_MS);
+ send_wnc_cmd("AT+CREG?", &pRespStr, WNC_TIMEOUT_MS);
+ send_wnc_cmd("AT@INTERNET=1", &pRespStr, WNC_TIMEOUT_MS); // Internet services enabled
+ send_wnc_cmd("AT@SOCKDIAL=1", &pRespStr, WNC_TIMEOUT_MS);
+}
+
+bool checkSlots()
+{
+ bool changed = false;
+ int s1 = !slot1;
+ int s2 = !slot2;
+ int s3 = !slot3;
+ if(lastSlot1 != s1 || lastSlot2 != s2 ||lastSlot3 != s3)
+ {
+ pc.printf("slot 1 %d\r\n",s1);
+ pc.printf("slot 2 %d\r\n",s2);
+ pc.printf("slot 3 %d\r\n",s3);
+ changed = true;
+ }
+ lastSlot1 = s1;
+ lastSlot2 = s2;
+ lastSlot3 = s3;
+ return changed;
+}
+
int main() {
int i;
- int sendAttemps = 0;
+
HTS221 hts221;
pc.baud(115200);
@@ -724,7 +814,10 @@
}
} while (!i);
-
+ getIccid(&iccid);
+ printf(GRN "ICCID = %s" DEF "\r\n",iccid.c_str());
+
+ //check_wnc();
//Software init
software_init_mdm();
@@ -741,10 +834,11 @@
setTauTimer(12*60*60);
setActivityTimer(20);
setPowerSave(false);
-
- proximityStrip.init();
-
+
+#if PROXIMITYON == 1
+ proximityStrip.init();
proximityStrip.on();
+#endif
int count = 0;
// Send and receive data perpetually
@@ -754,27 +848,46 @@
//sprintf(SENSOR_DATA.Temperature, "%0.2f", CTOF(hts221.readTemperature()));
//sprintf(SENSOR_DATA.Humidity, "%02d", hts221.readHumidity());
// read_sensors(); //read available external sensors from a PMOD and the on-board motion sensor
-
- SetLedColor(0x2); //green
-
+ toggleLed = !toggleLed;
+ if(toggleLed)
+ SetLedColor(0x2); //green
+ else
+ SetLedColor(0); //off
+
+#if PROXIMITYON == 1
proximityStrip.scan();
+#else
+ bool slotsChanged = checkSlots();
+#endif
- SetLedColor(0); //off
-
- if(count >= 5*60 ||proximityStrip.changed(50))
+
+
+
+#if PROXIMITYON == 1
+ if(count >= 5*60 || proximityStrip.changed(50))
+#else
+ if(count >= 5*60 || slotsChanged)
+#endif
{
count = 0;
SetLedColor(0x04); //blue
char modem_string[512];
- GenerateModemString(&modem_string[0]);
+
+#if PROXIMITYON == 1
+ GenerateModemString(&modem_string[0],PROXIMITY_ONLY);
+#else
+ GenerateModemString(&modem_string[0],SWITCH_ONLY);
+#endif
+
printf(BLU "Sending to modem : %s" DEF "\r\n", modem_string);
wakeModem();
+ sockopen_mdm();
checkSocket();
sockwrite_mdm(modem_string);
wakeModem();
sockread_mdm(&MySocketData, 1024, 20);
-
+ sockclose_mdm();
// If any non-zero response from server, make it GREEN one-time
// then the actual FLOW responses will set the color.
if (MySocketData.length() > 0)
@@ -795,18 +908,9 @@
else
{
SetLedColor(0x1); //red
- // reset socket if read fails
- if(sendAttemps < 2)
- {
- sendAttemps++;
- sockclose_mdm();
- sockopen_mdm();
- }
- else // give up and do full reset
- {
- if(!rebootModem())
- system_reset();
- }
+ // failed to read reply try reseting modem
+ if(!rebootModem()) // if reset fails do a full software reset
+ system_reset();
}
}
