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: TextLCD MbedJSONValue libMotiv picojson mbed-rtos mbed
Fork of Mbed_MotiVControllerBox by
Diff: main.cpp
- Revision:
- 2:ad4509a9d051
- Parent:
- 1:d54aed10ddf3
- Child:
- 3:21c8adb97c8f
diff -r d54aed10ddf3 -r ad4509a9d051 main.cpp
--- a/main.cpp Sat Nov 15 13:04:09 2014 +0000
+++ b/main.cpp Tue Dec 02 20:51:18 2014 +0000
@@ -3,7 +3,8 @@
#include "TextLCD/TextLCD.h"
#include "Controller.h"
#include "EthernetInterface.h"
-#include "SDFileSystem.h"
+#include "HTTPClient.h"
+//#include "SDFileSystem.h" Needed if config files are going to be implemented
#include <string>
/*****************
@@ -23,7 +24,11 @@
//Comms
Serial pc(USBTX, USBRX); //tx, rx
Serial rfd(p9, p10); //tx, rx
+
+//TODO: Should be the responsibility of Controller
EthernetInterface eth;
+HTTPClient http;
+char str[512];
//Storage
//SD card
@@ -44,13 +49,14 @@
void setup(); //Called once to setup
void runProgram(); //Program with loop
+
/****************
MAIN
*****************/
int main()
{
setup();
-
+ c.lcd->cls();
//the LCD is cleared using function .cls()
lcd.cls();
@@ -73,42 +79,39 @@
//Initialize Ethernet
eth.init();
eth.connect();
+ wait_ms(200);
}
void runProgram()
{
- c.lcd->cls();
+
c.lcd->locate(0,0);
c.displayStatus();
// c.printDesc(1);
string ip = eth.getIPAddress();
- c.setStatus(Controller::READY);
-
- UDPSocket sock;
- sock.init();
-
- Endpoint nist;
- nist.set_address("utcnist.colorado.edu", 37);
-
- char out_buffer[] = "plop"; // Does not matter
- sock.sendTo(nist, out_buffer, sizeof(out_buffer));
-
- char in_buffer[4];
- int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer));
-
- unsigned int timeRes = ntohl( *((unsigned int*)in_buffer));
- pc.printf("Received %d bytes from server %s on port %d: %u seconds since 1/01/1900 00:00 GMT\n", n, nist.get_address(), nist.get_port(), timeRes);
-
- sock.close();
+ string mStr = "IP: " + ip + "\r\n";
+ c.lcdWriteLine(3, mStr);
+ pc.printf("%s", ip);
+//
- pc.printf("%s", ip);
+ //GET data
+ printf("\nTrying to fetch page...\r\n");
+ int ret = http.get("http://core.motiv.jvanbaarsen.com/v1/tables/7", str, 128);
+ if (!ret)
+ {
+ printf("Page fetched successfully - read %d characters\r\n", strlen(str));
+ printf("Result: %s\r\n", str);
+ c.lcdWriteLine(1, str);
+ }
+ else
+ {
+ printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+ }
-// c.writeLine(3, ("IP: " + ipa));
- c.lcd->locate(0,3);
- c.lcd->clearLine();
- c.lcd->locate(0,3);
- c.lcd->printf("IP: %s", ip);
+
+ c.setStatus(Controller::READY);
+ pc.printf("Controller ready\r\n");
//Reset flower
rfd.putc(2);
@@ -149,7 +152,7 @@
counter--;
} else if(Up)
pushedUp = false;
- else if(Down)
+ else if(Down)
pushedDown = false;
if(counter != counterLast) {
@@ -215,7 +218,7 @@
break;
}
counterLast = counter;
- c.lcdWriteLine(2, str);
+ c.lcdWriteLine(2, str);
}
@@ -229,23 +232,23 @@
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
-
+
UDPSocket sock;
sock.init();
-
+
Endpoint nist;
nist.set_address("utcnist.colorado.edu", 37);
-
+
char out_buffer[] = "plop"; // Does not matter
sock.sendTo(nist, out_buffer, sizeof(out_buffer));
-
+
char in_buffer[4];
int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer));
-
+
unsigned int timeRes = ntohl( *((unsigned int*)in_buffer));
printf("Received %d bytes from server %s on port %d: %u seconds since 1/01/1900 00:00 GMT\n", n, nist.get_address(), nist.get_port(), timeRes);
-
+
sock.close();
-
+
eth.disconnect();
*/
\ No newline at end of file
