Difference between revisions of "ESP32: WiFi UDP analogRead"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
| Line 3: | Line 3: | ||
/* WiFi network name and password */ | /* WiFi network name and password */ | ||
| − | const char * ssid = " | + | const char * ssid = "o3"; |
| − | const char * pwd = " | + | const char * pwd = "Dzaq1993!"; |
// IP address to send UDP data to. | // IP address to send UDP data to. | ||
| Line 10: | Line 10: | ||
// a network broadcast address | // a network broadcast address | ||
// here is broadcast address | // here is broadcast address | ||
| − | const char * udpAddress = "192.168. | + | const char * udpAddress = "192.168.0.159"; |
| − | const int udpPort = | + | const int udpPort = 8888; |
//create UDP instance | //create UDP instance | ||
| Line 20: | Line 20: | ||
//Connect to the WiFi network | //Connect to the WiFi network | ||
| − | + | WiFi.begin(ssid, pwd); | |
Serial.println(""); | Serial.println(""); | ||
| Line 39: | Line 39: | ||
void loop(){ | void loop(){ | ||
// read only pin 32 & 36 others problem!! | // read only pin 32 & 36 others problem!! | ||
| − | int sensorReading = analogRead( | + | int sensorReading = analogRead(32); |
//send hello world to server | //send hello world to server | ||
udp.beginPacket(udpAddress, udpPort); | udp.beginPacket(udpAddress, udpPort); | ||
| Line 51: | Line 51: | ||
==Server== | ==Server== | ||
| − | nc -ul | + | nc -ul 8888 |
==Pranala Menarik== | ==Pranala Menarik== | ||
* [[ESP32]] | * [[ESP32]] | ||
Latest revision as of 19:32, 24 February 2023
#include <WiFi.h>
#include <WiFiUdp.h>
/* WiFi network name and password */
const char * ssid = "o3";
const char * pwd = "Dzaq1993!";
// IP address to send UDP data to.
// it can be ip address of the server or
// a network broadcast address
// here is broadcast address
const char * udpAddress = "192.168.0.159";
const int udpPort = 8888;
//create UDP instance
WiFiUDP udp;
void setup(){
Serial.begin(115200);
//Connect to the WiFi network
WiFi.begin(ssid, pwd);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
//This initializes udp and transfer buffer
udp.begin(udpPort);
}
void loop(){
// read only pin 32 & 36 others problem!!
int sensorReading = analogRead(32);
//send hello world to server
udp.beginPacket(udpAddress, udpPort);
Serial.println(sensorReading);
udp.printf("%u \n", sensorReading);
udp.endPacket();
delay(1000);
}
Server
nc -ul 8888