Send BMP280 sensor data with ESP8266 to ThingSpeak

Got my temperature, pressure and humidity data logging working.
I started by trying out the BPM280 nodemcu module with some lua scripts.
The I2C setup was easy and soon I was seeing sensor readings.
After getting the ESP8266 talking to my WiFi access point and I tried to post data to ThinkSpeak. I followed these instructions: https://vaasa.hacklab.fi/2015/01/12/esp8266-ds18b20-thingspeak-nodemcu/ substituting the sensors used with the BMP280.
Somehow I couldn't send anything to ThingSpeak so I decided to go the Arduino IDE way as proposed in the Vaasa Hacklab instructions comments section.

To set up the Arduino IDE with the ESP8266 you could follow some guide like: http://www.instructables.com/id/Programming-ESP8266-ESP-12E-NodeMCU-Using-Arduino-/?ALLSTEPS
First I had some problems to blink the on-board led on my NodeMCU 12E 1.0 fake from Ebay.
The pin# 2 did the trick. After a lot of hammering and realizing the I hadn't downloaded the newest Adafruit_BME280 library I got the following code to do my bidding:

  • Change in Adafruit_BME280.h #define BME280_ADDRESS (0x77) to #define BME280_ADDRESS (0x76)
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <ESP8266WiFi.h>
#include <ThingSpeak.h>

unsigned long myChannelNumber = YOURCHANNERNUMBER;  
const char * myWriteAPIKey = "YOURAPIKEY";  
const char* ssid = "YOURSSID";  
const char* password = "YOURPW";

const char* server = "api.thingspeak.com";  
WiFiClient client;

Adafruit_BME280 bme; // I2C

void setup() {  
  Wire.begin(0, 2);
  Serial.begin(115200);

  WiFi.begin(ssid, password);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

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

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
  ThingSpeak.begin(client);
}

void loop() {  
  float t = bme.readTemperature();
  float p = bme.readPressure();
  float h = bme.readHumidity();


  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" degrees Celcius Pressure: ");
  Serial.print(p);
  Serial.print(" Humidity: ");
  Serial.print(h);
  Serial.println("% send to Thingspeak");
  ThingSpeak.setField(1, t);
  ThingSpeak.setField(2, p);
  ThingSpeak.setField(3, h);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);
}

Here is the channel: https://thingspeak.com/channels/156985

Sandro

So many projects to make! I Enjoy building electronics, especially radios. I also like web development, playing with hardware like the Raspberry Pi and spending time outdoors. Love combining it all!

Finland
comments powered by Disqus