Difference between revisions of "WeMOS: WiFi Local AnalogRead"
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
Onnowpurbo (talk | contribs)  (Created page with " #include <WiFi.h>  #include <WiFiUdp.h>    →WiFi network name and password:   const char * ssid = "Wisma Anggrek";  const char * pwd = "@nggr3kbul@n";    // IP address to...")  | 
				Onnowpurbo (talk | contribs)   | 
				||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − |   #include <  | + |   #include <ESP8266WiFi.h>  | 
  #include <WiFiUdp.h>  |   #include <WiFiUdp.h>  | ||
| + | |||
| + |  // replace with your channel’s thingspeak API key and  your SSID and password  | ||
| + |  const char* ssid = "Wisma Anggrek";  | ||
| + |  const char* password = "@nggr3kbul@n";  | ||
| − | + |   WiFiClient client;  | |
| − | |||
| − | |||
| − | |||
  // IP address to send UDP data to.  |   // IP address to send UDP data to.  | ||
  // it can be ip address of the server or    |   // it can be ip address of the server or    | ||
| Line 15: | Line 16: | ||
  //create UDP instance  |   //create UDP instance  | ||
  WiFiUDP udp;  |   WiFiUDP udp;  | ||
| − | + | ||
| − |   void setup(){  | + |   void setup()    | 
| + |  {  | ||
    Serial.begin(115200);  |     Serial.begin(115200);  | ||
| + |    delay(10);  | ||
| + |    WiFi.begin(ssid, password);  | ||
| − | + |     Serial.println();  | |
| − | + |    Serial.println();  | |
| − |     Serial.  | + |     Serial.print("Connecting to ");  | 
| − | + |    Serial.println(ssid);  | |
| − | + |    WiFi.begin(ssid, password);  | |
| − |     while (WiFi.status() != WL_CONNECTED) {  | + | |
| + |     while (WiFi.status() != WL_CONNECTED)    | ||
| + |    {  | ||
      delay(500);  |       delay(500);  | ||
      Serial.print(".");  |       Serial.print(".");  | ||
    }  |     }  | ||
    Serial.println("");  |     Serial.println("");  | ||
| − | + |     Serial.println("WiFi connected");  | |
| − |     Serial.println  | ||
| − | |||
| − | |||
| − | |||
    udp.begin(udpPort);  |     udp.begin(udpPort);  | ||
| − |   }    | + |   }  | 
| + | |||
  void loop(){  |   void loop(){  | ||
| Line 47: | Line 50: | ||
| − | |||
| − | |||
| − | |||
==Pranala Menarik==  | ==Pranala Menarik==  | ||
| − | * [[  | + | * [[WeMOS]]  | 
Latest revision as of 08:23, 9 November 2019
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
 
// replace with your channel’s thingspeak API key and  your SSID and password
const char* ssid = "Wisma Anggrek";
const char* password = "@nggr3kbul@n";
WiFiClient client;
// 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 = "10.11.12.143";
const int udpPort = 44444;
//create UDP instance
WiFiUDP udp;
 
void setup() 
{
  Serial.begin(115200);
  delay(10);
  WiFi.begin(ssid, password);
  
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  udp.begin(udpPort);
}
  
void loop(){
  int sensorReading = analogRead(A0);
  udp.beginPacket(udpAddress, udpPort);
  Serial.println(sensorReading);
  udp.printf("%u \n", sensorReading);
  udp.endPacket();
  delay(1000);
}