#include #include #include #include #include extern "C" { #include "user_interface.h" #include "spi_flash.h" } // ************************************************************** // Este arquivo precisa ser editado colocando a senha na linha 91 // ************************************************************** const char* host = "OTA-LEDS"; const int led_pin = 2; ESP8266WebServer server(80); char value_str[10]; uint8_t cachaca() { // http://labarc.dsc.ufcg.edu.br/loac/index.php?n=OAC.ESP12#cachaca register uint8_t now, prev=1, value=0; for(register uint8_t i=0; i<200; i++) { now = digitalRead(12); value += now ^ prev; prev = now; } return value; } void handleRoot() { // http://OTA-LEDS.local/?led=0 switches the blue LED off // http://OTA-LEDS.local/?led=100 switches the blue LED completely on if( server.args() == 1 && server.argName(0) == "led" ) analogWrite(led_pin, 100 - atoi(server.arg(0).c_str())); char tempo[40]; int sec = millis() / 1000; int min = sec / 60; int hr = min / 60; snprintf ( tempo, 40, "ESP12 Uptime: %02d:%02d:%02d",hr, min % 60, sec % 60); itoa(cachaca(), value_str, 10); server.send(200, "text/plain", String(tempo) + " value=" + String(value_str)); } void handleNotFound(){ String message = "File Not Found\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET)?"GET":"POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for (uint8_t i=0; i next_time ) { Serial.print("Connecting to Labarc "); // Use WiFiClient class to create TCP connections WiFiClient client; if (!client.connect("labarc.ufcg.edu.br", 80)) { Serial.println("connection failed"); return; } itoa(cachaca(), value_str, 10); Serial.print("\n\rRequesting URL: "); // This will send the request to the server client.print(String("GET ") + "/php/?name=ESP12&data=" + value_str + " HTTP/1.0\r\n\r\n"); delay(500); // Read all the lines of the reply from server and print them to Serial while(client.available()){ String line = client.readStringUntil('\r'); Serial.print(line + "\r"); } Serial.println(); Serial.println("closing connection"); next_time += SEND_INTERVAL; } }