-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi1.ino
45 lines (33 loc) · 1.46 KB
/
wifi1.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<SoftwareSerial.h>
SoftwareSerial esp(2,3); //rx tx
#define ssid "srx123" //add your ssid name
#define pass "12345678910" //add your password
#define IP "180.106.153.149" // ip for thingspeak
String cmd;
String msg = "GET /update?key=ZLFJWCYYGV66YFK9"
int data; //the data you want to send should be stored in data
void setup()
{
//**************Wifi***********************************************
Serial.begin(115200);
esp.println("AT"); //cheked if arduino is connecter to esp microcontroler
if(esp.find("OK")); Serial.println("esp is online");
//connecting to wifi rounter
esp.println("AT+CWMODE=1"); //change to station mode(i also confused why we do it)
esp.println("AT+CWJAP=\""+ssid+"\",\""+pass+"\""); //give ssid and password to intialize the connection
if(esp.find("OK")) Serial.println("connected to wifi");
else Serial.println("trying again failed to connect to wifi");
//*********************************************************************
}
//****to send data*****************
//add more parameter if you want to send more data
void send(int data1)
{
esp.println("AT+CIPSTART=\"UDP\",\""+IP+"\",80"); //start a udp connection
cmd=msg+"&field1="+data1+"\r\n"; //the data packet to be send
esp.println("AT+CIPSEND="+cmd.length()); //intailize buffer to send data
esp.println(cmd) //send the data
esp.println("AT+CIPCLOED"); //closed the connection
}
void loop(){
}