Receive data using esp8266ESP8266
I have connected esp8266ESP8266 to my Raspberry pi's wifiPi's WiFi network and assigned ana static IP.
My arduinoArduino code
#include "SoftwareSerial.h"
String ssid ="Rpi";
String password="raspberry";
SoftwareSerial esp(3, 2);// RX, TX
String server = "192.168.50.1"; //my Host
void setup() {
esp.begin(115200);
Serial.begin(115200);
connectWifi();
httpget();
delay(1000);
}
void connectWifi() {
String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
esp.println(cmd);
delay(4000);
if(esp.find("OK")) {
Serial.println("Connected!");
}
else {
Serial.println("Cannot connect to wifi ! Connecting again..."); }
connectWifi();
}
/////////////////////////////GET METHOD///////////////////////////////
void httpget() {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",1234");//start a TCP connection.
if( esp.find("OK")) {
Serial.println("TCP connection ready");
} delay(1000);
/*
String getRequest =
"GET " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Type: application/json\r\n" +
"\r\n";
*/
String sendCmd = "AT+CIPSEND=";
esp.print(sendCmd);
//esp.println(getRequest.length() );
delay(500);
if(esp.find(">")) {
Serial.println("Sending..");
// esp.print(getRequest);
if( esp.find("SEND OK")) {
Serial.println("Packet sent");
while (esp.available()) {
String response = esp.readString();
}
esp.println("AT+CIPCLOSE");
}
}
}
void loop() {
httpget();
}
#include "SoftwareSerial.h"
String ssid = "Rpi";
String password = "raspberry";
SoftwareSerial esp(3, 2);// RX, TX
String server = "192.168.50.1"; //my Host
void setup() {
esp.begin(115200);
Serial.begin(115200);
connectWifi();
httpget();
delay(1000);
}
void connectWifi() {
String cmd = "AT+CWJAP=\"" + ssid + "\",\"" + password + "\"";
esp.println(cmd);
delay(4000);
if (esp.find("OK")) {
Serial.println("Connected!");
}
else {
Serial.println("Cannot connect to wifi ! Connecting again...");
}
connectWifi();
}
/////////////////////////////GET METHOD///////////////////////////////
void httpget() {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",1234");//start a TCP connection.
if ( esp.find("OK")) {
Serial.println("TCP connection ready");
}
delay(1000);
/*
String getRequest =
"GET " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Type: application/json\r\n" +
"\r\n";
*/
String sendCmd = "AT+CIPSEND=";
esp.print(sendCmd);
//esp.println(getRequest.length() );
delay(500);
if (esp.find(">")) {
Serial.println("Sending..");
// esp.print(getRequest);
if ( esp.find("SEND OK")) {
Serial.println("Packet sent");
while (esp.available()) {
String response = esp.readString();
}
esp.println("AT+CIPCLOSE");
}
}
}
void loop() {
httpget();
}
But I can not see it in my serial monitorSerial Monitor. Do I need to create a separate program for getting from wifiWiFi?
Thanks in advance.
Receive data using esp8266
I have connected esp8266 to my Raspberry pi's wifi network and assigned an static IP.
My arduino code
#include "SoftwareSerial.h"
String ssid ="Rpi";
String password="raspberry";
SoftwareSerial esp(3, 2);// RX, TX
String server = "192.168.50.1"; //my Host
void setup() {
esp.begin(115200);
Serial.begin(115200);
connectWifi();
httpget();
delay(1000);
}
void connectWifi() {
String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
esp.println(cmd);
delay(4000);
if(esp.find("OK")) {
Serial.println("Connected!");
}
else {
Serial.println("Cannot connect to wifi ! Connecting again..."); }
connectWifi();
}
/////////////////////////////GET METHOD///////////////////////////////
void httpget() {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",1234");//start a TCP connection.
if( esp.find("OK")) {
Serial.println("TCP connection ready");
} delay(1000);
/*
String getRequest =
"GET " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Type: application/json\r\n" +
"\r\n";
*/
String sendCmd = "AT+CIPSEND=";
esp.print(sendCmd);
//esp.println(getRequest.length() );
delay(500);
if(esp.find(">")) {
Serial.println("Sending..");
// esp.print(getRequest);
if( esp.find("SEND OK")) {
Serial.println("Packet sent");
while (esp.available()) {
String response = esp.readString();
}
esp.println("AT+CIPCLOSE");
}
}
}
void loop() {
httpget();
}
But I can not see it in my serial monitor. Do I need to create a separate program for getting from wifi?
Thanks in advance.
Receive data using ESP8266
I have connected ESP8266 to my Raspberry Pi's WiFi network and assigned a static IP.
My Arduino code
#include "SoftwareSerial.h"
String ssid = "Rpi";
String password = "raspberry";
SoftwareSerial esp(3, 2);// RX, TX
String server = "192.168.50.1"; //my Host
void setup() {
esp.begin(115200);
Serial.begin(115200);
connectWifi();
httpget();
delay(1000);
}
void connectWifi() {
String cmd = "AT+CWJAP=\"" + ssid + "\",\"" + password + "\"";
esp.println(cmd);
delay(4000);
if (esp.find("OK")) {
Serial.println("Connected!");
}
else {
Serial.println("Cannot connect to wifi ! Connecting again...");
}
connectWifi();
}
/////////////////////////////GET METHOD///////////////////////////////
void httpget() {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",1234");//start a TCP connection.
if ( esp.find("OK")) {
Serial.println("TCP connection ready");
}
delay(1000);
/*
String getRequest =
"GET " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Type: application/json\r\n" +
"\r\n";
*/
String sendCmd = "AT+CIPSEND=";
esp.print(sendCmd);
//esp.println(getRequest.length() );
delay(500);
if (esp.find(">")) {
Serial.println("Sending..");
// esp.print(getRequest);
if ( esp.find("SEND OK")) {
Serial.println("Packet sent");
while (esp.available()) {
String response = esp.readString();
}
esp.println("AT+CIPCLOSE");
}
}
}
void loop() {
httpget();
}
But I can not see it in my Serial Monitor. Do I need to create a separate program for getting from WiFi?
When I execute AT+CIPSTA?
Output :My arduino code
+CIPSTA:ip:#include "SoftwareSerial.h"
String ssid ="Rpi";
String password="raspberry";
SoftwareSerial esp(3, 2);// RX, TX
String server = "192.168.50.18"1"; //my Host
+CIPSTA:gateway:"192
void setup() {
esp.168begin(115200);
Serial.50begin(115200);
connectWifi();
httpget();
delay(1000);
}
void connectWifi() {
String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
esp.1"println(cmd);
+CIPSTA
delay(4000);
if(esp.find("OK")) {
Serial.println("Connected!");
}
else {
Serial.println("Cannot connect to wifi ! Connecting again..."); }
connectWifi();
}
/////////////////////////////GET METHOD///////////////////////////////
void httpget() {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",1234");//start a TCP connection.
if( esp.find("OK")) {
Serial.println("TCP connection ready");
} delay(1000);
/*
String getRequest =
"GET " + uri + " HTTP/1.0\r\n" +
"Host:netmask " + server + "\r\n" +
"Accept:"255 *" + "/" + "*\r\n" +
"Content-Type: application/json\r\n" +
"\r\n";
*/
String sendCmd = "AT+CIPSEND=";
esp.255print(sendCmd);
//esp.255println(getRequest.0"length() );
delay(500);
if(esp.find(">")) {
Serial.println("Sending..");
// esp.print(getRequest);
if( esp.find("SEND OK")) {
Serial.println("Packet sent");
while (esp.available()) {
String response = esp.readString();
}
esp.println("AT+CIPCLOSE");
}
}
}
void loop() {
httpget();
}
I get this message
Cannot connect to wifi ! Connecting again...
import socket
TCP_IP = '192.168.50.1' #Local Host
TCP_PORT = 30071234 #Listening Port
BUFFER_SIZE = 12
SERVER_IP = '192.168.50.18' #Arduino IP
SERVER_PORT = 3007 #Server Port
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((TCP_IP,TCP_PORT))
#s.listen(1)
#(conn,addr) = s.accept()
#print 'Connection address: ',addr
while True:
print 'Sending message'
s.sendto('1',(SERVER_IP,SERVER_PORT))
print 'Waiting for response'
data,addr = s.recvfrom(BUFFER_SIZE)
if not data: break
print 'received data: ',data
print 'data recieved from: ',addr
conn.close()
s.close()
When I execute AT+CIPSTA?
Output :
+CIPSTA:ip:"192.168.50.18"
+CIPSTA:gateway:"192.168.50.1"
+CIPSTA:netmask:"255.255.255.0"
import socket
TCP_IP = '192.168.50.1' #Local Host
TCP_PORT = 3007 #Listening Port
BUFFER_SIZE = 12
SERVER_IP = '192.168.50.18' #Arduino IP
SERVER_PORT = 3007 #Server Port
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((TCP_IP,TCP_PORT))
#s.listen(1)
#(conn,addr) = s.accept()
#print 'Connection address: ',addr
while True:
print 'Sending message'
s.sendto('1',(SERVER_IP,SERVER_PORT))
print 'Waiting for response'
data,addr = s.recvfrom(BUFFER_SIZE)
if not data: break
print 'received data: ',data
print 'data recieved from: ',addr
conn.close()
s.close()
My arduino code
#include "SoftwareSerial.h"
String ssid ="Rpi";
String password="raspberry";
SoftwareSerial esp(3, 2);// RX, TX
String server = "192.168.50.1"; //my Host
void setup() {
esp.begin(115200);
Serial.begin(115200);
connectWifi();
httpget();
delay(1000);
}
void connectWifi() {
String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
esp.println(cmd);
delay(4000);
if(esp.find("OK")) {
Serial.println("Connected!");
}
else {
Serial.println("Cannot connect to wifi ! Connecting again..."); }
connectWifi();
}
/////////////////////////////GET METHOD///////////////////////////////
void httpget() {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",1234");//start a TCP connection.
if( esp.find("OK")) {
Serial.println("TCP connection ready");
} delay(1000);
/*
String getRequest =
"GET " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Type: application/json\r\n" +
"\r\n";
*/
String sendCmd = "AT+CIPSEND=";
esp.print(sendCmd);
//esp.println(getRequest.length() );
delay(500);
if(esp.find(">")) {
Serial.println("Sending..");
// esp.print(getRequest);
if( esp.find("SEND OK")) {
Serial.println("Packet sent");
while (esp.available()) {
String response = esp.readString();
}
esp.println("AT+CIPCLOSE");
}
}
}
void loop() {
httpget();
}
I get this message
Cannot connect to wifi ! Connecting again...
import socket
TCP_IP = '192.168.50.1' #Local Host
TCP_PORT = 1234 #Listening Port
BUFFER_SIZE = 12
SERVER_IP = '192.168.50.18' #Arduino IP
SERVER_PORT = 3007 #Server Port
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((TCP_IP,TCP_PORT))
#s.listen(1)
#(conn,addr) = s.accept()
#print 'Connection address: ',addr
while True:
print 'Sending message'
s.sendto('1',(SERVER_IP,SERVER_PORT))
print 'Waiting for response'
data,addr = s.recvfrom(BUFFER_SIZE)
if not data: break
print 'received data: ',data
print 'data recieved from: ',addr
conn.close()
s.close()
Receive data using esp8266
I have connected esp8266 to my Raspberry pi's wifi network and assigned an static IP.
When I execute AT+CIPSTA?
Output :
+CIPSTA:ip:"192.168.50.18"
+CIPSTA:gateway:"192.168.50.1"
+CIPSTA:netmask:"255.255.255.0"
In my Raspberry Pi I am constantly sending a signal to this IP address.
import socket
TCP_IP = '192.168.50.1' #Local Host
TCP_PORT = 3007 #Listening Port
BUFFER_SIZE = 12
SERVER_IP = '192.168.50.18' #Arduino IP
SERVER_PORT = 3007 #Server Port
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((TCP_IP,TCP_PORT))
#s.listen(1)
#(conn,addr) = s.accept()
#print 'Connection address: ',addr
while True:
print 'Sending message'
s.sendto('1',(SERVER_IP,SERVER_PORT))
print 'Waiting for response'
data,addr = s.recvfrom(BUFFER_SIZE)
if not data: break
print 'received data: ',data
print 'data recieved from: ',addr
conn.close()
s.close()
But I can not see it in my serial monitor. Do I need to create a separate program for getting from wifi?
Thanks in advance.