Arduino, Phase 7 : Never Ending ESP8266
HI fellas! This is our story with ESP866. Again. And again. So, our team met again this Thursday and tried to make ESP8266 working well. As we used before, we need
As we said before, we connect our Arduino to ESP8266. What we did in this section, we tried to check our PHP code with browser. And it works
Nah, our main problem now is, we still can’t send our data well. We have two reason here. First, we can send manually with AT Command, but can’t do it automatically. Second, we have problem with pin.
Okay, so let’s start with our journey with AT Command. We test our ESP8266 with blank code and upload it to Arduino. And then, we input it manually using serial monitor like this.
AT+CWJAP=”Connectify-huntul”,”huntulkece”
AT+CIPSTART=”TCP”,”192.168.28.1″,80
On the first step, we tried to connect ESP8266 to Luthfi’s laptop as an acess point. On the second stp, we tried TCP connection with server. On the third step, we tried to send the data. But when we tried last step, we got respond like this.
We tried to solve the first problem, for 400 error. We think that we wrote the wrong code. So, we tried to look into some server log for some request samples. We tried to fix our code and we got some syntax here.
GET /attendance.php?id=”somevalueshere” HTTP/1.0/
Then, we look for 408 error. We Googled it and we found this article
http://electronics.stackexchange.com/questions/177031/esp8266-wont-send-or-receive-returns-busy-s
It is said that the data length was not set properly. If it is not big enough, we can’t send data to server. At first, we think counting the character itself is enough. We forgot that “enter” in serial monitor would be include in it. So we give extra space for that enter. That article said, we should give 4 extra bytes (2 for hit the first enter, confirm data sent and 2 for hit the socnd enter, confirm data to the server). If we want to send 44 bytes, we should make it 48 bytes.
After we got some properly change, we tried to send data like this.
It is said 200 OK. Our request sucessfully received by the server and its process the request and give the proper response. Because of we connect it to the database, we got two response.
When the value sent match with the one on database, then the response “record updated sucessfully”
When the value sent don;t match with the one on database, then the response “no value matched”.
Because we got second response before, we tried the same value now. Hope we got the first response after this
And we got the first! It means finally the value matched with the one in the database.
But, we only got this far. We still can’t do it with automated code, only via serial monitor. So, we search for some reference and got this
http://www.instructables.com/id/Arduino-Esp8266-Post-Data-to-Website/
After necessary changes, this is our code
#include “SoftwareSerial.h”
String ssid =”Connectify-huntul”;
String password=”huntulkece”;
SoftwareSerial esp(6, 7);// RX, TX
String server = “192.168.28.1”; // http://www.example.com
String uri = “/attendance.php”;// our example is /esppost.php
int DHpin = 8;//sensor pin
//pinMode (DHpin, OUTPUT);
//reset the esp8266 module
esp.println(“AT+RST”);
delay(100);
if(esp.find(“OK”) ) Serial.println(“Module Reset”);
}
//connect to your wifi network
String cmd = “AT+CWJAP=\”” +ssid+”\”,\”” + password + “\””;
Serial.println(“Connected!”);
}
Serial.println(“Cannot connect to wifi”); }
for (int i = 0; i < 8; i ++) {
if (digitalRead (DHpin) == LOW) {
while (digitalRead (DHpin) == LOW); // wait for 50us
delayMicroseconds (30); // determine the duration of the high level to determine the data is ‘0 ‘or ‘1’
if (digitalRead (DHpin) == HIGH)
data |= (1 << (7-i)); // high front and low in the post
while (digitalRead (DHpin) == HIGH);
// data ‘1 ‘, wait for the next one receiver
digitalWrite (DHpin, LOW); // bus down, send start signal
delay (30); // delay greater than 18ms, so DHT11 start signal can be detected
digitalWrite (DHpin, HIGH);
delayMicroseconds (40); // Wait for DHT11 response
while (digitalRead (DHpin) == HIGH);
// DHT11 response, pulled the bus 80us
if (digitalRead (DHpin) == LOW);
// DHT11 80us after the bus pulled to start sending data
for (int i = 0; i < 4; i ++)
// receive temperature and humidity data, the parity bit is not considered
digitalWrite (DHpin, HIGH);
// send data once after releasing the bus, wait for the host to open the next Start signal
// convert the bit data to string form
//hum = String(dat[0]);
hum = “DATA_DATA-AN”;
//temp= String(dat[2]);
temp = “syalala”;
data = “?id=” + temp;
httppost();
esp.println(“AT+CIPSTART=\”TCP\”,\”” + server + “\”,80″);//start a TCP connection.
Serial.println(“TCP connection ready”);
“GET ” + uri + data + ” HTTP/1.0/\r\n”;
String sendCmd = “AT+CIPSEND=”;//determine the number of caracters to be sent.
esp.println(postRequest.length() );
if(esp.find(“>”)) { Serial.println(“Sending..”); esp.print(postRequest);
if( esp.find(“SEND OK”)) { Serial.println(“Packet sent”);
while (esp.available()) {
String tmpResp = esp.readString();
esp.println(“AT+CIPCLOSE”);
Buuut, I didn’t know somehow if we send it with serial software, we can’t make it automated. This is the result from serial monitor
Actually, we can connect it to ESP8266. But it looks like the data keep sent by itself, but we got no response. Let’s take a look on the server log.
It looks like ESP8266 spam our server. I guess that is for now.