Have you managed to get the examples working without Blynk on your ESP? ie, outputting to Serial monitor?
do you mean with sensor SI2021?
Yup
Ok i will try it. I was try with Arduino and that was good…
Do you mean an Arduino UNO? Just call it an UNO since Arduino can apply to multiple types of hardware.
Arduino Mini or Nano…
How did you get on with the ESP?
Do you mean how long i am using ESP8266? 1,5 year.
No, did you get the examples working on the ESP.
yes:-)
Paste the code
Here is. And it is working great.
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WebServer.h>
#include <Wire.h>
#include <SI7021.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPClient.h>
#define SDA 0 // GPIO0 on ESP-01 module
#define SCL 2 // GPIO2 on ESP-01 module
#define FIVEMIN (1000UL * 60 * 5) // Update Frequency
#define AP_SSID "xxxxx" // Access Point SSID
#define AP_PSK "xxxxx" // Access Point PSK
#define TS_APIKEY "xxxxx" // ThingSpeak API Key
ESP8266WiFiMulti wifiMulti;
ESP8266WebServer server(80);
SI7021 sensor;
HTTPClient http;
unsigned long rolltime = millis() + FIVEMIN;
// Root Handle
void handle_root() {
int temperature = sensor.getCelsiusHundredths();
int humidity = sensor.getHumidityPercent();
float temp = temperature / 100.0;
server.send(200, "text/plain", String() + F("{\"temperature\": ") + String(temp,1) + F(", \"humidity\": ") + String(humidity) + F("}"));
}
// 404 Handler
void handleNotFound(){
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
}
void setup() {
Serial.begin (9600);
WiFi.mode(WIFI_STA);
wifiMulti.addAP(AP_SSID, AP_PSK);
Serial.print("Connecting Wifi..");
// Try to connect to WIFI
while(wifiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
// Show AP connection details
if(wifiMulti.run() == WL_CONNECTED) {
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
// Start MDNS responder
if(MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
// Set Root Handler
server.on("/", handle_root);
// Inline Handler
server.on("/inline", [](){
server.send(200, "text/plain", "this works as well");
});
// 404 Handler
server.onNotFound(handleNotFound);
// Start Server
server.begin();
// Start SI7021
sensor.begin(SDA,SCL);
}
void loop() {
// Handle HTTP Server
if (wifiMulti.run() == WL_CONNECTED) {
server.handleClient();
}
// Check to see if we need to send an ThingSpeak update
if((long)(millis() - rolltime) >= 0) {
int temperature = sensor.getCelsiusHundredths();
int humidity = sensor.getHumidityPercent();
float temp = temperature / 100.0;
Serial.println("Sending Update To ThingSpeak ");
if (wifiMulti.run() == WL_CONNECTED) {
http.begin("https://api.thingspeak.com/update.json");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST("api_key=" + String(TS_APIKEY) + "&field1=" + String(temp,1) + "&field2=" + humidity);
if(httpCode > 0) {
// We got a header
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// We got a 200!
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
}
// Roll on timer
rolltime += FIVEMIN;
}
}
Now iam trying :
#define BLYNK_DEBUG
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include <SI7021.h>
float temp, hum;
//char temp[20], hum[20];
bool SI7021_present = true;
#define I2C_SCL 12
#define I2C_SDA 13
SI7021 sensor;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = ""; // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
void setup()
{
Wire.begin();
sensor.begin(SDA,SCL);
Wire.begin(I2C_SDA, I2C_SCL);
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
}
void sendUptime()
{
int temperature = sensor.getCelsiusHundredths();
int humidity = sensor.getHumidityPercent();
Blynk.virtualWrite(1, temperature); // virtual pin
Blynk.virtualWrite(2, humidity); // virtual pin
}
void loop()
{
Blynk.run();
timer.run();
}
But in serial monitor is:
@ŕ‚-cý˙[249] Connecting to ASUS
[1750] Connected to WiFi
[1750] IP: 192.168.1.2
[1750]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.4.4 on NodeMCU
[1819] Free RAM: 45224
[5001] Connecting to blynk-cloud.com:8442
[5034] <[02|00|01|00] 75a3e91cbdf1457c9498b35eea63e9c1
[5059] >[00|00|01|00]Č
[5059] Ready (ping: 3ms).
[5059] <[11|00|01|00]Hver[00]0.4.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Jan 23 2017 07:33:18[00]
[5173] >[00|00|01|00]Č
[15174] <[06|00|02|00|00]
[15198] >[00|00|02|00]Č
[17128] >[14|00|01|00|02]
[17128] >pm
thanks
Congrats! You got it working!
Just comment out
#define BLYNK_DEBUG
And your Serial monitor wont have the HEX output.
Also add to setup()
timer.setInterval(1000L,sendUptime);
How is it working with out calling the sendUptime function? Or am I blind?
Good spotting!
SO YES. Now is sketch working good
. But i dont know are all things in the sketch necessarily??float temp, hum;
?bool SI7021_present = true;
?SimpleTimer timer;
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include <SI7021.h>
float temp, hum;
bool SI7021_present = true;
#define I2C_SCL 12 // Barometric Pressure Sensor (BMP085)
#define I2C_SDA 13
SI7021 sensor;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = ""; // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
void setup()
{
Wire.begin();
sensor.begin(SDA,SCL);
Wire.begin(I2C_SDA, I2C_SCL);
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
timer.setInterval(1000L,sendUptime);
}
void sendUptime()
{
int temperature = sensor.getCelsiusHundredths()/100;
int humidity = sensor.getHumidityPercent();
Blynk.virtualWrite(5, temperature); // virtual pin
Blynk.virtualWrite(6, humidity); // virtual pin
}
void loop()
{
Blynk.run();
timer.run();
}
Thanks.
sensor.getCelsiusHundredths()/100; = 20 celsius
And how i must change it if i need /point/ ? = 20.3 celsius
Thanks.
You need to change it to a float .
int are whole numbers only.
float allows for decimal places.
float temperature = sensor.getCelsiusHundredths()/100;
float humidity = sensor.getHumidityPercent();