Skip to content

Commit

Permalink
Oled display message #19
Browse files Browse the repository at this point in the history
  • Loading branch information
khubaibiftikhar committed Aug 5, 2023
1 parent 165e245 commit f1a1b41
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Message_sendinng.py
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()
50 changes: 50 additions & 0 deletions src/message_send_on_sms.ino
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);
}
}

0 comments on commit f1a1b41

Please sign in to comment.