Arduino Server-Client Communication: UDP, WiFi, and Programming Tips

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

18 Terms

1
New cards

Role of the Arduino

It acts as a Server: a device that listens for requests on a network and sends back a response.

2
New cards

Role of the mobile app

It acts as a Client: a device that sends a request to a server and waits for its response.

3
New cards

Communication model

A 'request-reply' model. The app (client) sends a 'request' (a 'knock'), and the Arduino (server) sends a 'reply' (the gas data).

4
New cards

Port 8888

The specific 'door' or 'channel' the server is listening on. It's like a doorbell for a specific service.

5
New cards

Serial.begin(9600)

The hardware serial port for debugging messages, connected to the computer via USB.

6
New cards

SoftwareSerial on pins 4 & 5

To create a virtual serial port ('walkie-talkie') to talk to the ESP WiFi module, keeping the main serial port free for debugging.

7
New cards

AT+CIOBAUD=9600 and AT+RST commands

They are AT commands used to tell the ESP WiFi module to change its speed to a more stable 9600 baud and then reset to apply the change.

8
New cards

Udp.begin(local_port)

It 'opens the door.' It tells the Arduino to start listening for UDP packets on port 8888, officially starting the server.

9
New cards

First check inside the loop

int packetSize = Udp.parsePacket(); It checks if any client has 'knocked' (sent a UDP packet). If packetSize is 0, it does nothing.

10
New cards

Math analogRead(analogInPin)*100/1024

To convert the ADC's 10-bit reading (a number from 0 to 1023) into a simple percentage (a number from 0 to 99).

11
New cards

Creating a String and converting to char[]

String is easy to build (e.g., 'Gas Level: ' + 35). char[] is the raw data format required by Udp.write() to send over the network.

12
New cards

How Arduino knows where to send reply

It uses Udp.remoteIP(), a function that automatically gets the IP address of the client that sent the last packet.

13
New cards

Postcard vs. phone call analogy

UDP (postcard): Fast, simple, 'fire-and-forget.' No guarantee of delivery. TCP (phone call): Slow, reliable, requires a connection and handshake.

14
New cards

Why UDP is a good choice

It's fast, simple, and missing one sensor reading isn't critical. The app can just ask again.

15
New cards

Hardcoding WiFi credentials problem

Solution: Use a WiFi Manager library. It creates a temporary hotspot and a web page (captive portal) to let you configure WiFi from your phone.

16
New cards

Using String class on Arduino problem

Memory fragmentation, which can lead to random, unexplained crashes over time.

17
New cards

Safer alternative to String class

Use a char[] (character array) directly with the sprintf() function to format the text safely.

18
New cards

While(true); loops problem

They are 'blocking code' that freezes the Arduino. A better solution is to use a timeout and blink an LED to give visual feedback that something is wrong.