Basic http check

Dependencies:   HTTPClient mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
Spookmx
Date:
Tue Nov 11 21:34:37 2014 +0000
Commit message:
Ok

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.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 ce7b80583a29 EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Tue Nov 11 21:34:37 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Spookmx/code/EthernetInterface/#a79eec2afa49
diff -r 000000000000 -r ce7b80583a29 HTTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Tue Nov 11 21:34:37 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#277279a1891e
diff -r 000000000000 -r ce7b80583a29 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 11 21:34:37 2014 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "HTTPClient.h"
+
+EthernetInterface eth;
+HTTPClient http;
+char str[512];
+
+DigitalOut led_red(LED_RED);
+DigitalOut led_green(LED_GREEN);
+DigitalOut led_blue(LED_BLUE);
+Serial pc(USBTX, USBRX);
+
+void check_color(void)
+{
+    //GET data
+    printf("\nTrying to fetch page...\n");
+    int ret = http.get("http://joseromero.mx/checkColor.php", str, 128);
+    if (!ret) {
+        if(strcmp(str," RED")== 0) {
+            led_green = 1;
+            led_red = 0;
+            led_blue = 1;
+        } else if(strcmp(str," GREEN")== 0) {
+            led_green = 0;
+            led_red = 1;
+            led_blue = 1;
+        } else if(strcmp(str," BLUE")== 0) {
+            led_green = 1;
+            led_red = 1;
+            led_blue = 0;
+        } else {
+            led_green = 0;
+            led_red = 0;
+            led_blue = 1;
+        }
+        printf("Page fetched successfully - read %d characters\n", strlen(str));
+        printf("Result: %s\n", str);
+    } else {
+        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+    }
+}
+
+
+int main()
+{
+    eth.init(); //Use DHCP
+    eth.connect();
+
+    led_green = 1;
+    led_red = 1;
+    led_blue = 1;
+    pc.printf("Starting setting color.\n");
+    while (true) {
+        check_color();
+        wait(2);
+    }
+}
diff -r 000000000000 -r ce7b80583a29 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Nov 11 21:34:37 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#1be1070d822f
diff -r 000000000000 -r ce7b80583a29 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 11 21:34:37 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file