Demo for Mbed Connect Cloud board and an HTTP Python Server

Dependencies:   C12832 mbed-http

View the tutorial for this demo here.

Files at this revision

API Documentation at this revision

Comitter:
Jenny Plunkett
Date:
Tue Nov 14 14:26:53 2017 -0600
Child:
1:36c5989d5636
Commit message:
Blank program (with working/ code) for tutorial

Changed in this revision

.mbed Show annotated file Show diff for this revision Revisions of this file
C12832.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-http.lib Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib 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
mbed_settings.py Show annotated file Show diff for this revision Revisions of this file
server/server.py Show annotated file Show diff for this revision Revisions of this file
working/main_working.h Show annotated file Show diff for this revision Revisions of this file
working/server_working.py Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.mbed	Tue Nov 14 14:26:53 2017 -0600
@@ -0,0 +1,2 @@
+TARGET=UBLOX_EVK_ODIN_W2
+TOOLCHAIN=GCC_ARM
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Tue Nov 14 14:26:53 2017 -0600
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/chris/code/C12832/#7de323fa46fe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 14 14:26:53 2017 -0600
@@ -0,0 +1,30 @@
+//----------------------------------------------------------------------------
+// The confidential and proprietary information contained in this file may
+// only be used by a person authorised under and to the extent permitted
+// by a subsisting licensing agreement from ARM Limited or its affiliates.
+//
+// (C) COPYRIGHT 2016 ARM Limited or its affiliates.
+// ALL RIGHTS RESERVED
+//
+// This entire notice must be reproduced on all copies of this file
+// and copies of this file may only be made by a person if such person is
+// permitted to do so under the terms of a subsisting license agreement
+// from ARM Limited or its affiliates.
+//----------------------------------------------------------------------------
+#include "mbed.h"
+#include "C12832.h"
+#include "OdinWiFiInterface.h"
+#include "http_request.h"
+
+// GLOBAL VARIABLES HERE
+
+
+// FUNCTION DEFINTIONS HERE
+
+
+int main() {
+
+    // MAIN CODE HERE
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-http.lib	Tue Nov 14 14:26:53 2017 -0600
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/sandbox/code/mbed-http/#3004056e4661
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Tue Nov 14 14:26:53 2017 -0600
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#78474a5129e18e136cc7e872adbaa5b74fbb8f6a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Tue Nov 14 14:26:53 2017 -0600
@@ -0,0 +1,20 @@
+{
+    "config": {
+        "wifi-ssid": {
+            "help": "WiFi SSID",
+            "value": "\"SSID\""
+        },
+        "wifi-password": {
+            "help": "WiFi Password",
+            "value": "\"PASSWORD\""
+        }
+    },
+    "target_overrides": {
+        "*": {
+            "platform.stdio-convert-newlines": true
+        },
+        "UBLOX_EVK_ODIN_W2": {
+            "target.device_has": ["EMAC"]
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_settings.py	Tue Nov 14 14:26:53 2017 -0600
@@ -0,0 +1,45 @@
+"""
+mbed SDK
+Copyright (c) 2016 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+
+from os.path import join, abspath, dirname
+
+#ROOT = abspath(join(dirname(__file__), "."))
+
+##############################################################################
+# Build System Settings
+##############################################################################
+#BUILD_DIR = abspath(join(ROOT, "build"))
+
+# ARM
+#ARM_PATH = "C:/Program Files/ARM"
+
+# GCC ARM
+#GCC_ARM_PATH = ""
+
+# GCC CodeRed
+#GCC_CR_PATH = "C:/code_red/RedSuite_4.2.0_349/redsuite/Tools/bin"
+
+# IAR
+#IAR_PATH = "C:/Program Files (x86)/IAR Systems/Embedded Workbench 7.0/arm"
+
+# Goanna static analyser. Please overload it in private_settings.py
+#GOANNA_PATH = "c:/Program Files (x86)/RedLizards/Goanna Central 3.2.3/bin"
+
+#BUILD_OPTIONS = []
+
+# mbed.org username
+#MBED_ORG_USER = ""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/server.py	Tue Nov 14 14:26:53 2017 -0600
@@ -0,0 +1,18 @@
+from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
+import SocketServer
+import socket
+
+class MyHandler(BaseHTTPRequestHandler):
+
+    # HTTP REQUESTS HERE
+
+
+
+def run():
+    httpd = HTTPServer(('', 8080), MyHandler)
+    print "HTTP server running on port 8080"
+    print "Your IP address is: ", socket.gethostbyname(socket.gethostname())
+    httpd.serve_forever()
+
+if __name__ == '__main__':
+    run()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/working/main_working.h	Tue Nov 14 14:26:53 2017 -0600
@@ -0,0 +1,102 @@
+//----------------------------------------------------------------------------
+// The confidential and proprietary information contained in this file may
+// only be used by a person authorised under and to the extent permitted
+// by a subsisting licensing agreement from ARM Limited or its affiliates.
+//
+// (C) COPYRIGHT 2016 ARM Limited or its affiliates.
+// ALL RIGHTS RESERVED
+//
+// This entire notice must be reproduced on all copies of this file
+// and copies of this file may only be made by a person if such person is
+// permitted to do so under the terms of a subsisting license agreement
+// from ARM Limited or its affiliates.
+//----------------------------------------------------------------------------
+#include "mbed.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 wifi;
+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 DEFINTIONS 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
+
+    lcd_print("Connecting...");
+    int ret = wifi.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!");
+
+    post_button.rise(&send_post);
+    get_put_button.rise(&send_get_put);
+
+    while (true) {
+
+        // WHILE LOOP CODE HERE
+
+        if (post_clicked) {
+            post_clicked = false;
+            NetworkInterface* net = &wifi;
+            HttpRequest* request = new HttpRequest(net, HTTP_POST, "http://IP_ADDRESS_HERE:8080");
+            request->set_header("Content-Type", "application/json");
+            const char body[] = "{\"post\":\"request\"}";
+            HttpResponse* response = request->send(body, strlen(body));
+            lcd_print(response->get_body_as_string().c_str());
+            delete request;
+        }
+
+        if (get_clicked) {
+            get_clicked = false;
+            put_clicked = true;
+            NetworkInterface* net = &wifi;
+            HttpRequest* request = new HttpRequest(net, HTTP_GET, "http://IP_ADDRESS_HERE: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);
+
+        if (put_clicked) {
+            put_clicked = false;
+            NetworkInterface* net = &wifi;
+            HttpRequest* request = new HttpRequest(net, HTTP_PUT, "http://IP_ADDRESS_HERE: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;
+        }
+
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/working/server_working.py	Tue Nov 14 14:26:53 2017 -0600
@@ -0,0 +1,43 @@
+from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
+import SocketServer
+import socket
+
+class MyHandler(BaseHTTPRequestHandler):
+
+    # HTTP REQUESTS HERE
+
+    def do_POST(self):
+        content = b"POST: Hello, Mbed!"
+        self.send_response(200)
+        self.send_header('Content-type', 'text/plain')
+        self.send_header('Content-Length', len(content))
+        self.end_headers()
+        self.wfile.write(content)
+        return
+
+    def do_GET(self):
+        content = b"GET: Hello, Mbed!"
+        self.send_response(200)
+        self.send_header('Content-type', 'text/plain')
+        self.send_header('Content-Length', len(content))
+        self.end_headers()
+        self.wfile.write(content)
+        return
+
+    def do_PUT(self):
+        content = b"PUT: Hello, Mbed!"
+        self.send_response(200)
+        self.send_header('Content-type', 'text/plain')
+        self.send_header('Content-Length', len(content))
+        self.end_headers()
+        self.wfile.write(content)
+        return
+
+def run():
+    httpd = HTTPServer(('', 8080), MyHandler)
+    print "HTTP server running on port 8080"
+    print "Your IP address is: ", socket.gethostbyname(socket.gethostname())
+    httpd.serve_forever()
+
+if __name__ == '__main__':
+    run()