A remote sensor to measure the height of a river and send the data using UDP over 3G.

Dependencies:   HTTPClient RangeFinder VodafoneUSBModem mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
NickRyder
Date:
Mon Dec 10 13:18:54 2012 +0000
Commit message:
Prototype river sensor. Measures and buffers distances and transmits them via UDP.

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
RangeFinder.lib Show annotated file Show diff for this revision Revisions of this file
VodafoneUSBModem.lib 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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a75ff778bebe HTTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Mon Dec 10 13:18:54 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#1f743885e7de
diff -r 000000000000 -r a75ff778bebe RangeFinder.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RangeFinder.lib	Mon Dec 10 13:18:54 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/NickRyder/code/RangeFinder/#cf496fb70317
diff -r 000000000000 -r a75ff778bebe VodafoneUSBModem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VodafoneUSBModem.lib	Mon Dec 10 13:18:54 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/VodafoneUSBModem/#66db9afdc3c1
diff -r 000000000000 -r a75ff778bebe main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 10 13:18:54 2012 +0000
@@ -0,0 +1,71 @@
+#include "mbed.h"
+#include "RangeFinder.h"
+#include "VodafoneUSBModem.h"
+#include "VodafoneUSBModem/Socket/UDPSocket.h"
+
+void test(void const*) {
+    set_time(0);    // really should set time over network, needed a 
+                    // set_time() or time(NULL) gave -1 for some reason
+    AnalogIn batterymonitor(p19);
+    RangeFinder rf(p21, 10, 5800.0, 100000);
+    float battery;
+    int index = 0;
+    float distances[100];
+    time_t times[100];
+    int loop = 60;
+    UDPSocket sock;
+    VodafoneUSBModem mo;
+    while(1) {
+        distances[index] = rf.read_m();
+        times[index] = time(NULL);
+        printf("%i: d = %f m, t = %d s.\n", index, distances[index], times[index]);
+        wait(1.0);
+        index++;
+        if (index == loop)   {   
+            index = 0;
+            printf("I am attempting to connect...\n");
+            int x = mo.connect("smart");
+            if (x){
+                printf("Failed to connect.\n");
+            }   else    {
+                int bound = sock.bind(87);
+                printf("Bound = %d.\n", bound);
+                Endpoint server;
+                int servercon = server.set_address("someurl.org", 2345);
+                char databuffer[512];
+                for (int i = 0; i < loop; i++)    {
+                    sprintf(databuffer, "id=mbedAA,time=%i,height=%f", times[i], distances[i]);
+                    int len = 0;
+                    for (len = 0; len < 512; len++) {
+                        if (databuffer[len] == '\0')  break;
+                    }
+                    printf("Sending: %s (%d)\n", databuffer, len);
+                    int n = sock.sendTo(server, databuffer, len);
+                    printf("Sent %i bytes.\n", n);
+                }
+                battery = batterymonitor.read() * 3.3 * 3.0;
+                printf("Battery at %f V.\n", battery);
+                sprintf(databuffer, "id=mbedAA,time=%d,battery=%f", time(NULL), battery);
+                int len;
+                for (len = 0; len < 512; len++) {
+                    if (databuffer[len] == '\0') break;
+                }
+                sock.sendTo(server, databuffer, len);
+                mo.disconnect();
+            }
+        }
+    }
+}
+
+int main()
+{
+  Thread testTask(test, NULL, osPriorityNormal, 1024 * 10);
+  DigitalOut led(LED2);
+  while(1)
+  {
+    led=!led;
+    Thread::wait(10000);  
+  }
+
+  return 0;
+}
\ No newline at end of file
diff -r 000000000000 -r a75ff778bebe mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon Dec 10 13:18:54 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#88a1a9c26ae3
diff -r 000000000000 -r a75ff778bebe mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Dec 10 13:18:54 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b60934f96c0c
\ No newline at end of file