https://www.youtube.com/watch?v=FnNo10FYSTE

Dependencies:   DISCO_L475VG_IOT01A_wifi

Files at this revision

API Documentation at this revision

Comitter:
hexfactory
Date:
Wed Nov 20 15:22:41 2019 +0000
Commit message:
add WOL-WIFI project

Changed in this revision

DISCO_L475VG_IOT01A_wifi.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 d4bf65e1d0d7 DISCO_L475VG_IOT01A_wifi.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DISCO_L475VG_IOT01A_wifi.lib	Wed Nov 20 15:22:41 2019 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/DISCO_L475VG_IOT01A_wifi/#c61a93635433
diff -r 000000000000 -r d4bf65e1d0d7 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 20 15:22:41 2019 +0000
@@ -0,0 +1,106 @@
+#include "mbed.h"
+#include "wifi.h"
+/*------------------------------------------------------------------------------
+Hyperterminal settings: 115200 bauds, 8-bit data, no parity
+
+This example 
+  - connects to a wifi network (SSID & PWD to set in mbed_app.json)
+  - Connects to a TCP server (set the address in RemoteIP)
+  - Sends "Hello" to the server when data is received
+
+This example uses SPI3 ( PE_0 PC_10 PC_12 PC_11), wifi_wakeup pin (PB_13), 
+wifi_dataready pin (PE_1), wifi reset pin (PE_8)
+------------------------------------------------------------------------------*/
+
+/* Private defines -----------------------------------------------------------*/
+#define WIFI_WRITE_TIMEOUT 10000
+#define WIFI_READ_TIMEOUT  10000
+#define CONNECTION_TRIAL_MAX          10
+
+/* Private typedef------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+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;
+uint8_t TxData[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75,
+                    0x40, 0x8D, 0x5C, 0x1E, 0x3B, 0x75};
+uint16_t RxLen;
+uint8_t  MAC_Addr[6]; 
+uint8_t  IP_Addr[4]; 
+
+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:8002 ...\n",     
+                       RemoteIP[0],
+                       RemoteIP[1],
+                       RemoteIP[2],
+                       RemoteIP[3]);
+        
+                if( WIFI_OpenClientConnection(0, WIFI_UDP_PROTOCOL, "UDP_WOL", RemoteIP, 8002, 0) == WIFI_STATUS_OK){
+                    printf("> UDP configured successfully.\n"); 
+                    Socket = 0;
+                }
+            } 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"); 
+    }
+  
+    if(WIFI_SendData(Socket, TxData, sizeof(TxData), &Datalen, WIFI_WRITE_TIMEOUT) != WIFI_STATUS_OK) {
+        printf("> ERROR : Failed to send Data.\n");   
+    } else {
+        printf("> WOL packet sent\n");  
+    }
+
+}
diff -r 000000000000 -r d4bf65e1d0d7 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Nov 20 15:22:41 2019 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#4c256f04596179699c4f14b6863b07cc024ca9be
diff -r 000000000000 -r d4bf65e1d0d7 mbed_app.json
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Wed Nov 20 15:22:41 2019 +0000
@@ -0,0 +1,28 @@
+{
+    "config": {
+        "wifi-ssid": {
+            "help": "WiFi SSID",
+            "value": "\"wifi name""
+        },
+        "wifi-password": {
+            "help": "WiFi Password",
+            "value": "\"xxxxxxxxxxxxxxxxxxxxxx\""
+        },
+        "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": "66"
+        },
+        "server-ip-4": {
+            "help": "TCP server IP address 4th value",
+            "value": "255"
+        }
+    }
+}
\ No newline at end of file