tempcommit 13/05

Files at this revision

API Documentation at this revision

Comitter:
tijl
Date:
Wed May 15 13:39:22 2019 +0000
Parent:
1:63664175e603
Commit message:
blub 15/05;

Changed in this revision

Esp8266.cpp Show annotated file Show diff for this revision Revisions of this file
Esp8266.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
--- a/Esp8266.cpp	Mon May 13 13:59:19 2019 +0000
+++ b/Esp8266.cpp	Wed May 15 13:39:22 2019 +0000
@@ -41,7 +41,7 @@
     while(processed == false);
 }
 
-string Esp8266::getRequest(const char* TCPorUDP, const char* Server, int Port, const char* ConnectionString) {
+string Esp8266::getRequest(const char* TCPorUDP, const char* Server, int Port, const char* ConnectionString, bool stayAlive) {
     bool processed = false;
     do {
         processed = parser->send("AT+CIPSTART=\"%s\",\"%s\",%d", TCPorUDP, Server, Port) && parser->recv("OK");
@@ -60,8 +60,9 @@
     while(processed == false);
 
     parser->send("%s", con.c_str());
-
-    closeConnection();
+    if(!stayAlive) {
+        closeConnection();
+    }
     return getJsonString();
 }
 
@@ -82,7 +83,7 @@
 
     while(1) {
         presentChar = (char)parser->getc();
-
+        
         if(presentChar == '{' && previousChar == '[') {
             startOfJSON = true;
         }
--- a/Esp8266.h	Mon May 13 13:59:19 2019 +0000
+++ b/Esp8266.h	Wed May 15 13:39:22 2019 +0000
@@ -9,7 +9,7 @@
     public:
         explicit Esp8266(PinName TX, PinName RX, int BaudRate, PinName ResetPin, PinName ChipSelect);
         void connectToAP(const char* SSID, const char* Password);
-        std::string getRequest(const char* TCPorUDP, const char* Server, int Port, const char* ConnectionString);
+        std::string getRequest(const char* TCPorUDP, const char* Server, int Port, const char* ConnectionString, bool stayAlive);
         void setModuleMode(int Mode);
         std::vector<std::string> processJsonString(std::string response);
     private:
--- a/main.cpp	Mon May 13 13:59:19 2019 +0000
+++ b/main.cpp	Wed May 15 13:39:22 2019 +0000
@@ -325,7 +325,12 @@
         char str_uur[10];
         memset(&str_uur, 0, sizeof(str_uur)); // zero out the buffer
         sprintf(str_uur, "%d", uur);
-        paint.DrawStringAt(x, y, str_uur,&Font20, 0);
+        if(uur <= 9) {
+            paint.DrawStringAt(x+15, y, str_uur,&Font20, 0);
+        } else {
+            paint.DrawStringAt(x, y, str_uur,&Font20, 0);
+        }
+
         paint.DrawHorizontalLine(x+38, y+8, 270, 0);
         y += 30;
     }
@@ -357,14 +362,18 @@
     //TEXT OP RECTANGLE
     string strLijn1 = vak;
     string strLijn2 = prof;
-    string strLijn3 = klas + " " + comments;    
+    string strLijn3 = klas;
+    string strLijn4 = comments;
     paint.DrawStringAt(links+1, boven+1, strLijn1.c_str(),&Font12, 1);
-    if(onder - boven >= 30) {
+    if(onder - boven >= 28) {
         paint.DrawStringAt(links+1, boven+15, strLijn2.c_str(),&Font12, 1);
     }
-    if(onder - boven >= 45) {
+    if(onder - boven >= 41) {
         paint.DrawStringAt(links+1, boven+30, strLijn3.c_str(),&Font12, 1);
     }
+    if(onder - boven >= 54) {
+        paint.DrawStringAt(links+1, boven+45, strLijn4.c_str(),&Font12, 1);
+    }
 }
 
 int main()
@@ -377,32 +386,59 @@
     drawLayout(paint);
     //WIFI
     pc.baud(9600);
+    int swichdays = 0;
+    string jsonString;
     wifi = new Esp8266(D1, D0, 9600, A3, D10);
+    
     while(1) {
+        printf("wifi connect\n\r", 0);
         wifi->setModuleMode(1);
         wifi->connectToAP("test", "password");
-        string jsonString = wifi->getRequest("TCP", "translini.be", 80, "/eink/?mbed=1&month=5&day=15");
-        vector<string> dataStrings = wifi->processJsonString(jsonString);
-        //drawLayout(Paint p);
-
-        vector<Shed> sheds;
-        for(int i = 0; i < (int)dataStrings.size(); i++) {
-            sheds.push_back(Shed(dataStrings[i]));
+        printf("wifi connected\n\r", 0);
+        if(swichdays == 0) {
+            jsonString = wifi->getRequest("TCP", "translini.be", 80, "/eink/?mbed=1&month=5&day=15", 0);
+        } else if(swichdays < 10) {
+            printf("update?\n\r", 0);
+            jsonString = wifi->getRequest("TCP", "translini.be", 80, "/eink/?mbed=1&month=5&day=15&update=1", 1);
+            if(jsonString == "{1}]") {
+                printf("update!\n\r", 0);
+                jsonString = wifi->getRequest("TCP", "translini.be", 80, "/eink/?mbed=1&month=5&day=15", 0);
+                printf("new data!\n\r", 0);
+            } else {
+                printf("no update!\n\r", 0);
+                jsonString = "";
+            }
+        } else if (swichdays == 10) {
+            jsonString = wifi->getRequest("TCP", "translini.be", 80, "/eink/?mbed=1&month=5&day=16", 0);
+        } else if(swichdays < 20) {
+            jsonString = wifi->getRequest("TCP", "translini.be", 80, "/eink/?mbed=1&month=5&day=16&update=1", 1);
+            if(jsonString == "{1}]") {
+                jsonString = wifi->getRequest("TCP", "translini.be", 80, "/eink/?mbed=1&month=5&day=16", 0);
+            } else {
+                jsonString = "";
+            }
+        } else {
+            swichdays = -1;
         }
-        for(int i = 0; i < ((int)sheds.size()); i++) {
-            /*
-            printf("Lokaal: %s\r\n", sheds[i].getLokaal().c_str());
-            printf("Startuur: %s\r\n", (sheds[i].getStart()->getDatetime()).c_str());
-            printf("Einduur: %s\r\n", (sheds[i].getEinde()->getDatetime()).c_str());
-            printf("Prof: %s\r\n", sheds[i].getProf().c_str());
-            printf("Klasgroep: %s\r\n", sheds[i].getKlasgroep().c_str());
-            printf("Vak: %s\r\n", sheds[i].getVak().c_str());
-            printf("Comments: %s\r\n\r\n", sheds[i].getComments().c_str());*/
-            drawLesblok(sheds[i],paint);
+        
+        if(jsonString != "") {
+            vector<string> dataStrings = wifi->processJsonString(jsonString);
+            vector<Shed> sheds;
+            for(int i = 0; i < (int)dataStrings.size(); i++) {
+                sheds.push_back(Shed(dataStrings[i]));
+            }
+            for(int i = 0; i < ((int)sheds.size()); i++) {
+                drawLesblok(sheds[i],paint);
+            }
+            //drawLayout(p);
+            epd.DisplayFrame(NULL,img);
         }
-        epd.DisplayFrame(NULL,img);
         epd.Sleep();
+        swichdays++;
+        printf("swichdays staat op %d\n\r", swichdays);
+        printf("jsonString staat op %s\n\r", jsonString);
         pc.printf("\r\n\r\n");
-        wait(60);
+        wait(10);
+        printf("na wait\n\r", 0);
     }
 }