Electrovalvula Proyecto
Electrovalvula Proyecto
Electrovalvula Proyecto
int8_t answer;
int onModulePin= 2; // SUBE LOS DATOS AL SERVIDOR
char data[512];
int data_size;
char aux_str[100];
char aux;
int x = 0;
char pin[]="1111";
char apn[]="claro.com.ec";
char user_name[]="jony";
char password[]="jony.321";
char url[ ]="http://medidor.enjambre.ec/api/medicion/0924638469/300.6/";
/***********************************************************************/
// DECLARACION DE FUNCIONES
int funcion_valvula(int buttonValvula, int electrovalvula);
int funcion_sensorFlujo(int litros_Hora);
/****************************************************************************/
//FUNCIONES
int funcion_valvula(int buttonValvula, int electrovalvula) {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonValvula);
uint8_t answer=0;
return answer;
}
delay(100);
x = 0;
previous = millis();
// this loop waits for the answer
do{
if(Serial.available() != 0){
response[x] = Serial.read();
x++;
// check if the desired answer 1 is in the response of the module
if (strstr(response, expected_answer1) != NULL)
{
answer = 1;
}
// check if the desired answer 2 is in the response of the module
if (strstr(response, expected_answer2) != NULL)
{
answer = 2;
}
}
// Waits for the asnwer with time out
}while((answer == 0) && ((millis() - previous) < timeout));
return answer;
}
/
***********************************************************************************
********************/
/
***********************************************************************************
********************/
//PROGRAMA EN DESARROLLO
void setup() {
// para la electrovalvula
pinMode(electrovalvula, OUTPUT);
pinMode(buttonValvula, INPUT);
pinMode(onModulePin, OUTPUT);
Serial.begin(115200);
delay(3000);
delay(3000);
void loop()
{
// Inicializa el servidor http
answer = sendATcommand("AT+HTTPINIT", "OK", 10000);
if (answer == 1)
{
// ajuste del parametro CID
answer = sendATcommand("AT+HTTPPARA=\"CID\",1", "OK", 5000);
if (answer == 1)
{
// Ajuste de url
snprintf(aux_str, sizeof(aux_str), "AT+HTTPPARA=\"URL\",\"%s\"", url);
answer = sendATcommand(aux_str, "OK", 5000);
if (answer == 1)
{
// EMPEZAR LA ACCION GET
answer = sendATcommand("AT+HTTPACTION=0", "+HTTPACTION:0,200", 10000);
if (answer == 1)
{
x=0;
do{
sprintf(aux_str, "AT+HTTPREAD=%d,100", x);
if (sendATcommand2(aux_str, "+HTTPREAD:", "ERROR", 30000) == 1)
{
data_size = 0;
while(Serial.available()==0);
aux = Serial.read();
do{
data_size *= 10;
data_size += (aux-0x30);
while(Serial.available()==0);
aux = Serial.read();
}while(aux != 0x0D);
if (data_size > 0)
{
while(Serial.available() < data_size);
Serial.read();
else
{
Serial.println("Descarga finalizada\n");
}
}
else if (answer == 2)
{
Serial.println("Error desde el HTTP");
}
else
{
Serial.println("No hay datos disponibles\n");
data_size = 0;
}
delay(5000);
}