ARDUINO UNO + WIFI SHIELD + SENSOR ANALOGO + SENORES ON OFF

HOLA

Bueno como siempre en este mundo de DIY, no has terminado algo y ya estas apostandole a algo mas.
Aun no termino mi proyecto con los sensores omnicom, pero ya casi esta listo y pronto o compartire.
Aprovecho para nuevamente dar las gracias a surbyte, sin su ayuda desinteresada y gran cantidad de tiempo dedicado a mi proyecto, talvez no iria en este momento ni por la mitad.

Bueno no se si alguien ya lo tenga, pero en este momento tengo un sensor analogo y un par de sensores on/off (tipo switch magnetico) que quisiera enviar a una web con su base de datos para irlos almacenado e implementando.

El gran problema es que no se mucho de Web y DBs entonces no se cual sea la mejor alternativa, ni como crear el servicio web al que enviarle la informacion y obvio no tengo mucha idea de como hacer el cliente en el arduino.

he visto varios ejemplos usando POST e incluso JSON, pero si es asi, como deberia configurar mi db para que reciba mis datos del arduino?

si alguien me puede hechar una mano con un ejemplo simple, pero desde ambos frentes desde el client en arduino y desde la DB en el servidor.

Saludos...

Yo estoy haciendo una cosa parecida.... quiero ir almacenando en una base de datos las temperaturas recogidas con un sensor de temperatura en un Arduino Uno.

Yo utilizo el módulo wifi HLK-RM04 que es bastante barato y no es muy complicado de configurar y de programar en Arduino.

En el PC tendrás que tener un servidor web, un intérprete php y base de datos (yo utilizo Mysql). Te lo puedes instalar por separado o con aplicaciones que te lo instalan todo a la vez, dependiendo del sistema operativo que utilices (linux o win) hay varias, como por ejemplo XAMPP

El procedimiento sería el siguiente:

  • En el script de arduino leo la temperatura y creo un página web muy simple (el único dato que contendría es el valor de la temperatura).
  • En el PC tengo otra página web, que mediante json, ajax, o jquery, recoge ese valor y lo introduce en un campo text de un formulario.
  • En este formulario, con javascript, con el evento OnSubmit, se manda este valor cuando este campo text tiene un valor.
  • Bien, ya tenemos una variable en el pc con el valor de la temperatura. Habiendo creado una base de datos al efecto introducimos ese valor en el campo correspondiente.

No se si habrá otra manera de hacerlo, pero esa es la que se me ha ocurrido a mi.

Saludos

Hola chujalt.

No entiendo muy bien, tienes tu Arduino como un web server?
Y el PC como Cliente de tu Arduino?

Si es asi no me sirve pues voy a tener el Arduino remotamente y son varios y no puedo asignarles IP fijas para convertirlos en Servers.

Yo necesito que mi Arduino sea el Client.

Bueno la verdad muy atrevido yo por refutarte pues soy 0 en el tema, si estoy equivocado por favor hazmelo saber.

mira la verdad lo que quisiera hacer es enviar lo siguiente:

"ID": "123456789012345",
"Fecha_Evento": "2015-06-01 13:45:07",
"Latitud": "1151551",
"Longitud": "7251555",
"Nivel": "12.6",
"Nivel_Unit": "mm",
"Ign_Pwr": "True",
"Sensor1": "True",
"Sensor2": "True",
"Sensor3": "False"

Puse unos valores de ejemplo

Un amigo me creo un servicio web que recibe esta trama JSON y funciona perfecto simulandolo con el RESTCLIENT, sube la trama perfecto.

Pero no he podido hacer que la trama suba desde el ARDUINO.

Alguna ayuda?

Sería interesante que pongas el código de tu programa para saber el contexto de lo que quieres enviar. En principio lo podrías hacer con uno o varios sprintf, recordando escapar todas las comillas que quieres enviar.

Hola Noter

Gracias por responder

Tienes la razon aunque mi sketch de verdad da pena pero bueno de algo se debe partir...mejor que de 0s.

#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiClient.h>
#include <LGPS.h>


#define WIFI_AP "MI RED"          
#define WIFI_PASSWORD "MI CLAVE."  
#define WIFI_AUTH LWIFI_WPA  

gpsSentenceInfoStruct info;
char buff[256];
char action[] = "POST";
char server[] = "serversql.distracom.com.co";
char path[] = "/FCIndustryServices/api/EventoGPS";
int port = 80;
String var;
String IMEI = "355675061007043";  //ESTE VALOR DEPENDE DE CADA TARJETA, LO USO COMO ID
String Nivel_Unit = "mm";//este valor tambien es fijo
int sensorPin = A0;    // Entrada para el sensor
float sensorValue = 0;  // variable para almacenar el valor del sensor
int ign = 4;//sensores tipo open-close
int sen1 = 7;
int sen2 = 8;
int sen3 = 12;
unsigned int valorIG;
unsigned int valorS1;
unsigned int valorS2;
unsigned int valorS3;
String pck;



static unsigned char getComma(unsigned char num,const char *str)
{
  unsigned char i,j = 0;
  int len=strlen(str);
  for(i = 0;i < len;i ++)
  {
     if(str[i] == ',')
      j++;
     if(j == num)
      return i + 1; 
  }
  return 0; 
}

static double getDoubleNumber(const char *s)
{
  char buf[10];
  unsigned char i;
  double rev;
  
  i=getComma(1, s);
  i = i - 1;
  strncpy(buf, s, i);
  buf[i] = 0;
  rev=atof(buf);
  return rev; 
}

static double getIntNumber(const char *s)
{
  char buf[10];
  unsigned char i;
  double rev;
  
  i=getComma(1, s);
  i = i - 1;
  strncpy(buf, s, i);
  buf[i] = 0;
  rev=atoi(buf);
  return rev; 
}

void parseGPGGA(const char* GPGGAstr)
{
  /* Refer to http://www.gpsinformation.org/dale/nmea.htm#GGA
   * Sample data: $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
   * Where:
   *  GGA          Global Positioning System Fix Data
   *  123519       Fix taken at 12:35:19 UTC
   *  4807.038,N   Latitude 48 deg 07.038' N
   *  01131.000,E  Longitude 11 deg 31.000' E
   *  1            Fix quality: 0 = invalid
   *                            1 = GPS fix (SPS)
   *                            2 = DGPS fix
   *                            3 = PPS fix
   *                            4 = Real Time Kinematic
   *                            5 = Float RTK
   *                            6 = estimated (dead reckoning) (2.3 feature)
   *                            7 = Manual input mode
   *                            8 = Simulation mode
   *  08           Number of satellites being tracked
   *  0.9          Horizontal dilution of position
   *  545.4,M      Altitude, Meters, above mean sea level
   *  46.9,M       Height of geoid (mean sea level) above WGS84
   *                   ellipsoid
   *  (empty field) time in seconds since last DGPS update
   *  (empty field) DGPS station ID number
   *  *47          the checksum data, always begins with *
   */
  double latitude;
  double longitude;
  int tmp, hour, minute, second, num ;
  if(GPGGAstr[0] == '

Como ya dije anteriormente un ejemplo de la trama json que quiero enviar es:

{ "IMEI": "123456789012345",
"Fecha_Evento": "2015-06-01 13:45:07", //AUN NO SE DE DONDE LA VOY A SACAR.
"Latitud": "1151551",
"Longitud": "7251555",
"Nivel": "12.6",
"Nivel_Unit": "mm",
"Ign_Pwr": "True",
"Sensor1": "True",
"Sensor2": "True",
"Sensor3": "False"}

Si lo pruebas en el RESTCLIENT con POST y el servidor que esta en el Sketch, la trama sube bien al servidor, pero yo no consigo subirla...AGRADEZCO TODAS LAS AYUDAS DE ANTEMANO.

)
  {
    tmp = getComma(1, GPGGAstr);
    hour    = (GPGGAstr[tmp + 0] - '0') * 10 + (GPGGAstr[tmp + 1] - '0');
    minute  = (GPGGAstr[tmp + 2] - '0') * 10 + (GPGGAstr[tmp + 3] - '0');
    second    = (GPGGAstr[tmp + 4] - '0') * 10 + (GPGGAstr[tmp + 5] - '0');
   
    //sprintf(buff, "HORA LOCAL %2d-%2d-%2d", hour-5, minute, second);
    //Serial.println(buff);
   
   
      tmp = getComma(2, GPGGAstr);
      latitude = getDoubleNumber(&GPGGAstr[tmp]);
      String Latitud = latitude  //jajajajaja...obviamente esto no funciona y ademas no estoy seguro si sea lo correcto para enviar la data.
      //sprintf(buff,"latitud = %10.4f",latitude);
      //Serial.println(buff);
     
      tmp = getComma(4, GPGGAstr);
      longitude = getDoubleNumber(&GPGGAstr[tmp]);
      //sprintf(buff,"longitud = %10.4f",longitude);
      //Serial.println(buff);
   
    tmp = getComma(7, GPGGAstr);
    num = getIntNumber(&GPGGAstr[tmp]);   
    //sprintf(buff, "Cantidad de Satelites = %d", num);
  // Serial.println(buff);
  }
  else
  {
    Serial.println("Not get data");
  }
}

void leernivel () {
  sensorValue = analogRead(sensorPin);  //Lee el valor del sensor
  //Serial.print("valor del sensor:");
  float Nivel = (sensorValue*5)/1023;
  //Serial.println(nivel);
  //delay(3000);
}

void leerONOFF (){
  valorIG=digitalRead(4);
  if (valorIG==LOW){
    String Ign_Pwr = "False";
  }else{
    String Ign_Pwr = "True";
  }
 
  valorS1=digitalRead(7);
  if (valorS1==LOW){
    String Sensor1 = "False";
  }else{
    String Sensor1 = "True";
  }
 
    valorS2=digitalRead(8);
  if (valorS2==LOW){
    String Sensor2 = "False";
  }else{
    String Sensor2 = "True";
  }
 
    valorS3=digitalRead(12);
  if (valorS3==LOW){
    String Sensor3 = "False";
  }else{
    String Sensor3 = "True";
  }
}

void setup() {
 
Serial.begin(115200);
LWiFi.begin();
LGPS.powerOn();
while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }
}

void loop() {
  LWiFiClient c;   
  while (!c.connect(server, 80))
  {
    Serial.println("retry connect");
    delay(100);
  }
  parseGPGGA((const char*)info.GPGGA);
  leernivel ();
  leerONOFF ();
 
  if (c.connect(server, port)){
   
    pck="{"IMEI":"+ IMEI +" , "Latitud":"+ Latitud +" , "Longitud":"+ longitude+" , "Nivel":"+ Nivel +" , "Nivel_Unit":" + Nivel_Unit +" , "Ign_Pwr":" + Ign_Pwr +" , "Sensor1":"+ Sensor1 +" , "Sensor2":"+ Sensor2 +" , "Sensor3":"+ Sensor3 +"}";
   
      Serial.print(action);                 
      Serial.print(path);                   
      Serial.println(" HTTP/1.1");
      Serial.println(F("Content-Type: application/json"));
      //c.print(F("Content-Length: "));
      //c.println(le);
      Serial.println();
      Serial.println(var);  // The payload defined above
      Serial.println();
      Serial.println((char)26);
     
     
      c.print(action);                 
      c.print(path);                   
      c.println(" HTTP/1.1");
      c.println(F("Content-Type: application/json"));
      //c.print(F("Content-Length: "));
      //c.println(le);
      c.println();
      c.println(var);  // The payload defined above
      c.println();
      c.println((char)26);
   
}


Como ya dije anteriormente un ejemplo de la trama json que quiero enviar es:

{ "IMEI": "123456789012345",
"Fecha_Evento": "2015-06-01 13:45:07", //AUN NO SE DE DONDE LA VOY A SACAR.
"Latitud": "1151551",
"Longitud": "7251555",
"Nivel": "12.6",
"Nivel_Unit": "mm",
"Ign_Pwr": "True",
"Sensor1": "True",
"Sensor2": "True",
"Sensor3": "False"}

Si lo pruebas en el RESTCLIENT con POST y el servidor que esta en el Sketch, la trama sube bien al servidor, pero yo no consigo subirla...AGRADEZCO TODAS LAS AYUDAS DE ANTEMANO.

Buuufff....

Como ya te dije yo utilizo el módulo wifi HLK-RM04, que es bastante fácil de configurar y barato, unos 5 € comprado de china.

Lo tengo como cliente, pero le he asignado una ip fija, 192.168.1.254.

Aquí te paso mi script, lo que hace es crear una paǵina web con un formulario con los valores que quiero que se envíen y que se autoejecuta al cargar la página. Al poner en el navegador del pc la dirección 192.168.1.254:8080, recibe ese form que se autoejecuta y se dirige a una página que carga los valores a una base de datos, esta misma página despues de cargar los datos en la DB espera 1 minuto y vuelve a conectar con arduino.

El script es muy básico, lo único que tengo conectado es un sensor de humedad y temperatura DHT11

//Se envian a una página WEB los valores analógicos y datos de sensor DHT11

#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(57600);
dht.begin();
}

void loop() {
boolean has_request = false;
int h = dht.readHumidity(); int t = dht.readTemperature();
if (Serial.available()) {
while(Serial.available()) {char c = Serial.read();}
has_request = true;
}
if (has_request) {
Serial.println("HTTP/1.1 200 OK");
Serial.println("Content-Type: text/html");
Serial.println("Connection: close");
String sr = "\n";
sr += "\n";
sr += "Humedad: ";
sr += h;
sr += (" %\t");
sr += "
\n";
sr += "Temperatura: ";
sr += t;
sr += (" &#186C ");
sr += "
\n";
sr += "<form name="formulario" action="http://localhost/arduino/wifi/temperatura/intro.php\" method="post">";
sr += " <input type="hidden" name="humedad" value="";
sr += h;
sr += "" />";
sr += "
";
sr += " <input type="hidden" name="temperatura" value="";
sr += t;
sr += "" />";
sr += "
";
sr += "";
sr += "";
sr += "";
Serial.print("Content-Length: ");
Serial.print(sr.length());
Serial.print("\r\n\r\n");
Serial.print(sr);
has_request = false;
}
}

Hola Chujalt

Como te dije no puedo poners IPs fijas, lo que necesito es lo contrario, o sea que mi Arduino sea el Cliente, y suba la info a un servidor remoto.

Bueno. Yo la cadena la montaría así, partiendo de variables "naturales" de arduino.

char *imei = "123456789012345";
struct {
	int year;
	byte month;
	byte day;
	byte hour;
	byte minute;
	byte second;
} curDate = {2015, 6, 10, 23, 10, 00};
long latitud = 1151551;
long longitud = 7251555;
int nivel = 1260; // Este valor lo entenderemos como 12.60. Así nos evitamos trabajar con float y sus "aberraciones"
char * nivel_unit = "mm";
bool Ign_Pwr = true;
bool Sensor1 = true;
bool Sensor2 = true;
bool Sensor3 = false;

char bufferLinea[50];


void setup()
{
	Serial.begin(9600);
	sprintf(bufferLinea, "\"Imei\":\"%s\",", imei);
	Serial.println(bufferLinea);
	sprintf(bufferLinea, "\"Fecha_Evento\":\"%04d-%02d-%02d %02d:%02d:%02d\",", 
		curDate.year, curDate.month, curDate.day, curDate.hour, curDate.minute, curDate.second );
	Serial.println(bufferLinea);
	sprintf(bufferLinea, "\"Latitud\":\"%lu\",", latitud );
	Serial.println(bufferLinea);
	sprintf(bufferLinea, "\"Longitud\":\"%lu\",", longitud );
	Serial.println(bufferLinea);
	sprintf(bufferLinea, "\"Nivel\":\"%03d.%02d\",", nivel/100, nivel%100 );
	Serial.println(bufferLinea);
	sprintf(bufferLinea, "\"Nivel_unit\":\"%s\",", nivel_unit);
	Serial.println(bufferLinea);
	sprintf(bufferLinea, "\"Ign_Pwr\":\"%s\",", (Ign_Pwr?"True":"False"));
	Serial.println(bufferLinea);
	sprintf(bufferLinea, "\"Sensor1\":\"%s\",", (Sensor1?"True":"False"));
	Serial.println(bufferLinea);
	sprintf(bufferLinea, "\"Sensor1\":\"%s\",", (Sensor1?"True":"False"));
	Serial.println(bufferLinea);
	sprintf(bufferLinea, "\"Sensor2\":\"%s\",", (Sensor2?"True":"False"));
	Serial.println(bufferLinea);
	sprintf(bufferLinea, "\"Sensor3\":\"%s\"}", (Sensor3?"True":"False"));
	Serial.println(bufferLinea);
}

void loop()
{
	
}

Creo que sale bastante parecido a lo que dices.

Hola Noter

Gracias por la ayuda...ya mismo me pongo a revisar y tratar de entender, porque los sprintf son nuevos para mi, jejejeje...de hecho no los comprendo mucho, sobre todo los atributos que pones con %.

Bueno mientras igual pongo un sketch que casi me genera todo por ahora (no quiere decir que sea el valido o este todo ok) sino que al menos ya visualizo toda la info junta, excepto la fecha y el reloj que no se de donde sacarlos (bueno el GPS me puede dar el UTC pero no la fecha)

El hecho es que aun no se como subirlos al server, si pueden ver; el se alcanza a conectar a conectar a la web por el puerto 80 y luego comienza a enviar info pero no se si lo estoy haciendo bien:

a continuacion que me conecto al server le digo POST y le doy la ruta (eso lo he visto en otros ejemplos)
luego HTTP 1.1 (No se que tan util o necesario sea esto).
Luego el content type que es un JSON
a continuacion la data y finalmnete un char26 (tambien lo vi en otros ejemplos para json).

EN ESTA PARTE ES DONDE MAS DUDAS TENGO....COMO LE SUBO LA INFO AL SERVICIO WEB?

#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiClient.h>
#include <LGPS.h>


#define WIFI_AP "mi red wifi"          
#define WIFI_PASSWORD "mi clave de red wifi"  
#define WIFI_AUTH LWIFI_WPA  

gpsSentenceInfoStruct info;
char buff[256];
char action[] = "POST";
char server[] = "serversql.distracom.com.co";
char path[] = "/FCIndustryServices/api/EventoGPS";
int port = 80;
String var;
String IMEI = "355675061007043";  //ESTE VALOR DEPENDE DE CADA TARJETA, LO USO COMO ID
String Nivel_Unit = "mm";//este valor tambien es fijo
int sensorPin = A0;    // Entrada para el sensor
float sensorValue = 0;  // variable para almacenar el valor del sensor
int ign = 4;//sensores tipo open-close
int sen1 = 7;
int sen2 = 8;
int sen3 = 12;
unsigned int valorIG;
unsigned int valorS1;
unsigned int valorS2;
unsigned int valorS3;
String pck;
double latitude;
double longitude;
double latitud;
double longitud;
int altura = 1500;
int Nivel;
String Ign_Pwr;
String Sensor1;
String Sensor2;
String Sensor3;



static unsigned char getComma(unsigned char num,const char *str)
{
  unsigned char i,j = 0;
  int len=strlen(str);
  for(i = 0;i < len;i ++)
  {
     if(str[i] == ',')
      j++;
     if(j == num)
      return i + 1; 
  }
  return 0; 
}

static double getDoubleNumber(const char *s)
{
  char buf[10];
  unsigned char i;
  double rev;
  
  i=getComma(1, s);
  i = i - 1;
  strncpy(buf, s, i);
  buf[i] = 0;
  rev=atof(buf);
  return rev; 
}

static double getIntNumber(const char *s)
{
  char buf[10];
  unsigned char i;
  double rev;
  
  i=getComma(1, s);
  i = i - 1;
  strncpy(buf, s, i);
  buf[i] = 0;
  rev=atoi(buf);
  return rev; 
}

void parseGPGGA(const char* GPGGAstr)
{
  /* Refer to http://www.gpsinformation.org/dale/nmea.htm#GGA
   * Sample data: $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
   * Where:
   *  GGA          Global Positioning System Fix Data
   *  123519       Fix taken at 12:35:19 UTC
   *  4807.038,N   Latitude 48 deg 07.038' N
   *  01131.000,E  Longitude 11 deg 31.000' E
   *  1            Fix quality: 0 = invalid
   *                            1 = GPS fix (SPS)
   *                            2 = DGPS fix
   *                            3 = PPS fix
   *                            4 = Real Time Kinematic
   *                            5 = Float RTK
   *                            6 = estimated (dead reckoning) (2.3 feature)
   *                            7 = Manual input mode
   *                            8 = Simulation mode
   *  08           Number of satellites being tracked
   *  0.9          Horizontal dilution of position
   *  545.4,M      Altitude, Meters, above mean sea level
   *  46.9,M       Height of geoid (mean sea level) above WGS84
   *                   ellipsoid
   *  (empty field) time in seconds since last DGPS update
   *  (empty field) DGPS station ID number
   *  *47          the checksum data, always begins with *
   */
  double latitude;
  double longitude;
  int tmp, hour, minute, second, num ;
  if(GPGGAstr[0] == '

)
  {
    tmp = getComma(1, GPGGAstr);
    hour    = (GPGGAstr[tmp + 0] - '0') * 10 + (GPGGAstr[tmp + 1] - '0');
    minute  = (GPGGAstr[tmp + 2] - '0') * 10 + (GPGGAstr[tmp + 3] - '0');
    second    = (GPGGAstr[tmp + 4] - '0') * 10 + (GPGGAstr[tmp + 5] - '0');
   
    //sprintf(buff, "HORA LOCAL %2d-%2d-%2d", hour-5, minute, second);
    //Serial.println(buff);
   
   
      tmp = getComma(2, GPGGAstr);
      latitude = getDoubleNumber(&GPGGAstr[tmp]);
      latitud = latitude;
      //String Latitud = latitude  //jajajajaja...obviamente esto no funciona y ademas no estoy seguro si sea lo correcto para enviar la data.
      //sprintf(buff,"latitud = %10.4f",latitude);
      //Serial.println(buff);
     
      tmp = getComma(4, GPGGAstr);
      longitude = getDoubleNumber(&GPGGAstr[tmp]);
      longitud = longitude;
      //sprintf(buff,"longitud = %10.4f",longitude);
      //Serial.println(buff);
   
    tmp = getComma(7, GPGGAstr);
    num = getIntNumber(&GPGGAstr[tmp]);   
    //sprintf(buff, "Cantidad de Satelites = %d", num);
  // Serial.println(buff);
  }
  else
  {
    Serial.println("Not get data");
  }
}

void leernivel () {
  sensorValue = analogRead(sensorPin);  //Lee el valor del sensor
  //Serial.print("valor del sensor:");
  Nivel = (sensorValue*altura)/1023;
  //Serial.println(nivel);
  //delay(3000);
}

void leerONOFF (){
  valorIG=digitalRead(4);
  if (valorIG==LOW){
    Ign_Pwr = "False";
  }else{
    Ign_Pwr = "True";
  }
 
  valorS1=digitalRead(7);
  if (valorS1==LOW){
    Sensor1 = "False";
  }else{
    Sensor1 = "True";
  }
 
    valorS2=digitalRead(8);
  if (valorS2==LOW){
    Sensor2 = "False";
  }else{
    Sensor2 = "True";
  }
 
    valorS3=digitalRead(12);
  if (valorS3==LOW){
    Sensor3 = "False";
  }else{
    Sensor3 = "True";
  }
}

void setup() {
 
Serial.begin(115200);
pinMode(ign, INPUT);
pinMode(sen1, INPUT);
pinMode(sen2, INPUT);
pinMode(sen3, INPUT);
LWiFi.begin();
LGPS.powerOn();
while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }
}

void loop() {
  LWiFiClient c;   
  while (!c.connect(server, 80))
  {
    Serial.println("retry connect");
    delay(100);
  }
  LGPS.getData(&info);
  //Serial.println((char*)info.GPGGA);
  parseGPGGA((const char*)info.GPGGA);
  leernivel ();
  leerONOFF ();
 
  if (c.connect(server, port)){
   
    pck="{"IMEI":"+ IMEI +" , "Latitud":"+ latitud +" , "Longitud":"+ longitud +" , "Nivel":"+ Nivel +" , "Nivel_Unit":" + Nivel_Unit +" , "Ign_Pwr":" + Ign_Pwr +" , "Sensor1":"+ Sensor1 +" , "Sensor2":"+ Sensor2 +" , "Sensor3":"+ Sensor3 +"}";
   
      Serial.print(action);                 
      Serial.print(path);                   
      Serial.println(" HTTP/1.1");
      Serial.println(F("Content-Type: application/json"));
      //c.print(F("Content-Length: "));
      //c.println(le);
      Serial.println();
      Serial.println(pck);  // The payload defined above
      Serial.println();
      Serial.println((char)26);
     
     
      c.print(action);                 
      c.print(path);                   
      c.println(" HTTP/1.1");
      c.println(F("Content-Type: application/json"));
      //c.print(F("Content-Length: "));
      //c.println(le);
      c.println();
      c.println(pck);  // The payload defined above
      c.println();
      c.println((char)26);
   
}
}

Alguien experto en WebClient que me ayude???

Lo primero ¿Te salen bien parseados los datos json por el serial? Revisa que sea así.

He buscado un poco por ahí, y tal vez esta función te pueda ayudar con unos pocos arreglos, o bien servirte de ayuda sobre lo que debes enviar. No la he probado, pues no he trabajado nunca json desde arduino, pero parece funcionar por lo que dicen en el hilo.

//   FUNCION: HTTPpost()   //
void updateHTTPPOST(String POSTdata)
{
  
  if (client.connect("server.com", 8086)) // Conexion a Servidor
  {
    Serial.println("--------------START POST-------------------------");
    // HTTP POST Headers
    client.print(F("POST /db/Test_Casa/series?u=root&p=XXXXXX HTTP/1.1\n"));  
    client.println(F("Host: server.com"));  
    client.print(F("User-Agent: Arduino/1.0\n"));  
    client.print(F("Connection: close\n"));
    client.print(F("Content-Type: application/x-www-form-urlencoded\n"));  
    client.print(F("Content-Length: "));
    client.print(POSTdata.length());
    client.print(F("\n\n"));  
          
    // HTTP POST Body
    client.print(POSTdata);
          Serial.print(POSTdata);
    
    lastConnectionTime = millis();

    // Chequeo POST con exito
    if (client.connected())
    {
      Serial.println(F("----------------FIN POST-------------------------"));
      failedCounter=0;
      
    } else {
      failedCounter++;
      Serial.println(F("Conexion con Servidor perdida"));
      Serial.println(String(failedCounter));
    }
    
  }
    else  
  {
     failedCounter++;
     Serial.println(F("No puedo Conectarme a Servidor"));
     Serial.print(F("Conexion perdida Num. "));
     Serial.println(String(failedCounter));
     lastConnectionTime = millis();
  }
}

Bueno chicos

Finalmente he logrado hechar a andar este proyecto, pero como electronico, creo que mi programacion es muyyyy burda, ya surbyte me lo habia hecho ver una vez y toda la razon, nosotros los electronicos no tenemos elegancia para programar.

Les comparto el sketch que esta alimentando mi base de datos(recuerden que es con una linkit one), he visto que ha mas gente le ha sucedido que funciona un rato y luego deja de enviar info...pues a mi me pasa lo mismo...SURBYTE...en algun lado vi que hablabas de la RAM...pero no se como va eso.

Lo tengo enviando cada minuto y una veces funciona por una hora y otros por 2, pero finalmente termina bloqueandose y me toca reiniciarlo para que vuelva y continue.

NOTER: me ayudas haciendo este codigo mas elegante?

/*
 * Proyecto Medicion de Tanques REMOTO
 * Diego Bonilla 
 * 
 * Junio 2015
 *
 * Hardware Linkit ONE SeedStudio
 * Sondas de Nivel Analogas Omnicomm
 *
 * No olvide Configurar:
 * WiFi_AP, WiFiPassword, la Altura de la sonda y el IMEI de la Tarjeta.
 */

#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiClient.h>
#include <LGPS.h>



#define WIFI_AP "MI RED WIFI"          
#define WIFI_PASSWORD "MI PASSWORD"  
#define WIFI_AUTH LWIFI_WPA  


gpsSentenceInfoStruct info;
char buff[256];
char action[] = "GET ";
char server[] = "idi.besaba.com"; //MI SERVER EN HOSTINGER SERVICIO GRATUITO
char path[] = "/registros/registros.php?Imei="; //MI BASE DE DATOS EN ESE SERVER

int port = 80;
String IMEI = "355675061106381";  //ESTE VALOR DEPENDE DE CADA TARJETA, LO USO COMO ID
int sensorPin = A0;     // Entrada para el sensor
float sensorValue = 0;  // variable para almacenar el valor del sensor
int ign = 4;            //sensores tipo open-close
int sen1 = 7;
int sen2 = 8;
int sen3 = 12;
unsigned int valorIG;
unsigned int valorS1;
unsigned int valorS2;
unsigned int valorS3;
double latitude;
double longitude;
int latitud;
int longitud;
int altura = 1500;
int Nivel;
String Ign_Pwr;
String Sensor1;
String Sensor2;
String Sensor3;
unsigned long time = 0;
unsigned long Temp1 = 0;
unsigned long Temp2 = 0;
unsigned long tiempo = 0;
String contador;

//int tiempo = 120;

LWiFiClient globalClient;  



static unsigned char getComma(unsigned char num,const char *str)
{
  unsigned char i,j = 0;
  int len=strlen(str);
  for(i = 0;i < len;i ++)
  {
     if(str[i] == ',')
      j++;
     if(j == num)
      return i + 1; 
  }
  return 0; 
}



static double getDoubleNumber(const char *s)
{
  char buf[10];
  unsigned char i;
  double rev;
  
  i=getComma(1, s);
  i = i - 1;
  strncpy(buf, s, i);
  buf[i] = 0;
  rev=atof(buf);
  return rev; 
}



static double getIntNumber(const char *s)
{
  char buf[10];
  unsigned char i;
  double rev;
  
  i=getComma(1, s);
  i = i - 1;
  strncpy(buf, s, i);
  buf[i] = 0;
  rev=atoi(buf);
  return rev; 
}


void parseGPGGA(const char* GPGGAstr)
{
  /* Refer to http://www.gpsinformation.org/dale/nmea.htm#GGA
   * Sample data: $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
   * Where:
   *  GGA          Global Positioning System Fix Data
   *  123519       Fix taken at 12:35:19 UTC
   *  4807.038,N   Latitude 48 deg 07.038' N
   *  01131.000,E  Longitude 11 deg 31.000' E
   *  1            Fix quality: 0 = invalid
   *                            1 = GPS fix (SPS)
   *                            2 = DGPS fix
   *                            3 = PPS fix
   *                            4 = Real Time Kinematic
   *                            5 = Float RTK
   *                            6 = estimated (dead reckoning) (2.3 feature)
   *                            7 = Manual input mode
   *                            8 = Simulation mode
   *  08           Number of satellites being tracked
   *  0.9          Horizontal dilution of position
   *  545.4,M      Altitude, Meters, above mean sea level
   *  46.9,M       Height of geoid (mean sea level) above WGS84
   *                   ellipsoid
   *  (empty field) time in seconds since last DGPS update
   *  (empty field) DGPS station ID number
   *  *47          the checksum data, always begins with *
   */
  double latitude;
  double longitude;
  int tmp, hour, minute, second, num ;
  if(GPGGAstr[0] == '

)
  {
    tmp = getComma(1, GPGGAstr);
    hour    = (GPGGAstr[tmp + 0] - '0') * 10 + (GPGGAstr[tmp + 1] - '0');
    minute  = (GPGGAstr[tmp + 2] - '0') * 10 + (GPGGAstr[tmp + 3] - '0');
    second    = (GPGGAstr[tmp + 4] - '0') * 10 + (GPGGAstr[tmp + 5] - '0');
      tmp = getComma(2, GPGGAstr);
      latitude = getDoubleNumber(&GPGGAstr[tmp]);
      latitud = latitude;

tmp = getComma(4, GPGGAstr);
      longitude = getDoubleNumber(&GPGGAstr[tmp]);
      longitud = longitude;
   
      tmp = getComma(7, GPGGAstr);
      num = getIntNumber(&GPGGAstr[tmp]);   
  }
  else
  {
    Serial.println("Not get data");
  }
}

void leernivel () {
  sensorValue = analogRead(sensorPin);  //Lee el valor del sensor
  Nivel = (sensorValue*altura)/1023;
}

void leerONOFF (){
  valorIG=digitalRead(4);//IGNICION
  if (valorIG==LOW){
    Ign_Pwr = "false";
  }else{
    Ign_Pwr = "true";
  }
 
  valorS1=digitalRead(7);//ALIMENTACION
  if (valorS1==HIGH){
    Sensor1 = "false";
  }else{
    Sensor1 = "true";
  }
 
    valorS2=digitalRead(8);//TAPA
  if (valorS2==LOW){
    Sensor2 = "false";
  }else{
    Sensor2 = "true";
  }
 
    valorS3=digitalRead(12);//INCLINACION
  if (valorS3==LOW){
    Sensor3 = "false";
  }else{
    Sensor3 = "true";
  }
}

void SendData () {
 
  if (globalClient.connect(server, port)){
      Serial.println("conectado");
      Serial.print(action);                 
      Serial.print(path);
      Serial.print(IMEI);
      Serial.print("&");
      Serial.print("latitud=");
      Serial.print(latitud1000);
      Serial.print("&");
      Serial.print("longitud=");
      Serial.print(longitud
1000);
      Serial.print("&");
      Serial.print("nivel=");
      Serial.print(Nivel);
      Serial.print("&");
      Serial.print("ign_pwr=");
      Serial.print(Ign_Pwr);
      Serial.print("&");
      Serial.print("sensor1=");
      Serial.print(Sensor1);
      Serial.print("&");
      Serial.print("sensor2=");
      Serial.print(Sensor2);
      Serial.print("&");
      Serial.print("sensor3=");
      Serial.print(Sensor3);
      Serial.println(" HTTP/1.1");
      Serial.print(F("Host: "));
      Serial.println(server);
      Serial.println();
      Serial.println();
     
      globalClient.print(action);                 
      globalClient.print(path);
      globalClient.print(IMEI);
      globalClient.print("&");
      globalClient.print("latitud=");
      globalClient.print(latitud1000);
      globalClient.print("&");
      globalClient.print("longitud=");
      globalClient.print(longitud
1000);
      globalClient.print("&");
      globalClient.print("nivel=");
      globalClient.print(Nivel);
      globalClient.print("&");
      globalClient.print("ign_pwr=");
      globalClient.print(Ign_Pwr);
      globalClient.print("&");
      globalClient.print("sensor1=");
      globalClient.print(Sensor1);
      globalClient.print("&");
      globalClient.print("sensor2=");
      globalClient.print(Sensor2);
      globalClient.print("&");
      globalClient.print("sensor3=");
      globalClient.print(Sensor3);
      globalClient.println(" HTTP/1.1");
      globalClient.print(F("Host: "));
      globalClient.println(server);
      globalClient.println();
      globalClient.println();
}
      globalClient.stop();
      globalClient.flush();
     
}

void setup() {
Serial.begin(19200);
pinMode(ign, INPUT);
pinMode(sen1, INPUT);
pinMode(sen2, INPUT);
pinMode(sen3, INPUT);
LGPS.powerOn();
while (!LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(500);
  }
  LWiFiClient client;   
  globalClient = client;
}

void loop() {
  Temp1=millis();
  LGPS.getData(&info);
  parseGPGGA((const char*)info.GPGGA);
  leernivel ();
  leerONOFF ();
  Serial.print("connect to:");  //Esto es solo para visualizar la conexion y ver el conteo.
  Serial.println(server);
  Serial.println(time);

if (time>=60000) {
    contador="true";
  }else{
    contador="false";
  }
 
  if (Ign_Pwr=="true" || Sensor1=="true" || Sensor2=="true" || Sensor3=="true" || contador=="true"){
    SendData();
    time=0;
  }
  if (contador=="false") {
    Temp2=millis();
    tiempo=Temp2-Temp1;
    time=time+tiempo;
  }
}

Sigue los consejos de Noter y mejorarás tu programación.
Te iba a dar una mano pero noter es mas capaz que yo por lejos en estos temas.
En otros no se jajaja..

Hola Ricardo

Claro que me interesan los consejos de NOTER, el es como dicen uds los argentinos muy prolijo, organizado y optimizador de los programas, en pocas palabras es un excelente programador.

Pero mi pregunta en este momento va encaminada a saber porque de un tiempo deja de enviar info...simplemente no envia mas, hasta que reinicie la placa...la reinicio y woilaaa, nuevamente comienza a enviarme a mi DB.

No se que pueda ser y no se si noter tenga la respuesta, por eso pido la ayuda en general.

Mil gracias

PD: El envia info a veces por 1:30 horas o casi 3:00 pero de ahi no pasa.

Alguna idea de alguien?

que puedo hacer?

Hola. Perdón por no responder antes. No ando sobrado de tiempo últimamente. De momento sólo he podido echar un vistazo somero a tu código y además no he sido capaz de compilar, al no disponer de las librerías. De momento lo primero que haría en tu lugar es quitar los string ign_pwr y sucesivos y sustituirlos por bool. En tus comparaciones posteriores usa true o false sin comillas. Los string son voraces consumidores de memoria.
Las constantes (por ejemplo los número de pin) decláralas con la palabra const delante.
Y monitoriza en tu loop la cantidad de memoria disponible. Si va bajando, ahí habrá que profundizar. Si, sencillamente es baja inicialmente, miraremos de guardar cosas en flash o EEPROM. Cuando pueda estar con ordenador en lugar de celular intento detallar más las cosas.
Saludos.

Hola Noter, gracias por tus fabulosas explicaciones, definitivamente tu y surbyte son mis mentores.

Creo entender todo, solo algo...no se como monitorear la memoria.

Yo tengo una idea.
Busca Arduino AvailableMemory en este foro y usa esa rutina para ver si te quedas sin RAM por alguna razón
Eso puede provocar que se cuelgue tu programa.

Gracias Surbyte...al rato la busco.

Por ahora me voy a ver jugar mi seleccion....COLOMBIAAAA.

Copia la función freeram e imprime en el loop su resultado ( Serial.print(freeRam()).
Si se mantiene estable bien; si va bajando... Ahí tienes tu cuenta atrás para auto destrucción.