Boiler

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
DaniusKalv
Date:
Sat Apr 09 22:02:15 2016 +0000
Commit message:
boilMe

Changed in this revision

main.cpp 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 39d9e1d04d26 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Apr 09 22:02:15 2016 +0000
@@ -0,0 +1,119 @@
+#include "mbed.h"
+#include <string>
+
+Serial pc(USBTX, USBRX);
+Serial wifi(p28,p27);
+Timer t;
+
+DigitalOut myled(LED1);
+
+int initializeWifi();
+
+void serverResponse();
+
+int main() {
+    pc.baud(115200);
+    wifi.baud(115200);
+    pc.printf("Ready to boil!\r\n");
+    initializeWifi();
+    
+    char buffer[50];
+    int bufferIndex = 0;
+    
+    while(1) {
+        
+        if(pc.readable()){
+            wifi.putc(pc.getc());
+        }
+        
+        if(wifi.readable()){
+            char c = wifi.getc();
+            pc.putc(c);
+            if (c != 10){ 
+                buffer[bufferIndex] = c;
+                bufferIndex++;
+            }
+            else{
+                if(strstr(buffer, "Alive") != NULL){
+                    pc.printf("Yayy\r\n");
+                    serverResponse();//Do the response
+                }
+                memset(buffer, 0, 50);
+                bufferIndex = 0;
+            } 
+        } 
+    }
+}
+
+int initializeWifi(){
+    t.reset();
+    t.start();
+    wifi.printf("AT+RST\r\n"); 
+    while(t.read() < 0.2){ 
+        while(wifi.readable()) pc.putc(wifi.getc());
+    }
+    t.stop();
+    wifi.printf("AT+CWJAP=\"Liutauras WiFi\",\"12345678\"\r\n");
+    t.reset();
+    t.start();
+    while(t.read() < 7){
+        while(wifi.readable()) pc.putc(wifi.getc());  
+    } 
+    t.stop();
+    t.reset();
+    wifi.printf("AT+CIFSR\r\n");
+    t.start();
+    while(t.read() < 0.2){
+        while(wifi.readable()) pc.putc(wifi.getc());  
+    }
+     
+    t.stop();
+    t.reset();
+    wifi.printf("AT+CIPMUX=1\r\n");
+    t.start();
+    while(t.read() < 0.2){
+        while(wifi.readable()) pc.putc(wifi.getc());  
+    } 
+    
+    t.stop();
+    t.reset();
+    wifi.printf("AT+CIPSERVER=1,80\r\n");
+    t.start();
+    while(t.read() < 0.2){
+        while(wifi.readable()) pc.putc(wifi.getc());  
+    }
+    return true;  
+}
+
+void serverResponse(){
+    string temp1 = "HTTP/1.1 200 OK\r\n";
+    string temp2 = "Server: SuperBoiler\r\n";
+    string temp3 = "Content-Type: application/json\r\n";
+    string temp4 = "Connection: Closed\r\n";
+    string temp5 = "\"message\":\"BoilMe\"";
+    
+    wifi.printf("AT+CIPSEND=0,%d\r\n", sizeof(temp1)+sizeof(temp2)+sizeof(temp3)+sizeof(temp4)+sizeof(temp5));
+    t.reset();
+    t.start();
+    while(t.read() < 4){
+        while(wifi.readable()) pc.putc(wifi.getc());  
+    }  
+    t.stop();
+    pc.printf("%s", temp1);
+    pc.printf("%s", temp2);
+    pc.printf("%s", temp3);
+    pc.printf("%s", temp4);
+    pc.printf("%s", temp5);
+    wifi.printf("%s", temp1);
+    wifi.printf("%s", temp2);
+    wifi.printf("%s", temp3);
+    wifi.printf("%s", temp4);
+    wifi.printf("%s", temp5);
+    
+    //wifi.printf("HTTP/1.1 200 OK\r\n");
+    //wifi.printf("Server: SuperBoiler\r\n");
+    //wifi.printf("Content-Length: 88\r\n");
+    //wifi.printf("Content-Type: application/json\r\n");
+    //wifi.printf("Connection: Closed\r\n");
+    //wifi.printf("\"message\":\"BoilMe\"");          
+}
diff -r 000000000000 -r 39d9e1d04d26 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Apr 09 22:02:15 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/99a22ba036c9
\ No newline at end of file