Created
April 22, 2019 14:26
-
-
Save TheMagicSmoke/467d6227d670697464038056e22f302d to your computer and use it in GitHub Desktop.
Esp8266 Code
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> | |
char ssid[] = "demowifi"; // network SSID (name) | |
char pass[] = "demowifi"; // network password | |
//serial comm variables | |
uint8_t dataToSend = 0; | |
char dataFromAtmega[30]; | |
WiFiServer server(80); | |
void setup() { | |
Serial.begin(9600); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(ssid, pass); | |
while (WiFi.status() != WL_CONNECTED){ | |
delay(500);} | |
server.begin(); | |
} | |
void commWithAtmega(){ | |
Serial.print(dataToSend); | |
while(!Serial.available()); | |
if(Serial.available()) | |
Serial.readBytesUntil('#',dataFromAtmega,30); //reads the input until "#" and stores it in the data array. | |
} | |
void loop() { | |
WiFiClient client = server.available(); | |
if (client) | |
{ | |
if (client.connected()) | |
{ | |
delay(10); | |
if(client.available()) | |
{ | |
dataToSend = client.parseInt(); | |
client.flush(); | |
commWithAtmega(); | |
client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n")); | |
client.println(dataFromAtmega); | |
} | |
} | |
delay(1); | |
client.stop(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment