Exercises for communications. Versions for NXP FRDM K64F with not external hardware, ST NUCLEO L476RG with IDW04A1 WLAN module, ST NUCLEO L432KC with MOD WIFI ESP8266. UDP message send to and received from a smart phone app. https://os.mbed.com/docs/mbed-os/v6.3/apis/connectivity.html https://os.mbed.com/docs/mbed-os/v6.3/apis/ethernet.html https://os.mbed.com/docs/mbed-os/v6.3/apis/udpsocket.html UDP Socket: UDPSocket.open(), UDPSocket.sendto(), UDPSocket.recvfrom() The task is to make the microcontroller answer your UDP messages.
Revision 2:0783d916b348, committed 2021-12-12
- Comitter:
- timo_k2
- Date:
- Sun Dec 12 13:49:49 2021 +0000
- Parent:
- 1:76db175f3bac
- Commit message:
- Made clear that there are optional pins for the Tx transmit and Rx receive in the L432KC.
Changed in this revision
--- a/main.cpp Thu Sep 24 12:37:20 2020 +0000
+++ b/main.cpp Sun Dec 12 13:49:49 2021 +0000
@@ -4,22 +4,26 @@
***********************************
*UDP send receive example
* A microcontroller board and MOD WIFI ESP8266
- * https://os.mbed.com/docs/mbed-os/v6.3/apis/connectivity.html
- * https://os.mbed.com/docs/mbed-os/v6.3/apis/ethernet.html
- * https://os.mbed.com/docs/mbed-os/v6.2/apis/wi-fi.html
+ * https://os.mbed.com/docs/mbed-os/v6.15/apis/connectivity.html
+ * https://os.mbed.com/docs/mbed-os/v6.15/apis/ethernet.html
+ * https://os.mbed.com/docs/mbed-os/v6.15/apis/wi-fi.html
* https://os.mbed.com/teams/ESP8266/code/esp8266-driver/
* https://www.olimex.com/Products/IoT/ESP8266/MOD-WIFI-ESP8266/open-source-hardware
- * https://os.mbed.com/docs/mbed-os/v6.3/apis/udpsocket.html
+ * https://os.mbed.com/docs/mbed-os/v6.15/apis/udpsocket.html
*
* L432KC --- MOD WIFI ESP8266 from OLIMEX
* L432KC D5=PB6=UART1TX --- 3 RXD
* L432KC D4=PB7=UART1RX --- 4 TXD
+ * or
+ * L432KC D1=PA9=UART1TX --- 3 RXD
+ * L432KC D0=PA10=UART1RX --- 4 TXD
* L432KC 3V3 --- 1 3.3V
* L432KC GND --- 2 GND
*
* UDP Send Receive App on smart phone needed for testing
+ * https://play.google.com/store/search?q=UDP%20Sender%20Receiver
* or Windows computer with an UDP client app
- * Timo Karppinen 24.9.2020 Apache-2.0
+ * Timo Karppinen 12.12.2021 Apache-2.0
***********************************/
#include "mbed.h"
@@ -94,13 +98,14 @@
//Fields
char in_data[BUFF_SIZE];
-
+char out_data1[BUFF_SIZE] = "sensordata";
int main() {
// Setting up WLAN
printf("WiFi example\r\n\r\n");
+ ThisThread::sleep_for(500ms); // waiting for the ESP8266 to wake up.
scan_demo(&esp);
@@ -135,8 +140,13 @@
printf(" has been started.\n");
printf("The IP will be taken from the incoming message\n");
+ AnalogIn ain5(A5);
+
+
while(1) {
- ThisThread::sleep_for(50s); //It doesn't matter how long the main takes
+ sprintf(out_data1, "Input A5 value: 0x%04X\n", ain5.read_u16());
+ printf("Input A5 value: 0x%04X\n", ain5.read_u16());
+ ThisThread::sleep_for(1s); //It doesn't matter how long the main takes
}
}
@@ -158,12 +168,12 @@
void udpSend()
{
while(1){
- char out_data[BUFF_SIZE] = "demodata";
+ //char out_data[BUFF_SIZE] = "demodata";
clientUDP.set_port(REMOTE_PORT);
- serverUDP.sendto(clientUDP, out_data, sizeof(out_data));
- printf("Sending out: %s\n", out_data);
- printf("with %d" , sizeof(out_data));
+ serverUDP.sendto(clientUDP, out_data1, sizeof(out_data1));
+ printf("Sending out: %s\n", out_data1);
+ printf("with %d" , sizeof(out_data1));
printf(" data bytes in UDP datagram\n");
- ThisThread::sleep_for(5s);
+ ThisThread::sleep_for(2s);
}
}
--- a/mbed-os.lib Thu Sep 24 12:37:20 2020 +0000 +++ b/mbed-os.lib Sun Dec 12 13:49:49 2021 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#a2ada74770f043aff3e61e29d164a8e78274fcd4 +https://github.com/ARMmbed/mbed-os/#4cfbea43cabe86bc3ed7a5287cd464be7a218938
--- a/mbed_app.json Thu Sep 24 12:37:20 2020 +0000
+++ b/mbed_app.json Sun Dec 12 13:49:49 2021 +0000
@@ -2,18 +2,18 @@
"config": {
"wifi-ssid": {
"help": "WiFi SSID",
- "value": "\"XXXXX\""
+ "value": "\"xxxxx\""
},
"wifi-password": {
"help": "WiFi Password",
- "value": "\"YYYYYY\""
+ "value": "\"yyyyyyyyy\""
},
"esp-rx-pin": {
- "help": "ESP8266 module RX pin",
+ "help": "ESP8266 module Tx pin, Mc Rx PB_7 or PA_10",
"value": "PB_7"
},
"esp-tx-pin": {
- "help": "ESP8266 module TX pin",
+ "help": "ESP8266 module Rx pin, Mc Tx PB_6 or PA_9",
"value": "PB_6"
}
},
Timo Karppinen