void setup()
{
int status;
Serial.begin(9600);
pinMode(2, INPUT);
attachInterrupt(0, incpulso, RISING);
// To turn the MG2639 shield on, and verify communication
// always begin a sketch by calling cell.begin().
status = esp8266.begin();
if (status <= 0)
{
Serial.println(F("Unable to communicate with shield. Looping"));
while(1) ;
}
esp8266.setMode(ESP8266_MODE_STA); // Set WiFi mode to station
if (esp8266.status() <= 0) // If we're not already connected
{
if (esp8266.connect(mySSID, myPSK) < 0)
{
Serial.println(F("Error connecting"));
while (1) ;
}
}
// Get our assigned IP address and print it:
Serial.print(F("My IP address is: "));
Serial.println(esp8266.localIP());
}
void loop()
{
postToPhant();
delay(50000);
}
void postToPhant()
{
// Create a client, and initiate a connection
ESP8266Client client;
float myip = esp8266.localIP();// ip arduino
if (client.connect(phantServer, 80)<=0 )
{
Serial.println(F("Failed to connect to server."));
return;
}
sensor = fluxo();
///Serial.println("Connected.");
String url = "/arduino/";
url += "salvardados.php?";
url += "sensor=";
url += sensor;
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + phantServer + "\r\n" +
"Connection: close\r\n\r\n");
Serial.println(F("Posting to Phant!"));
if (client.connected())
client.stop(); // stop() closes a TCP connection.
}
float fluxo ()
{
for (int x=0; x<4; x++)
{
contaPulso = 0; //Zera a variável para contar os giros por segundos
sei(); //Habilita interrupção
delay (1000); //Aguarda 1 segundo
cli(); //Desabilita interrupção
vazao = contaPulso / 5.5; //Converte para L/min
media = media+vazao; //Soma a vazão para o calculo da media
i++;
Serial.print(vazao); //Imprime na serial o valor da vazão
Serial.println(" L/min - "); //Imprime L/min
Serial.print(i); //Imprime a contagem i (segundos)
Serial.println("s"); //Imprime s indicando que está em segundos
if(i==4)
{
return media;
}
}
}
void incpulso ()
{
contaPulso++; //Incrementa a variável de contagem dos pulsos
}
thanks for help