Extraer datos de thingspeak sin utilizar libreria | ESP8266 Wi-Fi Module | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
Extraer datos de thingspeak sin utilizar libreria
Avatar
Sergio_Tolosa
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
1
November 13, 2017 - 5:54 pm
sp_Permalink sp_Print

Buenas tardes, quisiera saber como hacer para extraer o bajar datos de un canal de thingspeak sin necesidad de utilizar su librería. Este es el código que llevo por ahora. Les agradezco su colaboración.

 

#include <ESP8266WiFi.h>

 

String apiKey = "MMRSR6BEWE7CZ26Z";

const char *ssid = "--------";
const char *pass = "++++++++";
const char* host = "api.thingspeak.com";

void setup()
{

Serial.begin(9600);
Serial.println("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

}
void loop()
{
WiFiClient client_1; //Inicializamos el cliente (client_1)

Serial.printf("
[Conectando a %s ... ", host); //Establecemos la conexión con el servidor
if (client_1.connect(host, 80))
{
Serial.println("conectado]");

Serial.println("[Enviando peticion]"); //Enviamos la petición de datos
client_1.print(String("GET /") + " HTTP/1.1
" +
"Host: " + host + "
" +
"Connection: close
" +
"
"
);

Serial.println("[Respuesta:]"); //Leemos la respuesta del servidor
while (client_1.connected())
{
if (client_1.available())
{

Serial.println(client_1.read());
Serial.println("-------------------------------------------");
delay(5000);

}
}
client_1.stop(); //Finalizamos la conexión con el servidor
Serial.println("
[Desconectado]");
}
else
{
Serial.println("conexion con el servidor no lograda!]");
client_1.stop();
}
delay(10000);
}

Avatar
cstapels

Gold
Forum Posts: 122
sp_UserOnlineSmall Online
2
November 14, 2017 - 3:24 pm
sp_Permalink sp_Print

El ejemplo del monitor de suelo muestra cómo enviar datos sin la biblioteca.
Puede ver la sintaxis correcta para que GET recupere datos en Obtener un canal de información.
Parece que te perdiste el texto de la solicitud en el código anterior.

" GET to https://api.thingspeak.com/channels/CHANNEL_ID/feeds"
Aquí hay un fragmento que podría ayudar:

if (client.connect(thingSpeakAddress, 80))
{

    client.println("GET /channels/"+tsChannel+tsFolder+tsField+"/last.txt");
    client.println();
}
else
{
  failedCounter++;

    lastConnectionTime = millis();
}
delay(500);
String response;
char charIn;

do {
charIn = client.read(); // read a char from the buffer
response += charIn; // append that char to the string response
}
while (client.available() > 0);
client.stop();

 

The soil monitor example shows how to send data without the library. 

You can see the correct syntax for the GET to retrieve data on Get a Channel Feed. 

It looks like you missed the text of the request in the code above.

" GET to https://api.thingspeak.com/channels/CHANNEL_ID/feeds"

Here is a snippet that might help:

if (client.connect(thingSpeakAddress, 80))
{

    client.println("GET /channels/"+tsChannel+tsFolder+tsField+"/last.txt");
    client.println();
}
else
{
  failedCounter++;

    lastConnectionTime = millis();
}
delay(500);
String response;
char charIn;

do {
charIn = client.read(); // read a char from the buffer
response += charIn; // append that char to the string response
}
while (client.available() > 0);
client.stop();

Hope the Spanish is ok.  I used Google translate but checked it with my Spanish immersion student son.  I think he is going to charge me for the service.

Avatar
cstapels

Gold
Forum Posts: 122
sp_UserOnlineSmall Online
3
December 5, 2017 - 9:01 am
sp_Permalink sp_Print

The soil monitor example shows how to send data without the library. 

You can see the correct syntax for the GET to retrieve data on Get a Channel Feed. 

It looks like you missed the text of the request in the code above.

" GET to 

 

Here is a snippet that might help:

if (client.connect(thingSpeakAddress, 80))
{

    client.println("GET /channels/"+tsChannel+tsFolder+tsField+"/last.txt");
    client.println();
}
else
{
  failedCounter++;

    lastConnectionTime = millis();
}
delay(500);
String response;
char charIn;

do {
charIn = client.read(); // read a char from the buffer
response += charIn; // append that char to the string response
}
while (client.available() > 0);
client.stop();

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: cstapels
21 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

yeseniara11

RomanFug

JamesPes

RobertBak

ScottSmiva

Amourhotte

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee