#include<ESP8266WiFi.h>voidsetup(){Serial.begin(9600);}voidloop(){Serial.println("Scanning WiFi");intno_of_networks=WiFi.scanNetworks();// only 2.4GHz for NodeMCUif(n==0){Serial.println("No networks available");}else{for(inti=0;i<n;i++){Serial.println(String(i+1)+" "+WiFi.SSID(i)+" "+String(WiFi.RSSI(i)));}}delay(5000);}
#include<ESP8266WiFi.h>// variables// we need to use these exact types and names, to override the one in the header filechar*ssid="WiFi Name";char*pass="WiFi Password";voidsetup(){Serial.begin(9600);pinMode(D2,OUTPUT);Serial.println("Connecting to WiFi...");WiFi.begin(ssid,pass);while(WiFi.status()!=WL_CONNECTED){Serial.print(".");delay(1000);}Serial.println("Connected to "+String(ssid)+" successfully");}voidloop(){// codedelay(5000);}
#include<ESP8266WiFi.h>// variables// we need to use these exact types and names, to override the one in the header filechar*ssid="WiFi Name";char*pass="WiFi Password";intlocal_port=80;WiFiServerserver(local_port);voidsetup(){Serial.begin(9600);pinMode(D2,OUTPUT);Serial.println("Connecting to WiFi...");WiFi.begin(ssid,pass);while(WiFi.status()!=WL_CONNECTED){Serial.print(".");delay(1000);}Serial.println("Connected to "+String(ssid)+" successfully.");server.begin(local_port);local_ip=WiFi.localIP();Serial.println("Started server on "+String(local_ip)+":"+String(local_port)+" successfully.");}voidloop(){WiFiClientclient=server.available();if(!client){return;}Serial.println("New request received!");Stringrequest=client.readStringUntil("\r");query_path="/on"/* localhost/on turns on LED localhost/off turns off LED */if(request.indexOf(query_path)!=-1){digitalWrite(D2,HIGH);Serial.println("LED turned on");}elseif(request.indexOf(query_path)!=-1){digitalWrite(D2,LOW);Serial.println("LED turned off");}else{Serial.println("Invalid request");}client_interaction_code=""+"<html><body>"+"<button><a href='/on'>On</a></button>"+"<button><a href='/off'>Off</a></button>"+"</body></html>";delay(5000);}
#include<ESP8266WiFi.h>// variables// we need to use these exact types and names, to override the one in the header filechar*ssid="WiFi Name";char*pass="WiFi Password";intlocal_port=80;WiFiClientclient;char*api_key="";intid_server=;charip_server[]="";voidsetup(){Serial.begin(9600);Serial.println("Connecting to WiFi ...");WiFi.begin(ssid,pass);while(WiFi.status()!=WL_CONNECTED){Serial.print(".");delay(1000);}Serial.println("WiFi connected");// ThingSpeak.begin(client);}voidloop(){if(client.connect(ip_server,local_port)){ThingSpeak.setField(1,data);ThingSpeak.writeFields(id_server,api);}delay(5000);}
#include<ESP8266WiFi.h>#include<ESP8266HTTPClient.h>// variables// we need to use these exact types and names, to override the one in the header filechar*ssid="WiFi Name";char*pass="WiFi Password";HTTPClientclient;Stringapi;intdata;intstatus_code;Stringresponse;voidsetup(){Serial.begin(9600);pinMode(D2,OUTPUT);Serial.println("Connecting to WiFi...");WiFi.begin(ssid,pass);while(WiFi.status()!=WL_CONNECTED){Serial.print(".");delay(1000);}Serial.println("Connected to "+String(ssid)+" successfully");}voidloop(){data=100;api="http://.../insert.php?data="+String(data);client.begin(api);status_code=client.GET();response=client.getString();delay(5000);}
Last Updated: 2024-05-12 ; Contributors: AhmedThahir