Go Down

Topic: how to enter floating varibles in a chain or char  (Read 390 times) previous topic - next topic

yesidm93


good morning, I am trying to send data from sensors to a web page through a gsm module. I have a char variable in which I keep the sending string, in this string I can enter data manually but I can not link the variables in which I am saving the data issued by the sensors.

for example:

this is my char:

char direccion[] = "GET /XXXX/XXXX.php?valor=350&valor1=100\r\nHost: 190.XXX.XXX.XXX\r\nConnection: close\r\n\r\n";



there it prints in the database the values ​​that enter 350 and 100. but if instead of giving fixed values ​​I assign a variable already created as for example:

float temp;
float hum;

char direccion[] = "GET /XXXX/XXXX.php?valor=temp&valor1=hum\r\nHost: 190.XXX.XXX.XXX\r\nConnection: close\r\n\r\n";




just print "temp" and "hum" in my database, take the variable as if it were text. What is the correct way to cite the variable so that it recognizes the internal value that it has?


please help :o

Robin2

You have not posted your program so I can only guess that you are doing something like client.print(direccion);

You don't have to send the message as a single item for it to be received as a single message. You could do something like

Code: [Select]
client.print("GET /XXXX/XXXX.php?valor=");
client.print(temp);
client,print("&valor1=");
// etc


Apologies if I have got the client.print part wrong, but you should get the idea.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

yesidm93

#2
Feb 15, 2018, 03:37 pm Last Edit: Feb 15, 2018, 04:34 pm by yesidm93
I sent the information with AT commands because I did not find another way to send it to the database, the client print I used it to send to the database via ethernet but with the sim900 I could not use. the code I use is the following


#include <SoftwareSerial.h>
SoftwareSerial SIM900(10, 11); // Configura el puerto serial para el SIM900. Para el Arduino MEGA utilizar pines 10 y 11



char aux_str[50];
//Contenido de la dirección Http 






char direccion[] = "GET /xxxxxxxx/iot.php?valor=350&valor1=100\r\nHost: xxx.xxx.xxx.xxx\r\nConnection: close\r\n\r\n";

void setup()

{
  SIM900.begin(9600); //Configura velocidad del puerto serie para el SIM900
  Serial.begin(9600); //Configura velocidad del puerto serie del Arduino
  delay(1000);
  Serial.println("Iniciando...");
  iniciar();
}

void loop() {
 
 PeticionHttp();
delay(100);

  enviarAT("AT+CIPCLOSE", "CLOSE OK", 10000); //Cerramos la conexion
  enviarAT("AT+CIPSHUT", "OK", 10000); //Cierra el contexto PDP del GPRS
       
 delay(3000000);
}
int enviarAT(String ATcommand, char* resp_correcta, unsigned int tiempo)
{

  int x = 0;
  bool correcto = 0;
  char respuesta[100];
  unsigned long anterior;

  memset(respuesta, '\0', 100); // Inicializa el string
  delay(100);
  while ( SIM900.available() > 0) SIM900.read(); // Limpia el buffer de entrada
  SIM900.println(ATcommand); // Envia el comando AT
  x = 0;
  anterior = millis();
  // Espera una respuesta
  do {
    // si hay datos el buffer de entrada del UART lee y comprueba la respuesta
    if (SIM900.available() != 0)
    {
        respuesta
  • = SIM900.read();

        x++;
      // Comprueba si la respuesta es correcta
      if (strstr(respuesta, resp_correcta) != NULL)
      {
        correcto = 1;
      }
    }
  }
  // Espera hasta tener una respuesta
  while ((correcto == 0) && ((millis() - anterior) < tiempo));
  Serial.println(respuesta);

  return correcto;
}
void iniciar()
{
 
  Serial.println("Conectando a la red...");
  delay (5000);

  //Espera hasta estar conectado a la red movil
  while ( enviarAT("AT+CREG?", "+CREG: 0,1", 1000) == 0 )
  {
  }

  Serial.println("Conectado a la red.");
  enviarAT("AT+CGATT=1\r", "OK", 1000); //Iniciamos la conexión GPRS
  enviarAT("AT+CSTT=\"internet.comcel.com.co\",\"comcel\",\"comcel\"", "OK", 3000); //Definimos el APN, usuario y clave a utilizar
  enviarAT("AT+CIICR", "OK", 3000); //Activamos el perfil de datos inalámbrico
  enviarAT("AT+CIFSR", "", 3000); //Activamos el perfil de datos inalámbrico
}



void PeticionHttp()
{

 
  if (enviarAT("AT+CREG?", "+CREG: 0,1", 1000) == 1) //Comprueba la conexion a la red
  {
    if (enviarAT("AT+CREG?", "+CREG: 0,1", 1000) == 1) //Comprueba la conexion a la red
  {
    enviarAT("AT+CIPSTART=\"TCP\",\"xxx.xxx.xxx.xxx\",\"80\"", "CONNECT OK", 5000); //Inicia una conexión TCP
    // Envíamos datos a través del TCP
    Serial.println(aux_str);
    sprintf(aux_str, "AT+CIPSEND=%d", strlen(direccion));
    Serial.println(aux_str);
    if (enviarAT(aux_str, ">", 10000) == 1)
    {
      enviarAT(direccion, "OK", 10000);
    }
  }
  else
  {
    //reiniciar();
    //iniciar();
  }
}
}

Robin2

To make it easy for people to help you please modify your post and use the code button </>
Code: [Select]
so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

And you have not commented on the suggestion I made in Reply #1

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up