Example application to connect the DISCO_F746NG board to thethings.iO

Dependencies:   BSP_DISCO_F746NG F7_Ethernet LCD_DISCO_F746NG NetworkAPI TS_DISCO_F746NG ThethingsiO_DISCO_F746NG mbed-dev mbed-rtos

Fork of TCP_Client_Example by Roy van Dam

Revision:
13:385d1df93acc
Parent:
11:f4d618b8141f
Child:
15:2bfdb6eab519
--- a/main.cpp	Sat Nov 15 21:37:01 2014 +0000
+++ b/main.cpp	Tue Sep 06 08:44:51 2016 +0000
@@ -1,45 +1,65 @@
-#include "mbed.h"
-#include "EthernetInterface.h"
+#include "TS_DISCO_F746NG.h"
+#include "LCD_DISCO_F746NG.h"
+#include "ThethingsiO_DISCO_F746NG.h"
+
+int result;
 
-#include "NetworkAPI/buffer.hpp"
-#include "NetworkAPI/ip/address.hpp"
-#include "NetworkAPI/tcp/socket.hpp"
+LCD_DISCO_F746NG lcd;
+TS_DISCO_F746NG ts;
 
-int
-main()
+int touched_left, touched_right ;
+stringstream temp_string;
+
+int main()
 {
-    EthernetInterface interface;
-    interface.init();
-    interface.connect();
-    printf("IP Address is %s\n\r", interface.getIPAddress());
-  
-    int result;
-  
-    network::tcp::Socket socket;
-    network::Buffer buffer(256);
-    std::string request("GET /media/uploads/donatien/hello.txt HTTP/1.1\r\nHost: %s\r\n\r\n");
-    
-    if (socket.open() < 0) {
-        printf("Failed to open TCP Socket\n\r");
-        return -1;
+    ThethingsiO_DISCO_F746NG thethings = ThethingsiO_DISCO_F746NG::ThethingsiO_DISCO_F746NG("HQ0dPZ1MGCbhE6gGtZMk7w8s80Dtjf0VtiWKghbTYSw");
+    //printf("IP Address is %s\n\r", interface.getIPAddress());
+    TS_StateTypeDef TS_State;
+    uint16_t x, y, x_ant, y_ant;
+
+    touched_left = touched_right = 0;
+    lcd.Clear(LCD_COLOR_BLACK);
+
+    lcd.SetTextColor(LCD_COLOR_RED);
+    lcd.DrawCircle(160, 136, 50);
+    wait(0.1);
+    lcd.SetTextColor(LCD_COLOR_RED);
+    lcd.FillCircle(160, 136, 50);
+    wait(1);
+    lcd.SetTextColor(LCD_COLOR_GREEN);
+    lcd.DrawCircle(320, 136, 50);
+    wait(0.1);
+    lcd.SetTextColor(LCD_COLOR_GREEN);
+    lcd.FillCircle(320, 136, 50);
+    wait(1);
+    ts.Init(lcd.GetXSize(), lcd.GetYSize());
+    wait(3);
+
+    lcd.SetBackColor(LCD_COLOR_BLACK);
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    printf("\r\n");
+    while (1) {
+        ts.GetState(&TS_State);
+        if (TS_State.touchDetected) {
+            x = TS_State.touchX[0];
+            y = TS_State.touchY[0];
+            if ((x_ant != x) && (y_ant != y)) {
+                if ((x >= 110 && x <= 210)&&(y >= 86 && y <= 186)) {
+                    touched_left++;
+                    temp_string.str("");
+                    temp_string << touched_left;
+                    lcd.DisplayStringAt(400, LINE(1), (uint8_t *)temp_string.str().c_str(), CENTER_MODE);
+                    thethings.thingWrite("demo", "1");
+                } else if ((x >= 270 && x <= 370)&&(y >= 86 && y <= 186)) {
+                    touched_right++;
+                    temp_string.str("");
+                    temp_string << touched_right;
+                    lcd.DisplayStringAt(110, LINE(1), (uint8_t *)temp_string.str().c_str(), CENTER_MODE);
+                    thethings.thingWrite("demo", "2");
+                }
+            }
+            x_ant = x;
+            y_ant = y;
+        }
     }
-    
-    if (socket.connect("mbed.org", 80) < 0) {
-        printf("Failed to connect with mbed.org\n\r");
-        return -1;
-    }
-    
-    if (socket.write((void *)request.data(), request.size()) < 0) {
-        printf("Failed to write HTTP request\n\r");
-        return -1;
-    }
-    
-    do
-    {
-        result = socket.read(buffer);   
-        printf("Received %d bytes:\n\r%s\n\r", result, (char *)buffer.data());
-    } while(result > 0);
-    
-    socket.close();
-    return 0;
 }
\ No newline at end of file