Esp 8266 Node MCU and DHT 11 to ThingSpeak Problems | 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
Esp 8266 Node MCU and DHT 11 to ThingSpeak Problems
Avatar
npctecnologia@gmail.com
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
1
October 20, 2017 - 5:46 am
sp_Permalink sp_Print

Dear friends I am new at thingspeak, and have problems to program and work with thingspeak, please could you help me? bellow is the program, the program may be wrong ?Frown

 

//Include da lib de Wifi do ESP8266
#include "ESP8266WiFi.h"
//Include da lib do sensor DHT11 e DHT22
#include "DHT.h"

//Define do pino a ser utilizado no ESP para o sensor = GPIO4
#define DHT_DATA_PIN 2
#define DHTTYPE DHT11

//Definir o SSID da rede WiFi
const char* ssid = "Multilaser_2.4G_2FC158";
//Definir a senha da rede WiFi
const char* password = "96243911";

//Colocar a API Key para escrita neste campo
//Ela é fornecida no canal que foi criado na aba API Keys
String apiKey = "***********************";
const char* server = "api.thingspeak.com";

DHT dht(DHT_DATA_PIN, DHTTYPE);
WiFiClient client;

void setup() {
//Configuração da UART
Serial.begin(9600);
//Inicia o WiFi
WiFi.begin(ssid, password);

//Espera a conexão no router
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

dht.begin();

//Logs na porta serial
Serial.println("");
Serial.print("Conectado na rede ");
Serial.println(ssid);
Serial.print("IP: ");
Serial.println(WiFi.localIP());
}

void loop() {

//Espera 20 segundos para fazer a leitura
delay(20000);
//Leitura de umidade
float umidade = dht.readHumidity();
//Leitura de temperatura
float temperatura = dht.readTemperature();

//Se não for um numero retorna erro de leitura
if (isnan(umidade) || isnan(temperatura)) {
Serial.println("Erro ao ler o sensor!");
return;
}

//Inicia um client TCP para o envio dos dados
if (client.connect(server,80)) {
String postStr = apiKey;
postStr +="&field1=";
postStr += String(temperatura);
postStr +="&field2=";
postStr += String(umidade);
postStr += "

";

client.print("POST /update HTTP/1.1
");
client.print("Host: api.thingspeak.com
");
client.print("Connection: close
");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"
");
client.print("Content-Type: application/x-www-form-urlencoded
");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("

");
client.print(postStr);

//Logs na porta serial
Serial.print("Temperatura: ");
Serial.print(temperatura);
Serial.print(" Umidade: ");
Serial.println(umidade);
}
client.stop();
}

Avatar
cstapels

Gold
Forum Posts: 126
sp_UserOfflineSmall Offline
2
October 24, 2017 - 3:47 pm
sp_Permalink sp_Print

Welcome to ThingSpeak!  What responses are you getting from the server on the serial monitor?

Also, I would make sure you can update your channel manually, using the command format for update a channel field.

https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX&field1=1230
You can enter the format above in your browser address bar, use your channel write API key on place of XXXX...(not the user API key or the read API Key).
Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
24 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:

dannymm1

KamorkasOr

GRV2903

Jusikaclaiz

Raymondpoers

ScottDus

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee