Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Esp8266 code (Modified)
#include <ESP8266WiFi.h>
#include "ESP8266WebServer.h"
char ssid[] = "demowifi"; // network SSID (name)
char pass[] = "demowifi"; // network password
//serial comm variables
uint8_t dataToSend = 0;
char dataFromAtmega[30];
ESP8266WebServer server(80);
String dataFromRequest = "";
void setup() {
Serial.begin(9600); //serial comm initialized
WiFi.mode(WIFI_STA); //esp01 initialized in station mode
WiFi.begin(ssid, pass); //connect to internet via WiFi
while (WiFi.status() != WL_CONNECTED){
delay(500);}
server.onNotFound(handleHttpRequest);
server.begin();
}
void handleHttpRequest(){
dataFromRequest = server.uri(); //the data that comes with the GET request . Format : "/(number)"
dataFromRequest.remove(0,1); // deleting the '/' from the data for converting string to integer
dataToSend = dataFromRequest.toInt(); // string to int conversion
//serial communication between Atmega328p and Esp01
Serial.print(dataToSend);
while(!Serial.available());
if(Serial.available())
Serial.readBytesUntil('#',dataFromAtmega,30); //reads the input until "#" and stores it in the data array.
//response and data sent to client
server.send(200,"text/plain",dataFromAtmega);
}
void loop() {
server.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.