Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 13:58 02 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : ESP01 vs ESP32 for telemetry.

Author Message
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5019
Posted: 05:31am 03 Apr 2024
Copy link to clipboard 
Print this post

Hi.

I set up a couple ESP01's as a telemetry serial connection between two points. One is acting as a wifi access point, the other connects to the access point, and they transfer serial data.

This is the access point...
#include <ESP8266WiFi.h>
#include <WiFiClient.h>

const char* ssid = "Telemetry";
const char* password = "1234567890";

WiFiServer server(80);

void setup() {
 delay(5000);
 Serial.begin(57600);
 WiFi.mode(WIFI_AP);
 WiFi.softAP(ssid, password);
 server.begin();

 Serial.println("AP Server started");
}

void loop() {
 // Check if a client has connected
 WiFiClient client = server.available();
 if (!client) {
   return;
 }

 Serial.println("Client connected");

 // Loop while the client is connected
 while (client.connected()) {
   // Check if the client sends any data
   while (client.available()) {
     char c = client.read();
     Serial.write(c);
   }

   // Check if there is data from the serial port to send to the client
   while (Serial.available()) {
     char c = Serial.read();
     client.write(c);
   }
 }

 client.stop();
 Serial.println("Client disconnected");
}


And this is the client...
#include <ESP8266WiFi.h>

const char* ssid = "Telemetry";
const char* password = "1234567890";
const char* host = "192.168.4.1"; // Default IP address for ESP8266 AP

void setup() {
 delay(5000);
 Serial.begin(57600);
 WiFi.mode(WIFI_STA);
 connectToWiFi();
}

void connectToWiFi() {
 Serial.print("Connecting to WiFi");
 WiFi.begin(ssid, password);

 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }

 Serial.println("Success.");
}

void loop() {
 static WiFiClient client;

 if (WiFi.status() != WL_CONNECTED) {
   connectToWiFi();
 }

 if (!client.connected()) {
   client.connect(host, 80);
 }

 while (Serial.available()) {
   char c = Serial.read();
   client.write(c);
 }

 while (client.available()) {
   char c = client.read();
   Serial.write(c);
 }
}


The code was written with ideas from chatgpt and me fixing the bugs.

It worked very well, but was range limited, even with decent aerials on the ESP01's. 40 meters open field.

I had a pair of ESP32-CAM modules, and have read the ESP32 has a much better wifi range. The only change to the code was to use #include <WiFi.h> instead of #include #include <ESP8266WiFi.h>, and I didnt need #include <WiFiClient.h> on the access point, apparently its included in <WiFi.h>.

Loaded the software, they connected to eachother just fine, but...
Lots of dropped packets. Like 40%. No matter how close they were to eachother. And after a few minutes, the Access point would stop sending serial data full stop, even though it was still showing up as a wifi access point.

Any suggestion as to what could be going on? Should I try slowing down, or speeding up, the serial speed? Maybe a full buffer? There is no CTS connection.

Glenn
Edited 2024-04-07 14:13 by Gizmo
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5909
Posted: 06:10am 03 Apr 2024
Copy link to clipboard 
Print this post

Can you try loading the default AT firmware onto the ESP32s and use AT commands to control them.

That is how I use the ESP modules and while I haven't used them for long range, connecting to my normal access-points works well and I can run high speed without losses.

Jim
VK7JH
MMedit   MMBasic Help
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5019
Posted: 06:16am 03 Apr 2024
Copy link to clipboard 
Print this post

  TassyJim said  Can you try loading the default AT firmware onto the ESP32s and use AT commands to control them.


Hi Jim, no I dont think so. One end points to a programmed called Mission Planner, the other is a flight computer. No opportunity to insert commands.

Its weird because the ESP01's worked fine, same code.
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3550
Posted: 08:09am 03 Apr 2024
Copy link to clipboard 
Print this post

Have you seen this page ?

ardupilot telemetry systems

The SIK radio modules seem like a good starting poin for mission planner. They have both USB (CDC port) as well as 3.3V UART signals. And they are not overly expensive (around 50 USD for a pair). Several KM range.

Volhout
Edited 2024-04-03 18:25 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5019
Posted: 08:20am 03 Apr 2024
Copy link to clipboard 
Print this post

  Volhout said  Have you seen this page ?

ardupilot telemetry systems

Volhout


Yeah. The ESP6266 code worked, but, you need to log your PC into its access point, which means your PC no longer has access to your home wifi. Which means no internet, no updating of the maps.

Thats why I wrote my own, its a true serial - wifi - serial, and my pc can still be on the home wifi.

I did try the ESP32 "Dronebridge" code, but it raised a few errors in the compile and I couldn't get it to work.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3550
Posted: 08:36am 03 Apr 2024
Copy link to clipboard 
Print this post

Hi Glenn,

What about placing a standard WIFI extender, WIFI connected to your home WIFI, in the neighbourhood of the rover ?
Most access points can also be configured as extender.

And use a single ESPxx as a UART bridge to the home WIFI network ? With standard AT command set.

Volhout
PicomiteVGA PETSCII ROBOTS
 
scruss
Regular Member

Joined: 20/09/2021
Location: Canada
Posts: 83
Posted: 10:58am 03 Apr 2024
Copy link to clipboard 
Print this post

The ESP01 doesn't have a great antenna. Some ESP32 modules have better antennas, but most are the usual PCB squiggles.

You might be able to find an ESP8266 board that can take an external antenna. The LOLIN D1 Mini Pro can, but it looks like you have to do some soldering to enable it. This would allow you to use the same code as worked with your ESP01 but with better range.
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5019
Posted: 12:14am 04 Apr 2024
Copy link to clipboard 
Print this post

I do have a couple ESP8266 D1 Mini's ( https://lonelybinary.com/products/esp8266-d1-mini-development-board-4mb-16mb?variant=43953553178781 ), and I've added external aerials to these by cutting tracks and soldering on some coax.

I'll do some experiments. Still its a shame I cant get the ESP32's to work, they should be a much better option. My code is basically sending one byte at a time, I'm wondering if I should be buffering it and sending packets of data. I dont know how long a sentence is, so maybe add a timeout to send the buffer even if its not full.
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5909
Posted: 01:57am 04 Apr 2024
Copy link to clipboard 
Print this post

One byte at a time over WiFi is really pushing things.
I would prefer to see line at a time if that is relevant to the data (end of line of some sort) with a timeout to be sure you aren't waiting too long.

Jim
VK7JH
MMedit   MMBasic Help
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3550
Posted: 05:28am 04 Apr 2024
Copy link to clipboard 
Print this post

I am not quite clear what range you require. The WiFi modules may get you 100meter open air with omnidirectional antennas ( meaning you do not point the antenna to follow the rover). But when you require 500 meter, it is a no go. Then you should either track the rover with antenna’s, or place multiple extenders along its path. Or use a different system. Something designed to have that range, at the required bitrate.

Volhout
Edited 2024-04-04 15:29 by Volhout
PicomiteVGA PETSCII ROBOTS
 
flasherror
Senior Member

Joined: 07/01/2019
Location: United States
Posts: 159
Posted: 12:41am 05 Apr 2024
Copy link to clipboard 
Print this post

  Quote  Lots of dropped packets. Like 40%. No matter how close they were to eachother. And after a few minutes, the Access point would stop sending serial data full stop, even though it was still showing up as a wifi access point.


Just some random thoughts:
1. How are you powering both? Try different/shorter USB cable if USB powered?
2. How far away do you need communication?
3. Are you using the PCB antenna? Verified that the antenna jumper is in the correct place? See https://dronebotworkshop.com/esp32-cam-intro/
4. Tried another set of esp32-cam boards to make sure not an issue with a defective one?
5. Not that it should matter, but remove the camera from the board?
6. Try switching off power saving for wifi?
WiFi.setSleep(WIFI_PS_NONE);
Edited 2024-04-05 10:54 by flasherror
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1789
Posted: 11:38am 05 Apr 2024
Copy link to clipboard 
Print this post

In this months Silicon Chip, Circuit Notebook p20 Experimenting with LoRa mesh networking.
The contributor is using a few ESP32s with LoRa modules and Meshtastic software to cover an extended area. Worth reading to see if it is suitable for your application.
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5019
Posted: 04:12am 07 Apr 2024
Copy link to clipboard 
Print this post

OK, now its working.

Added some buffering on incoming serial data. I also set the wifi to 802.11 LR (Long Range) mode.



The only time I lost a few packets was when I uploaded a new set of waypoints. The two ESP's are about 30 meters apart, one in the yard and the other in the house. Both have external aerials fitted, good supply power and a 100uF cap fitted across the supply at the module.

The updated code for the access point ( on the rover )...

#include <WiFi.h>
extern "C" {
 #include "esp_wifi.h"
}

const char* ssid = "Telemetry";
const char* password = "1234567890";

WiFiServer server(80);

void setup() {
 delay(5000);
 Serial.begin(57600);
 WiFi.mode(WIFI_AP);
 WiFi.softAP(ssid, password);
 esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_11B);
 server.begin();
 Serial.println("AP Server started");
}

void loop() {
 WiFiClient client = server.available();
 if (!client) {
   return;
 }

 Serial.println("Client connected");

 // Buffer for incoming serial data
 char serialBuffer[64];
 int bufferIndex = 0;
 unsigned long lastTime = millis();

 while (client.connected()) {
   // Check for incoming data from Serial
   while (client.available()) {
     char c = client.read();
     Serial.write(c);
   }

   // Check if there is data from the serial port to send to the client
  while (Serial.available()) {
     char c = Serial.read();
     serialBuffer[bufferIndex++] = c;

     // Send if buffer is full
     if (bufferIndex == 64) {
       client.write((const uint8_t*)serialBuffer, 64);
       bufferIndex = 0;
       lastTime = millis(); // Reset timeout timer
     }
   }

   // Check for timeout (1 second without filling the buffer)
   if (millis() - lastTime > 1000 && bufferIndex > 0) {
     client.write((const uint8_t*)serialBuffer, bufferIndex);
     bufferIndex = 0; // Reset buffer for next packet
     lastTime = millis(); // Reset timeout timer
   }
   // Check for incoming data from client to send to Serial
   
 }

 client.stop();
 Serial.println("Client disconnected");
}


And this is the client...

#include <WiFi.h>
extern "C" {
 #include "esp_wifi.h"
}

const char* ssid = "Telemetry";
const char* password = "1234567890";
const char* host = "192.168.4.1";

void setup() {
 delay(5000);
 Serial.begin(57600);
 WiFi.mode(WIFI_STA);
 WiFi.begin(ssid, password);
 esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B);

 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
 Serial.println("\nWiFi connected");
}

void loop() {
 static WiFiClient client;
 if (!client.connected()) {
   client.connect(host, 80);
 }

 // Buffer for outgoing serial data
 char serialBuffer[64];
 int bufferIndex = 0;
 unsigned long lastTime = millis();

 while (client.connected()) {
   // Check for incoming data from Serial
   while (Serial.available()) {
     char c = Serial.read();
     serialBuffer[bufferIndex++] = c;

     // Send if buffer is full
     if (bufferIndex == 64) {
       client.write((const uint8_t*)serialBuffer, 64);
       bufferIndex = 0; // Reset buffer index
       lastTime = millis(); // Reset timeout timer
     }
   }

   // Check for timeout (1 second without filling the buffer)
   if (millis() - lastTime > 1000 && bufferIndex > 0) {
     client.write((const uint8_t*)serialBuffer, bufferIndex);
     bufferIndex = 0; // Reset buffer index
     lastTime = millis(); // Reset timeout timer
   }

   // Check for incoming data from server to send to Serial
   while (client.available()) {
     char c = client.read();
     Serial.write(c);
   }
 }

 if (!client.connected()) {
   Serial.println("Attempting to reconnect...");
   client.stop();
   while (!client.connect(host, 80)) {
     delay(1000);
     Serial.print(".");
   }
   Serial.println("\nReconnected.");
 }
}


As before, ChatGPT helped a great deal with this.
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024