Last active
April 23, 2019 09:05
-
-
Save TheMagicSmoke/adaae1e4d92f258c88184c8690e68f08 to your computer and use it in GitHub Desktop.
Esp8266 code (Modified)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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