-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
165e245
commit f1a1b41
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import socket | ||
import time | ||
|
||
IP_ADDRESS = "192.168.96.98" # Replace with the ESP32 IP address | ||
UDP_PORT = 1234 | ||
|
||
def send_message(message): | ||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
sock.sendto(message.encode(), (IP_ADDRESS, UDP_PORT)) | ||
sock.close() | ||
|
||
def main(): | ||
message = input("Enter the message to display on ESP32: ") | ||
send_message(message) | ||
print("Message sent") | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <WiFi.h> | ||
#include <WiFiUdp.h> | ||
#include <U8g2lib.h> | ||
|
||
const char* ssid = "Jhelum.net [Luqman House]"; | ||
const char* password = "7861234786"; | ||
const int udpPort = 1234; | ||
WiFiUDP udp; | ||
|
||
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
WiFi.begin(ssid, password); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(1000); | ||
Serial.println("Connecting to WiFi..."); | ||
} | ||
|
||
Serial.println("Connected to WiFi"); | ||
Serial.print("ESP IP Address: "); | ||
Serial.println(WiFi.localIP()); | ||
|
||
u8g2.begin(); | ||
u8g2.clearBuffer(); | ||
u8g2.setFont(u8g2_font_ncenB08_tr); | ||
u8g2.drawStr(0, 10, "Waiting messages..."); | ||
u8g2.sendBuffer(); | ||
|
||
udp.begin(udpPort); | ||
} | ||
|
||
void loop() { | ||
int packetSize = udp.parsePacket(); | ||
if (packetSize) { | ||
u8g2.clearBuffer(); | ||
u8g2.setFont(u8g2_font_ncenB08_tr); | ||
u8g2.drawStr(0, 10, "Received message:"); | ||
|
||
char incomingPacket[255]; | ||
int len = udp.read(incomingPacket, 255); | ||
if (len > 0) { | ||
incomingPacket[len] = 0; | ||
} | ||
|
||
u8g2.drawStr(0, 25, incomingPacket); | ||
u8g2.sendBuffer(); | ||
Serial.println(incomingPacket); | ||
} | ||
} |