Difference between revisions of "ESP32: WiFi UDP analogRead"
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
| Onnowpurbo (talk | contribs)  (→ESP32) | Onnowpurbo (talk | contribs)  | ||
| Line 47: | Line 47: | ||
|     delay(1000); |     delay(1000); | ||
|   } |   } | ||
| + | |||
| + | |||
| + | ==Pranala Menarik== | ||
| + | |||
| + | * [[ESP32]] | ||
Revision as of 19:15, 5 November 2019
#include <WiFi.h>
#include <WiFiUdp.h>
/* WiFi network name and password */
const char * ssid = "HUAWEI-1A73";
const char * pwd = "52408495";
// 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.8.100";
const int udpPort = 44444;
//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(){
  //send hello world to server 
  udp.beginPacket(udpAddress, udpPort);
  int sensorReading = analogRead(15);
  Serial.println(sensorReading);
  udp.write(sensorReading);
  udp.write('\n");
  udp.endPacket();
  delay(1000);
}