n/a

Dependencies:   C12832 mbed-http

Fork of HTTP-Python-Demo by Cambridge Hackathon

Files at this revision

API Documentation at this revision

Comitter:
BKasza
Date:
Sun Nov 26 00:22:09 2017 +0000
Parent:
2:b91140c3c3f6
Child:
4:14c774cf7ac2
Commit message:
worked last time;

Changed in this revision

config.h 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_app.json Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config.h	Sun Nov 26 00:22:09 2017 +0000
@@ -0,0 +1,6 @@
+#ifndef _CONFIG_H
+#define _CONFIG_H
+
+#define SERVERNAME "Bianca"
+
+#endif //_CONFIG_H
\ No newline at end of file
--- a/main.cpp	Fri Nov 17 16:04:17 2017 -0600
+++ b/main.cpp	Sun Nov 26 00:22:09 2017 +0000
@@ -12,19 +12,95 @@
 // from ARM Limited or its affiliates.
 //----------------------------------------------------------------------------
 #include "mbed.h"
+#include "config.h"
 #include "C12832.h"
 #include "OdinWiFiInterface.h"
 #include "http_request.h"
 
-// GLOBAL VARIABLES HERE
-
+C12832  lcd(PE_14, PE_12, PD_12, PD_11, PE_9);
+OdinWiFiInterface wifiIF;
+InterruptIn post_button(PF_2);
+InterruptIn get_put_button(PG_4);
+volatile bool post_clicked = false;
+volatile bool get_clicked = false;
+volatile bool put_clicked = false;
 
-// FUNCTION DEFINITIONS HERE
+void lcd_print(const char* message) {
+    lcd.cls();
+    lcd.locate(0, 3);
+    lcd.printf(message);
+}
 
+void send_post() {
+    post_clicked = true;
+}
+ 
+void send_get_put() {
+    get_clicked = true;
+}
 
 int main() {
 
-    // MAIN CODE HERE
+    int ret;
+    SocketAddress serverAddr;
+    
+    lcd_print("Connecting...");
+    ret = wifiIF.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
+    if (ret != 0) {
+        lcd_print("Connection error.");
+        return -1;
+    }
+    lcd_print("Successfully connected!");
+    lcd_print(wifiIF.get_mac_address());
+    wifiIF.gethostbyname(SERVERNAME, &serverAddr);
 
+    /* Enable interrupts */
+    post_button.rise(&send_post);
+    get_put_button.rise(&send_get_put);
+    
+    /* Main loop */
+    while (1) {
+        /* Post data */
+        if (post_clicked) {
+            lcd_print("post");
+            post_clicked = false;
+            NetworkInterface* netIF = &wifiIF;
+            HttpRequest* request = new HttpRequest(netIF, HTTP_POST, "http://10.25.2.152:8080");
+            request->set_header("Content-Type", "application/json");
+            const char body[] = "HelloWorld";
+            HttpResponse* response = request->send(body, strlen(body));
+            lcd_print(response->get_body_as_string().c_str());
+            delete request;
+        }
+        
+        /* Get data */
+        if (get_clicked) {
+            get_clicked = false;
+            put_clicked = true;
+            NetworkInterface* netIF = &wifiIF;
+            HttpRequest* request = new HttpRequest(netIF, HTTP_GET, "http://10.25.2.152:8080");
+            request->set_header("Content-Type", "application/json");
+            const char body[] = "{\"get\":\"request\"}";
+            HttpResponse* response = request->send(body, strlen(body));
+            lcd_print(response->get_body_as_string().c_str());
+            delete request;
+        }
+
+        wait_ms(2000);
+        
+        /* Put */
+        if (put_clicked) {
+            put_clicked = false;
+            lcd_print("put");
+            NetworkInterface* net = &wifiIF;
+            HttpRequest* request = new HttpRequest(net, HTTP_PUT, "http://10.25.2.152:8080");
+            request->set_header("Content-Type", "application/json");
+            const char body[] = "{\"put\":\"request\"}";
+            HttpResponse* response = request->send(body, strlen(body));
+            lcd_print(response->get_body_as_string().c_str());
+            delete request;
+        }
+   
+    }
 
 }
--- a/mbed_app.json	Fri Nov 17 16:04:17 2017 -0600
+++ b/mbed_app.json	Sun Nov 26 00:22:09 2017 +0000
@@ -2,11 +2,11 @@
     "config": {
         "wifi-ssid": {
             "help": "WiFi SSID",
-            "value": "\"SSID\""
+            "value": "\"ht\""
         },
         "wifi-password": {
             "help": "WiFi Password",
-            "value": "\"PASSWORD\""
+            "value": "\"mb3dcl0ud\""
         }
     },
     "target_overrides": {