- Mon Jun 17, 2024 6:01 pm
#68616
So, I've been trying HC-06, four modules of them from different outlets, but never got them to work so I gave up.
I have since found Seeed Xiao ESP32C3 which has a small form factor and can be pinned or SMD mounted. Well, my issue is I know nothing about code, but so far I have been able to put my module in both AP and BLE and connect to it (I have not tried to run it over WiFi where it connects to a router). However, what I have failed to do is to communicate with my Mega 2560. I have it wired up properly as far as I can tell with a logic level shifter. I have set IP to 192.168.4.1 and port 80 in TS but it fails when testing the connection. Where is the issue with my code, if there is any, as I presume that's where I err?
I am sure someone else has a way better understanding of how to do this.
TIA
I have since found Seeed Xiao ESP32C3 which has a small form factor and can be pinned or SMD mounted. Well, my issue is I know nothing about code, but so far I have been able to put my module in both AP and BLE and connect to it (I have not tried to run it over WiFi where it connects to a router). However, what I have failed to do is to communicate with my Mega 2560. I have it wired up properly as far as I can tell with a logic level shifter. I have set IP to 192.168.4.1 and port 80 in TS but it fails when testing the connection. Where is the issue with my code, if there is any, as I presume that's where I err?
I am sure someone else has a way better understanding of how to do this.
TIA
Code: Select all
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>
#include <HardwareSerial.h>
const char* ssid = "Test"; // WiFi Access Point SSID
const char* password = "12345678"; // WiFi Access Point password
WiFiServer server(80); // TCP server on port 80
void setup() {
Serial.begin(115200); // Initialize Serial for debugging
Serial1.begin(9600); // Initialize UART for communication with Arduino Mega 2560
// Start WiFi Access Point
WiFi.softAP(ssid, password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
server.begin(); // Start TCP server
}
void loop() {
WiFiClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char data = client.read();
Serial1.write(data); // Forward received data to Arduino Mega 2560 over UART
}
if (Serial1.available()) {
char data = Serial1.read();
client.write(data); // Forward data received from Arduino Mega 2560 to WiFi client
}
}
client.stop(); // Close client connection
}
}