Necesito enviar varios datos a una sola variable y graficarlos en una misma petición, pero no recibo ningún dato, por favor podrían ayudarme? Este es el código que tengo:
void setup()
{
LTask.begin();
Serial.begin(115200); // setup Serial port
pinMode(13, OUTPUT);
Serial.println(“Attach to GPRS network”); // Attach to GPRS network - need to add timeout
while (!LGPRS.attachGPRS(“internet.comcel.com.co”,"","")) {
delay(500);
}
Serial.println(“GPRS attached!”);
delay(500);
ads1115.begin();
Here’s an MQTT example that’s working for me! it sends three variables. You need to install the PubSubClient library first (https://github.com/knolleary/pubsubclient).
#include <LGPRS.h> //include the base GPRS library
#include <LGPRSClient.h> //include the ability to Post and Get information using HTTP
#include <PubSubClient.h>
// These are the variables you will want to change based on your IOT data streaming account / provider
#define TOPIC "/v1.6/devices/linkit-one"
char payload[180]; // Reserve a char to store the Ubidots data. Account for 60 bytes per variable.
char le[4];
char mqttBroker[] = "things.ubidots.com";
String response;
LGPRSClient GPRSclient;
PubSubClient client(GPRSclient);
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("linkit-one","TOKENUBIDOTS","")) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup()
{
Serial.begin(115200); // setup Serial port
pinMode(13, OUTPUT);
Serial.println("Attach to GPRS network"); // Attach to GPRS network - need to add timeout
while (!LGPRS.attachGPRS("apn.konekt.io","","")) {
delay(500);
}
Serial.println("GPRS attached!");
client.setServer(mqttBroker, 1883);
delay(10000);
}
void loop(){
int temp = analogRead(A0);
int ph = analogRead(A1);
int orp = analogRead(A2);
sprintf(payload,"%s", "{\"temperature\":");
sprintf(payload,"%s%d", payload, temp);
sprintf(payload,"%s%s", payload, ",\"ph\":");
sprintf(payload,"%s%d", payload, ph);
sprintf(payload,"%s%s", payload, ",\"orp\":");
sprintf(payload,"%s%d", payload, orp);
sprintf(payload,"%s%s", payload, "}");
Serial.println(payload);
if (!client.connected()) {
reconnect();
}
client.publish(TOPIC, payload);
client.loop();
delay(1000);
}