Arduino - metodo get http

 
Vista:
sin imagen de perfil

metodo get http

Publicado por anabel (1 intervención) el 06/05/2017 17:09:37
Hola gente, necesito de su generosa ayuda, tengo una estacion meteorologica con arduino y el mismo envia los datos a un localhost...hasta ahi funciono perfecto, pero ahora lo que necesito es que me los envie a un host remoto y no logro que me los envie... la rutina php funciona correctamente, lo que no funciona es desde el arduino.
Desde ya agradezco cualquier ayuda

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <Ethernet.h>
#include <SPI.h>
char                 databuffer[35];
double               temp;
long intervalo =10000;   //300000 es el tiempo de nuestro delay   5 minutos     
long tiempo = 0;
long tiempoAnterior = 0;
boolean bandera=1;
 
// Configuracion del Ethernet Shield
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
 
// arduino
IPAddress ip(192,168,1,101);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress servidor_dns(200,58,112,193);
 
// Inicializa la instancia client
EthernetClient client;
 
// Direccion del servidor
byte server[] = { 200,58,110,76 };
//char server[] = "http://cmcens451.com/";
 
int Direccion;
float velocidad;
float velMax;
float temperatura;
float OneHour;
float OneDay;
float presion;
int humedad,i;
 
 
//String envioDatos = "GET /estacion/carga.php?";
String envioDatos = "GET /cmcens451.com/carga2.php?";
#define parametro1 "&WindDirection="
#define parametro2 "&WindSpeedAverage="
#define parametro2 "&WindSpeedMax="
#define parametro3 "&Temperature="
#define parametro4 "&RainfallOneHour="
#define parametro5 "&BarPressure="
#define parametro6 "&Humidity="
#define parametro7 "&RainfallOneDay="
 
 
void getBuffer()                                                                    //Get weather status data
{
  int index;
  for (index = 0;index < 35;index ++)
  {
    if(Serial.available())
    {
      databuffer[index] = Serial.read();
      if (databuffer[0] != 'c')
      {
        index = -1;
      }
    }
    else
    {
      index --;
    }
  }
}
 
int transCharToInt(char *_buffer,int _start,int _stop)                               //char to int)
{
  int _index;
  int result = 0;
  int num = _stop - _start + 1;
  int _temp[num];
  for (_index = _start;_index <= _stop;_index ++)
  {
    _temp[_index - _start] = _buffer[_index] - '0';
    result = 10*result + _temp[_index - _start];
  }
  return result;
}
 
int WindDirection()                                                                  //Wind Direction
{
  return transCharToInt(databuffer,1,3);
}
 
float WindSpeedAverage()                                                             //air Speed (1 minute)
{
  temp = 0.44704 * transCharToInt(databuffer,5,7);
  return temp;
}
 
float WindSpeedMax()                                                                 //Max air speed (5 minutes)
{
  temp = 0.44704 * transCharToInt(databuffer,9,11);
  return temp;
}
 
float Temperature()                                                                  //Temperature ("C")
{
  temp = (transCharToInt(databuffer,13,15) - 32.00) * 5.00 / 9.00;
  return temp;
}
 
float RainfallOneHour()                                                              //Rainfall (1 hour)
{
  temp = transCharToInt(databuffer,17,19) * 25.40 * 0.01;
  return temp;
}
 
float RainfallOneDay()                                                               //Rainfall (24 hours)
{
  temp = transCharToInt(databuffer,21,23) * 25.40 * 0.01;
  return temp;
}
 
int Humidity()                                                                       //Humidity
{
  return transCharToInt(databuffer,25,26);
}
 
float BarPressure()                                                                  //Barometric Pressure
{
  temp = transCharToInt(databuffer,28,32);
  return temp / 10.00;
}
 
void setup()
{
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
      }
}
void loop()
{
 
     tiempo = millis();
 
      if(tiempo - tiempoAnterior > intervalo)
      {
 
      tiempoAnterior = tiempo;
      getBuffer();
      Serial.print("Wind speed: ");
      Serial.print(WindSpeedMax());
      Serial.print("Wind Direction: ");
      Serial.print(WindDirection());
      Serial.println("  ");
      Serial.print("Average Wind Speed (One Minute): ");
      Serial.print(WindSpeedAverage());
      Serial.println("m/s  ");
      Serial.print("Rain Fall (One Hour): ");
      Serial.print(RainfallOneHour());
      Serial.println("mm  ");
      Serial.print("Temperature: ");
      Serial.print(Temperature());
      Serial.println("C  ");
      Serial.print("Humidity: ");
      Serial.print(Humidity());
      Serial.println("%  ");
      Serial.print("Barometric Pressure: ");
      Serial.print(BarPressure());
      Serial.println("hPa");
      Serial.println("");
      Serial.println("");
 
      Direccion = WindDirection();
      velocidad=WindSpeedAverage();
      temperatura=Temperature();
      OneHour=RainfallOneHour();
      presion=BarPressure();
      humedad = Humidity();
      velMax = WindSpeedMax();
      OneDay =RainfallOneDay();
 
 
 
    Serial.println("Conectando...");
 
      if (client.connect(server, 80)>0) {  // Conexion con el servidor 
 
 
          envioDatos +=  parametro1 + String(Direccion) + parametro2  + String(velocidad)+ parametro3  + String(temperatura) +  parametro4  + String(OneHour) + parametro5 +  String(presion) + parametro6 +  String(humedad) + parametro7  + String(velMax);
          client.print(envioDatos);
 
 
          client.println(" HTTP/1.0");
          client.println("User-Agent: Arduino 1.0");
          client.println();
           Serial.println("Conectado");
 
       } else {
          Serial.println("Fallo en la conexion");
       }
 
         if (!client.connected()) {
             Serial.println("Desconectando!");
        }
        client.stop();
        client.flush();
 
//delay (300000);
 
   }
  }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder