Network Enabled Hardware Development

Dependencies:   DISCO_L475VG_IOT01A_wifi VL53L0X BSP_B-L475E-IOT01

Files at this revision

API Documentation at this revision

Comitter:
abdulh
Date:
Sun Apr 19 00:29:14 2020 +0000
Commit message:
Project for Class

Changed in this revision

BSP_B-L475E-IOT01.lib Show annotated file Show diff for this revision Revisions of this file
DISCO_L475VG_IOT01A_wifi.lib Show annotated file Show diff for this revision Revisions of this file
VL53L0X.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-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
diff -r 000000000000 -r 98a1923c15fb BSP_B-L475E-IOT01.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP_B-L475E-IOT01.lib	Sun Apr 19 00:29:14 2020 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/ST/code/BSP_B-L475E-IOT01/#bfe8272ced90
diff -r 000000000000 -r 98a1923c15fb DISCO_L475VG_IOT01A_wifi.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DISCO_L475VG_IOT01A_wifi.lib	Sun Apr 19 00:29:14 2020 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/DISCO_L475VG_IOT01A_wifi/#c61a93635433
diff -r 000000000000 -r 98a1923c15fb VL53L0X.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VL53L0X.lib	Sun Apr 19 00:29:14 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ST/code/VL53L0X/#e9269ff624ed
diff -r 000000000000 -r 98a1923c15fb main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Apr 19 00:29:14 2020 +0000
@@ -0,0 +1,175 @@
+#include "mbed.h"
+#include "wifi.h"
+// Sensors drivers present in the BSP library
+#include "stm32l475e_iot01_tsensor.h"
+#include "stm32l475e_iot01_hsensor.h"
+#include "VL53L0X.h"
+
+#define WIFI_WRITE_TIMEOUT 10000
+#define WIFI_READ_TIMEOUT  10000
+#define CONNECTION_TRIAL_MAX          10
+
+Serial pc(SERIAL_TX, SERIAL_RX);
+uint8_t RemoteIP[] = {MBED_CONF_APP_SERVER_IP_1,MBED_CONF_APP_SERVER_IP_2,MBED_CONF_APP_SERVER_IP_3, MBED_CONF_APP_SERVER_IP_4};
+uint8_t RxData [500];
+char* modulename;
+uint16_t RxLen;
+uint8_t  MAC_Addr[6]; 
+uint8_t  IP_Addr[4]; 
+DigitalOut led(LED1);
+
+static DevI2C devI2c(PB_11,PB_10);
+
+
+static DigitalOut shutdown_pin(PC_6);
+static VL53L0X range(&devI2c, &shutdown_pin, PC_7);
+
+
+int main()
+{
+    int32_t Socket = -1;
+    uint16_t Datalen;
+    uint16_t Trials = CONNECTION_TRIAL_MAX;
+
+    pc.baud(115200);
+    
+    /*Initialize  WIFI module */
+    if(WIFI_Init() ==  WIFI_STATUS_OK) {
+        printf("> WIFI Module Initialized.\n");  
+        if(WIFI_GetMAC_Address(MAC_Addr) == WIFI_STATUS_OK) {
+            printf("> es-wifi module MAC Address : %X:%X:%X:%X:%X:%X\n",     
+                   MAC_Addr[0],
+                   MAC_Addr[1],
+                   MAC_Addr[2],
+                   MAC_Addr[3],
+                   MAC_Addr[4],
+                   MAC_Addr[5]);   
+        } else {
+            printf("> ERROR : CANNOT get MAC address\n");
+        }
+    
+        if( WIFI_Connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, WIFI_ECN_WPA2_PSK) == WIFI_STATUS_OK) {
+            printf("> es-wifi module connected \n");
+            if(WIFI_GetIP_Address(IP_Addr) == WIFI_STATUS_OK) {
+                printf("> es-wifi module got IP Address : %d.%d.%d.%d\n",     
+                       IP_Addr[0],
+                       IP_Addr[1],
+                       IP_Addr[2],
+                       IP_Addr[3]); 
+        
+                printf("> Trying to connect to Server: %d.%d.%d.%d:27015 ...\n",     
+                       RemoteIP[0],
+                       RemoteIP[1],
+                       RemoteIP[2],
+                       RemoteIP[3]);
+        
+                while (Trials--){ 
+                    if( WIFI_OpenClientConnection(0, WIFI_TCP_PROTOCOL, "TCP_CLIENT", RemoteIP, 27015, 0) == WIFI_STATUS_OK){
+                        printf("> TCP Connection opened successfully.\n"); 
+                        Socket = 0;
+                    }
+                }
+                if(!Trials) {
+                    printf("> ERROR : Cannot open Connection\n");
+                }
+            } else {
+                printf("> ERROR : es-wifi module CANNOT get IP address\n");
+            }
+        } else {
+            printf("> ERROR : es-wifi module NOT connected\n");
+        }
+    } else {
+        printf("> ERROR : WIFI Module cannot be initialized.\n"); 
+    }
+    
+    
+    float sensor_valuet;
+    float sensor_valueh;
+
+    printf("Start sensor init\n");
+
+    BSP_TSENSOR_Init();
+    BSP_HSENSOR_Init();
+    
+    range.init_sensor(VL53L0X_DEFAULT_ADDRESS);
+
+    int i = 0;
+    
+    while(1) {
+        printf("\nNew loop, LED1 should blink during sensor read\n");
+
+        led = 1;
+        
+        uint32_t distance;
+        int status = range.get_distance(&distance);
+        if (status == VL53L0X_ERROR_NONE) {
+            printf("VL53L0X [mm]:            %6u\r\n", distance);
+        } else {
+            printf("VL53L0X [mm]:                --\r\n");
+            distance = 0;
+        }   
+        
+        int timer = 0;
+        
+        while (distance < 150 && distance > 0)
+        {
+            int status = range.get_distance(&distance);
+            if (status == VL53L0X_ERROR_NONE) {
+                printf("VL53L0X [mm]:            %6u\r\n", distance);
+            } else {
+                printf("VL53L0X [mm]:                --\r\n");
+                distance = 0;
+            } 
+            
+            timer++;
+            i++;
+            ThisThread::sleep_for(1000);
+        }
+        
+        if (timer >= 10)
+        {
+            uint8_t data[1024] = "";
+            uint8_t  temp[50] = "";
+            
+            sprintf((char *)temp, "%d", timer);
+            strcat((char *)data, (char *)temp);
+            
+            if(Socket != -1) {
+                if(WIFI_SendData(Socket, data, sizeof(data), &Datalen, WIFI_WRITE_TIMEOUT) != WIFI_STATUS_OK) {
+                    printf("Desu\n");   
+                }
+            }  
+        }  
+        
+        if (i%60 == 0)
+        {
+            uint8_t data[1024] = "";
+            uint8_t  temp[50] = "";
+            sensor_valuet = BSP_TSENSOR_ReadTemp();
+            sensor_valueh = BSP_HSENSOR_ReadHumidity();
+            printf("\nTEMPERATURE = %.2f degC\n", sensor_valuet);
+            printf("HUMIDITY    = %.2f %%\n", sensor_valueh);
+        
+        
+            sprintf((char *)temp, "%f", sensor_valuet);
+            strcat((char *)data, (char *)temp);
+            strcat((char *)data, (char *)",");
+            sprintf((char *)temp, "%f", sensor_valueh);
+            strcat((char *)data, (char *)temp);
+        
+            printf("%s\n", data);
+        
+            if(Socket != -1) {
+                if(WIFI_SendData(Socket, data, sizeof(data), &Datalen, WIFI_WRITE_TIMEOUT) != WIFI_STATUS_OK) {
+                    printf("Desu\n");   
+                }
+            }  
+        }
+
+        led = 0;
+        
+        ThisThread::sleep_for(1000);
+        i++;
+
+    }
+}
diff -r 000000000000 -r 98a1923c15fb mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sun Apr 19 00:29:14 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#b81aeff1a3e171c6421984faa2cc18d0e35746c0
diff -r 000000000000 -r 98a1923c15fb mbed_app.json
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Sun Apr 19 00:29:14 2020 +0000
@@ -0,0 +1,28 @@
+{
+    "config": {
+        "wifi-ssid": {
+            "help": "WiFi SSID",
+            "value": "\"RogersD033\""
+        },
+        "wifi-password": {
+            "help": "WiFi Password",
+            "value": "\"62JH48327G\""
+        },
+        "server-ip-1": {
+            "help": "TCP server IP address 1st value",
+            "value": "192"
+        },
+        "server-ip-2": {
+            "help": "TCP server IP address 2nd value",
+            "value": "168"
+        },
+        "server-ip-3": {
+            "help": "TCP server IP address 3rd value",
+            "value": "0"
+        },
+        "server-ip-4": {
+            "help": "TCP server IP address 4th value",
+            "value": "102"
+        }
+    }
+}
\ No newline at end of file