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
Diff: main.cpp
- Revision:
- 3:6afcf4f3b2aa
- Parent:
- 2:8de680cf7a19
- Child:
- 5:e180c73f4f70
--- a/main.cpp Mon Nov 02 20:24:56 2015 +0000
+++ b/main.cpp Fri Nov 06 19:22:29 2015 +0000
@@ -12,6 +12,23 @@
Serial pcSerial(USBTX, USBRX);
DigitalOut key(FONA_KEY);
+void setupGSM()
+{
+ printf("Starting FONA\n");
+ while(!fona.begin(9600)) {
+ printf("Cannot find FONA\n");
+ wait(1);
+ }
+ fona.begin(9600);
+ fona.setGPRSNetworkSettings("pwg", "", "");
+ bool enable = false;
+ while(enable != true) {
+ fona.enableGPRS(true);
+ fona.enableGPRS(false);
+ enable = fona.enableGPRS(true);
+ }
+}
+
void changeGSMPowerState()
{
key.write(0);
@@ -19,30 +36,41 @@
key.write(1);
}
-void enterSleep(int msec){
+void enterSleep(int msec)
+{
if(msec > 0) WakeUp::set_ms(msec);
deepsleep();
}
-
+
+bool sendDataOverHTTP(const char* url, const char* data)
+{
+ uint16_t statuscode;
+ int16_t length;
+ if (!fona.HTTP_POST_start(url, "text/plain", (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) {
+ pcSerial.printf("Failed!\r\n");
+ return false;
+ }
+ while (length > 0) {
+ while (fona.readable()) {
+ char c = fona.getc();
+ pcSerial.putc(c);
+ length--;
+ if (! length) break;
+ }
+ }
+ pcSerial.printf("\r\n****\r\n");
+ fona.HTTP_POST_end();
+ return true;
+}
int main()
{
- printf("Deep sleep test\n");
- // Enters deep sleep indefinitely
- enterSleep(0);
- printf("Exiting\n");
-
+
pcSerial.baud(9600);
changeGSMPowerState();
- printf("Starting FONA\n");
- while(!fona.begin(9600)) {
- printf("Cannot find FONA\n");
- wait(1);
- }
- fona.begin(9600);
- pcSerial.printf("On for 2 seconds\n");
- wait(2);
- pcSerial.printf("Turning off\n");
+ setupGSM();
+ //sendDataOverHTTP("http://requestb.in/10pbl2i1", "testing");
+
changeGSMPowerState();
return 0;