WiFi Fundamentals

The next thing on my agenda is to try and get my head around WiFi networks. There is an almost infinite number of articles that I can read online regarding WiFi networks, and I have had a go at a few of them but often find them to be a bit beyond me.

Understandably, most articles assume a basic understanding, but it is the basic understanding that I am trying to grasp. Once I’ve got that I can move on.

Can anybody recommend an article or a web site that they have found to be useful that help you get your head around the fundamentals? I would like to avoid spending ages going down a lot of blind alleys.

where do you start from and what are you trying to understand?

for example, if you look at the OSI model - Wikipedia, is there a specific layer you want to explore?

In a sense, the wiki page highlights my dilemma, it's all rather indepth and complex.

I want to start by getting 2 esp32s sharing variables either peer to peer or via my home WiFi. And then move to more devices as a network sharing variables.

A lot of articles I have looked at assume a certain level of understanding and i end up going down the inevitable rabit hole.

I would like to find an article or site that explains the basic building blocks and I can move on as my knowledge grows.

there are two ways to go for this

  • start at the very bottom and work your way up understanding all the layers, TCP-IP, wireless communication etc

  • start at the top using high end features and libraries and work your way down, peeling the Onion one layer at a time

people with appetite for theory and concepts will go with the first approach, people who are more hands on and like to see some action will prefer the second one.

look at ESP NOWGetting Started with ESP-NOW (ESP32 with Arduino IDE) | Random Nerd Tutorials

Thanks a lot. I'll get stuck in. Probably try both options and see what suits me best.

Ian, which "arduino" are you using?
The ESP32 Devkit and ESP8266 "NodeMCU" are well supported by wifi examples in the ide

I'm using an lolin 32 lite.

I've looked at a lot of the examples hoping to learn something. Unfortunately, I don't know what most of them are doing.

If I get my head around some of the basics, I'm hoping that the examples will become clearer.

If you want to learn "Wi-Fi fundamentals" I think you're better served by ignoring Arduino completely and just learning how things work at the server/protocol level. There are many such examples at all levels of understanding. It sounds like you want to understand how to use Wi-Fi, not necessarily how all the IP layers work.

So maybe find a basic internet tutorial like 24.1. How the Internet Works — Introduction to Professional Web Development in JavaScript documentation

Then I'm guessing you may be stuck on some of the arduino web page tutorials.
This should be a good start to understand web pages: How to create dynamic HTML pages ? - GeeksforGeeks

Or maybe I'm completely wrong about what you're asking :slight_smile:

WiFi communication enables devices to connect wirelessly, facilitating seamless data exchange and internet access. It operates within the framework of the TCP/IP model, which governs how data is transmitted over networks.

Here's a limited overview of the essential concepts you'll need to understand to get two ESP32 devices communicating with each other:

  • TCP/IP Protocol Suite: The TCP/IP protocol suite consists of several layers, including the application layer, transport layer, internet layer (which includes the network layer), and link layer. Each layer plays a specific role in ensuring reliable and efficient communication.

  • Ports: Ports are virtual endpoints within a device enabling communication between different applications or services. They are identified by numerical values ranging from 0 to 65535, with certain well-known ports reserved for specific services.

  • Sockets: Sockets provide an interface for communication between two processes running on different devices over a network. They enable applications to send and receive data using standard networking protocols, identified by an IP address and a port number.

  • Network Layer: The network layer, part of the TCP/IP model, is responsible for routing and forwarding data packets between devices. It uses logical addressing (such as IP addresses) to identify devices on a network and determines the best path for data transmission.

  • IP Addresses: IP addresses are unique numerical identifiers assigned to devices on a network, facilitating communication. IPv4 (32-bit) and IPv6 (128-bit) are the two types of IP addresses commonly used.

  • Routing: Routing determines the best path for data packets to travel from the source to the destination across a network. Routers facilitate this process by forwarding packets based on network addresses, using routing tables to make decisions.

  • DNS (Domain Name System): DNS translates domain names (e.g., www.example.com) into IP addresses, enabling users to access resources using human-readable names. DNS servers maintain databases of domain names and their corresponding IP addresses.

  • DHCP (Dynamic Host Configuration Protocol): DHCP automatically assigns IP addresses and other network configuration parameters to devices on a network, simplifying network administration. DHCP servers manage the allocation process, assigning unique IP addresses and renewing leases periodically.

To establish communication between two ESP32 devices, you configure them with compatible network settings (so that they see each other, which means there exist a route for the packets to go from one to the other), implement socket-based communication using TCP/IP protocols, and ensure that the necessary ports are open for data exchange.

Thanks for the sugestions I'll have a look at these.

My ultimate goal is more along the line of IOT rather than the web in general.

Thanks for that.

I've found with a lot of problems with arduino, it's like a jigsaw. The more pieces you get in place, the clearer it becomes.

It helps knowing this stuff, i mistakenly thought that much of this was just to do with web applications.

You live and learn.

1. Fig-1 depicts the exising Internet and WiFi-LAN (Local Area Network) in my home cosisting of:
WiFiFundamentals
Figure-1:

(1) Three PCs with WiFi (Wireless Fidelity) devices/connectivity.

(2) Four Mobile Phones with WiFi devices.

(3) WiFi Router which is connected with Internet Modem by physical cable. In many cases, Modem and Router appear as a single unit; where, the word Router is used to refer to the whole unit.

(4) Internet Modem which is connected with my ISP Provider's Server by Optical Fibre.

(5) 30-pin ESP32 Dev Module which works as a Web Server and passes the "Close Condition of K1" to Mobile-1 via WiFi Network.

2. How do ESP32 and Mobile-1 communicate each other in a Router based WiFi Network?
(1) The ISP Provider (Internet Service Provider) assigns a Public IP (Internet Protocol) Address for the Router. For my Router, the IP Address is: 192.168.0.105.

(2) The ISP Provider also assigns the following credentials (changeable bythe user) for the Router:
SSID (Service Set Indentifier): "SiamWifiNew"
Password (Pass Word): "siam1234"

(3) The Router broadcasts a 2.4 GHz WiFi signal which can be detected by ESP32 and Mobile-1 and join with the network using Router's credentials mentioned above.

(4) The Router assigns "Private IP Address" to ESP32 (we will see later) and Mobile-1 which they use during mutual communication via Router.

3. How to pass the "Close Condition of K1" of ESP32 to Mobile-1.
...pending

JML, I have tried to go through the tutorial that you highlighted for [quote="J-M-L, post:4, topic:1223337"]
ESP NOWGetting Started with ESP-NOW (ESP32 with Arduino IDE) | Random Nerd Tutorials
[/quote]

Only to fall at the first hurdle. The reciever sketch fails to compile with the following error which I don't understand:

error: invalid conversion from 'void ()(const uint8_t, const uint8_t*, int)' {aka 'void ()(const unsigned char, const unsigned char*, int)'} to 'esp_now_recv_cb_t' {aka 'void ()(const esp_now_recv_info, const unsigned char*, int)'} [-fpermissive]
58 | esp_now_register_recv_cb(OnDataRecv);

Any advice would be welcome. Before I can start digging into it and find out how to use it I need the example to work.

The reciever sketch is below,

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include <esp_now.h>
#include <WiFi.h>

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
    char a[32];
    int b;
    float c;
    bool d;
} struct_message;

// Create a struct_message called myData
struct_message myData;

// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  memcpy(&myData, incomingData, sizeof(myData));
  Serial.print("Bytes received: ");
  Serial.println(len);
  Serial.print("Char: ");
  Serial.println(myData.a);
  Serial.print("Int: ");
  Serial.println(myData.b);
  Serial.print("Float: ");
  Serial.println(myData.c);
  Serial.print("Bool: ");
  Serial.println(myData.d);
  Serial.println();
}
 
void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);
  
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);

  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  
  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_register_recv_cb(OnDataRecv);
}
 
void loop() {

}

I just tried to compile that code for an ESP32 and it worked flawlessly
are you using the latest core for ESP32 ?-

I think that I have found the error,
void OnDataRecv(const uint8_t * mac
should be:
void OnDataRecv(const esp_now_recv_info_t * mac

It all works fine with this amendment.

Now to figure out how to use it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.