- Thu Mar 03, 2016 9:31 am
#42313
martinayotte wrote:What do you mean ?
Serial class provide Serial.available() to figure out if RX buffer has something to read, if it is the case, simply do Serial.read() to read the character one by one and place it into you own buffer for processing.
If the source of the RX is an Arduino board, beware that you need voltage divider to drop the 5V to 3V of the ESP.
I send data from an uno board with this program. so every 5 seconds, the arduino board transmits sensor reading.
int sensorPin =0;
int sensorValue = 0;
int sensorValue2 = 0;
void setup(){
Serial.begin(115200);
pinMode(sensorPin,INPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
sensorValue2=map(sensorValue,0,720,0,100);
if(sensorValue2>100)
{
sensorValue2=100;
}
Serial.println(sensorValue2);
delay(5000);
}
To receive the signal, i tried using this code on an esp8266-1. this is just a basic webserver page to display the sensor reading but the values it displays does not coincide with the values sent by the uno board.
#include <ESP8266WiFi.h>
const char* ssid = "pistinani";
const char* password = "redled01";
int value;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
// Connect to WiFi network
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");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
if(Serial.available()>0){
value = Serial.read();
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connetion: close");
client.println("Refresh: 5");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("Soil moisture: ");
client.print(value);
client.println("<br><br>");
client.println("Automatic drip irrigation<br><br>");
client.println("</html>");
delay(1);
client.stop();
Serial.println("Client disonnected");
Serial.println("");
}