Serial Communicaton between Atmega and ESP
Posted: Sun Aug 23, 2015 3:57 am
Hello together,
I'm playing arround with ESP modules and got stucked at a actually easy task:
I wand to adjust settings through a Website hosted by ESP and send these to an Atmega Chip. For basic tesing I'm using an Arduino Nano, later on I want to use a Atmega1284 programmed by Atmel Studio.
So let me explain it with a lil Example:
The website should adjust an RTC connected to Arduino I2C lines. The user calls the Website, ESP asks Arduino for current time, displays this on website, user adjust time and hit Save, ESP sends new time to Arduino and this one saves it in RTC.
First user calls site and ESP Asks for time:
Arduino Code:
This is just to explain. Later on they will be all json encoded and way more logig to handle all kinds of requests. But I'm stucked at the part where ESP sends something over Serial and waits for the complete answer to parse this on the Website. Here is a complete Example where ESP is listen to Serial Monitor to parse the typed in time:
I hope someone can point out my mistake...
Greetings
I'm playing arround with ESP modules and got stucked at a actually easy task:
I wand to adjust settings through a Website hosted by ESP and send these to an Atmega Chip. For basic tesing I'm using an Arduino Nano, later on I want to use a Atmega1284 programmed by Atmel Studio.
So let me explain it with a lil Example:
The website should adjust an RTC connected to Arduino I2C lines. The user calls the Website, ESP asks Arduino for current time, displays this on website, user adjust time and hit Save, ESP sends new time to Arduino and this one saves it in RTC.
First user calls site and ESP Asks for time:
Code: Select all
// in Setup
server.on("/clock", setTime);
void setTime() {
// Send request to Arduino
Serial.println("req:time");
// Wait for Respond
char s_read;
while (Serial.available()) {
s_read += (char)Serial.read();
}
server.send(200, "text/html", s_read );
}
Arduino Code:
Code: Select all
void loop() {
if (stringComplete) {
if(inputString == "req:time"){
Serial.println(RTC.printTime());
inputString = "";
stringComplete = false;
}
}
This is just to explain. Later on they will be all json encoded and way more logig to handle all kinds of requests. But I'm stucked at the part where ESP sends something over Serial and waits for the complete answer to parse this on the Website. Here is a complete Example where ESP is listen to Serial Monitor to parse the typed in time:
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char *ssid = "ESP_TEST";
ESP8266WebServer server(80);
void handleRoot() {
Serial.println("type in time");
char s_read;
while (Serial.available()) {
s_read += (char)Serial.read();
}
String site = "Time: ";
site += s_read;
server.send(200, "text/html", site);
}
void setup() {
delay(1000);
Serial.begin(115200);
WiFi.softAP(ssid);
IPAddress myIP = WiFi.softAPIP();
server.on("/", handleRoot);
server.begin();
}
void loop() {
server.handleClient();
}
I hope someone can point out my mistake...
Greetings