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.
Dependencies: GPSLibrary GSM mbed-modifed Storage_Library Temp_Library Wakeup pH_Sensor
Revision 12:973566676eba, committed 2015-11-30
- Comitter:
- ptcrews
- Date:
- Mon Nov 30 21:07:03 2015 +0000
- Parent:
- 11:cc22917d6634
- Child:
- 13:52fba498c00d
- Commit message:
- Mostly works. Need to fix fona power up/down.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 18 21:36:49 2015 +0000
+++ b/main.cpp Mon Nov 30 21:07:03 2015 +0000
@@ -14,6 +14,7 @@
// Global Positioning System constants
#define GPS_TX D6
#define GPS_RX PB_11
+#define GPS_EN D7
// pH sensor constants
#define PH_TX PC_10
@@ -24,7 +25,7 @@
AnalogIn temperature(TMP_ANALOG);
#define READINGSIZE sizeof(struct reading)
-#define URL "http://requestb.in/17asutd1"
+#define URL "http://requestb.in/sd2o2gsd"
// Cellular communication global variables
Adafruit_FONA fona(FONA_TX, FONA_RX, FONA_RST, FONA_RI);
@@ -49,6 +50,7 @@
const int refresh_Time = 2000; //refresh time in ms
Serial gps_Serial(GPS_TX, GPS_RX); // Serial object for GPS
Adafruit_GPS myGPS(&gps_Serial);
+DigitalOut gpsEN(GPS_EN);
// pH sensor global variables
Serial ph_Serial (PH_TX, PH_RX);
@@ -80,6 +82,7 @@
}
void setupGPS() {
+ gpsEN.write(1);
myGPS.begin(9600);
myGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //these commands are defined in MBed_Adafruit_GPS.h; a link is provided there for command creation
myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
@@ -92,8 +95,8 @@
void setup() {
printf("\n=====\nSetup in Full Project\n");
setupPCSerial();
+ setupGPS();
setupPH();
- setupGPS();
}
// Send default message to pH sensor, asking for data.
@@ -106,6 +109,7 @@
}
void pHRead() {
+ pHRequest();
printf("Reading pH information.\n");
if (ph_Serial.readable() > 0) { //if we see that the Atlas Scientific product has sent a character.
printf("Receiving sensor string... [");
@@ -140,6 +144,10 @@
// n_queries is the number of times we query the GPS. We need something like 23000 characters.
void GPSRead(int n_queries) {
+ for(int i = 0; i < 20; i++){
+ wait(1);
+ if(myGPS.fix) break;
+ }
pcSerial.printf("\n");
for (int i = 0; i < n_queries; i++) {
c = myGPS.read(); //queries the GPS
@@ -198,7 +206,7 @@
}
fona.begin(9600);
printf("After begin\n");
- fona.setGPRSNetworkSettings("fast.t-mobile.com", "", "");
+ fona.setGPRSNetworkSettings("pwg", "", "");
printf("After set setting\n");
bool enable = false;
while(enable != true) {
@@ -207,6 +215,7 @@
enable = fona.enableGPRS(true);
}
printf("After enable\n");
+ key.write(1);
}
void changeGSMPowerState()
@@ -229,9 +238,11 @@
void enterSleep(int msec)
{
+ gpsEN.write(0);
if(msec > 0) WakeUp::set_ms(msec);
deepsleep();
resetADC();
+ gpsEN.write(1);
}
bool sendDataOverHTTP(char* url, uint8_t* data, int dlength)
@@ -366,7 +377,6 @@
bool toSend = false;
while (true) {
printf("~~~~~[pH]~~~~~\n");
- pHRequest();
pHRead();
lastReadingBuffer.pH = pH;
wait(1);
@@ -378,7 +388,7 @@
wait(1);
writeEEPROMbytes((uint8_t *) &lastReadingBuffer, READINGSIZE);
nreadings++;
- if(nreadings == 1)
+ if(nreadings == 10)
toSend = true;
if(toSend) {
struct reading* data = new struct reading[nreadings];
@@ -402,6 +412,7 @@
}
delete[] data;
}
+ //else changeGSMPowerState();
/*
printf("Reading Size is %d\n", READINGSIZE);
printf("ROM Latitude: %f\n", verifier.latitude);
@@ -414,8 +425,9 @@
printf("ROM Hour: %d\n", verifier.hour);
printf("ROM Minutes: %d\n", verifier.minutes);
*/
- wait(2);
- enterSleep(10000);
+ wait(1);
+ key.write(1);
+ enterSleep(360000);
}
return 0;