This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
CONSULTA Datos de Arduino a Base de datos.
#1
Muy buenas, estoy en un proyecto y he llegado a un punto que no paso de ahi, a ver si comentandolo  por aqui, podeis echarme una ano, gracias.

Lo primero , os pongo dos codigos:

Este es uno de los TX:

Código:
#include <SPI.h>
#include "RF24.h"
#include "RF24Network.h"
#include "RF24Mesh.h"
#include "DHT.h"          
RF24 radio(7,8);
RF24Network network(radio);
RF24Mesh mesh(radio,network);
#define nodeID 2        
#define NOMESHMASTER
#define dnt_pin 2          
DHT dht;    

struct dataOut {
   uint32_t nid;        
   float temp;
   float hum;
};
uint32_t sendTimer = 0;            
uint32_t sendInterval = 6000;      
void setup() {
   Serial.begin(115200);
   dht.setup(dnt_pin);
   mesh.setNodeID(nodeID);
   mesh.begin(72,RF24_250KBPS,30000);
   radio.setPALevel(RF24_PA_LOW);
   radio.printDetails();
   
}

void loop() {
   if (millis() - sendTimer >= sendInterval) {
       sendData();
       sendTimer = millis();
   }
}

void sendData() {
   float t = dht.getTemperature();                
   float h = dht.getHumidity();                    
   
   dataOut payload = {
       nodeID,
       t,
       h,
    };

   
   mesh.update();

 
   if ( !mesh.write(&payload,1,sizeof(payload),0) ) {    
       Serial.println("Envio Fallido");
       if ( !mesh.checkConnection() ) {          
           Serial.println("Renovando la Direccion");
           mesh.renewAddress();              
       } else {
           Serial.println("Envio Fallido, test ok");
       }
   } else {                    
       delay(5);
       Serial.println("Envio Correcto!!");      
   }
}


Este es el RX:

Código:
#include <SPI.h>
#include "RF24.h"
#include "RF24Network.h"
#include "RF24Mesh.h"
#include <Ethernet.h>
#define INTERWAL 3000
RF24 radio(7,8);
RF24Network network(radio);
RF24Mesh mesh(radio,network);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "xxxxxxxxxx.es";
EthernetClient client;
unsigned long tiempo_conexion = 0;

struct nodoIn {            
   uint32_t nid;        
   float temp;
   float hum;
};

void setup() {
   Serial.begin(115200);
   mesh.setNodeID(0);
   mesh.begin(72,RF24_250KBPS,30000);
   radio.setPALevel(RF24_PA_LOW);
   radio.printDetails();
   Serial.println("Estacion Base Lista");
   Ethernet.begin(mac);
}

void loop() {
   mesh.update();            
   mesh.DHCP();              

   while (network.available()) {        
       RF24NetworkHeader header;        
       network.peek(header);            

       nodoIn nodoData;        
       
       switch(header.type) {        

           case 1:      
           case 2:
               
               network.read(header,&nodoData,sizeof(nodoData));
               
               Serial.print("sensor:");
               Serial.print(nodoData.nid);
               Serial.print("temperatura:");
               Serial.print(nodoData.temp);
               Serial.print("humedad:");
               Serial.print(nodoData.hum);
               Serial.println(" ");
           break;

           default:
               Serial.println("Mensaje no Definido");
           break;
       }            
   }          
if (millis() - tiempo_conexion > INTERWAL) {

}
nodoIn nodoData;
RF24NetworkHeader header;        
       network.peek(header);
switch(header.type) {        

           case 1:      
           case 2:
               
               network.read(header,&nodoData,sizeof(nodoData));
client.stop();
if (client.connect(server, 80)) {
client.print("GET /insertar.php?");
client.print("&sensor1=");
client.print(nodoData.nid);
client.print("&temperatura1=");
client.print(nodoData.temp);
client.print("&humedad1=");
client.print(nodoData.hum);
client.print("&sensor2=");
client.print(nodoData.nid);
client.print("&temperatura2=");
client.print(nodoData.temp);
client.print("&humedad2=");
client.print(nodoData.hum);
client.println(" HTTP/1.1");
client.println("Host: xxxxxxx.es");
client.println("Connection: close");
client.println();
tiempo_conexion = millis();

}
}
}


El problema que tengo, es que en la base de datos , no me entra bien los valores, o bien me coge los del TX1 o los del TX2 , pero no los diferencia, viendo en el monitor serial , si se diferencia bien:

[Imagen: 788f8fde3316de54011d449de84f1fdd.png]

Pero viendo el log de mi base de datos, se puede apreciar que los datos no estan bien:

[Imagen: dd4d3a49b87909f70b9a2654bf14a712.png]

Como se puede observar, en sensor1=2(el TX2) pero en sensor2=2 , osea el mismo , despues de unas lineas entra el TX1 y asi , pero no los diferencia correctamente.

Alguna sugerencia??? Gracias!!!
  Responder
#2
No vas mal encaminado, ponle tambien un caracter al terminar el string.

sendor1&sensor2&sensor3&

Otro consejo, no hace falta que uses tanto texto para identificar. un sensor de temperatura = temp, el de humedad = hum.
Si son dos sensores puedes hacer temp1, hum1, temp2, hum2.

Si son 2 nodos diferentes, separar por nodos.

Tendras que trabajar un poquito mas en el parser, pero vas muy bien encaminado.
-> Mi CNC de escritorio CNCDesktop 500 -> https://www.spainlabs.com/foros/tema-Fresadora-Desktop-CNC-500
-> Laboratorio de Fabricación Digital Maker www.lowpower.io 
--> Twitter: https://twitter.com/Grafisoft_ES  | IG: https://www.instagram.com/lowpowerio/
  Responder
#3
Buenas noches.

Una cosa que veo es que no tienes bien definidos ni configurados los sensores dht, debes definir si son sensores dht11 o dht22, y a su vez en que pin esta conectado la recepción de los datos de temperatura y humedad, te dejo un enlace a una pagina que lo explica muy bien.

https://www.luisllamas.es/arduino-dht11-dht22/

Y para usar dos sensores o mas

https://forum.arduino.cc/index.php?topic=208098.0

Una vez configurados los sensores, veremos que pasa con los datos recibidos por el Arduino.

Un saludo
  Responder


Posibles temas similares…
Tema Autor Respuestas Vistas Último mensaje
  como combinar muchos datos con arduino homer32 3 1,633 31-08-2018, 06:55 AM
Último mensaje: homer32
  Subir datos a ubidots y thingspeak desde un dispositivo. alejayo 5 2,775 16-08-2017, 11:30 AM
Último mensaje: alejayo
  Proyecto: Base de carga para relojes automáticos miguelgomez18 22 6,469 10-04-2016, 03:49 PM
Último mensaje: miguelgomez18
  XIVELY - Subir datos con arduino [AYUDA] dcp1985 3 2,836 12-09-2014, 04:49 PM
Último mensaje: dcp1985
  ¿Arduino MEGA o Arduino ADK? igargi 7 3,274 25-08-2013, 04:58 PM
Último mensaje: cansi22