Приветствую!
В связи с отключением Blink решил перейти на новую версию.
При попытке заливки скетча программа выдает ошибку. Эта прошивка прям сейчас установлена и работает, просто токен решил сменить, в чем может быть проблема?
Метеостанция в двумя реле, 2 кнопки и 2 контрольных светодиода.
Скетч прилагаю
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSerif9pt7b.h>
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "5Hlbjm0jsGCuNaSdfnIftY3A9aq2Unik";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "iwireless";
char pass[] = "vt3ENCndej";
// давление на высоте уровня моря в hPa
// давление на высоте уровня моря (можно оставить по умолчанию; 760 миллиметров ртутного столба — это нормальное атмосферное давление)
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing reset pin)
// initialize Adafruit display library
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//////////////////////////////////////////////////////////////////////
#define VPIN_TEMP V0
#define VPIN_HUMD V1
#define VPIN_PRES V2
#define VPIN_ALT V3
// RELAY /////////////////////////////////////////////////////////////
// LOW or HIGH
#define RELAY_ACTIVE_LEVEL HIGH
uint8_t gRelayPins[] = { D5, D6 };
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
const int gRelays = ARRAY_SIZE(gRelayPins);
#define RELAY1_BUTTON_VPIN V4
#define RELAY2_BUTTON_VPIN V5
uint8_t gRelayLedVPins[gRelays] = { V6, V7 };
#include "Button.h"
Button gaBtns[gRelays] = {(D3), (D4)};
//////////////////////////////////////////////////////////////////////
WidgetLED ledRelay[gRelays] = { (gRelayLedVPins[0]), (gRelayLedVPins[1]) };
const uint8_t RELAY_LVL_ON = (RELAY_ACTIVE_LEVEL==LOW)?LOW:HIGH;
const uint8_t RELAY_LVL_OFF = (RELAY_LVL_ON==LOW)?HIGH:LOW;
#include <EEPROM.h>
#include "crc8.h"
#pragma pack(push, 1)
struct STATE
{
bool relays[gRelays];
uint8_t crc; // should be last
}
gState;
#pragma pack(pop)
void loadState()
{
EEPROM.get(0, gState);
if (crc8((uint8_t *)&gState, sizeof(gState)-sizeof(gState.crc)) != gState.crc)
{
Serial.println(F("Settings read error, using defaults."));
// инициализационные значения
for(auto & state: gState.relays) state = false; // выключенны по умолчанию
}
else
{
Serial.println(F("Settings read ok."));
}
}
void storeState()
{
gState.crc = crc8((uint8_t *)&gState, sizeof(gState)-sizeof(gState.crc));
EEPROM.put(0, gState);
EEPROM.commit();
Serial.println(F("Settings stored."));
}
void relaysPinsInit()
{
for(auto & pin : gRelayPins) pinMode(pin, OUTPUT);
}
void relayPinSet(int i)
{
uint8_t pinval = gState.relays?RELAY_LVL_ON:RELAY_LVL_OFF;
digitalWrite(gRelayPins, pinval);
}
void relaysPinsSet()
{
for(int i = 0; i < gRelays; i++) relayPinSet(i);
}
void relayStateSet(int i, bool state)
{
if (state != gState.relays)
{
gState.relays = state;
relayPinSet(i);
storeState();
// forward to blynk
if (gState.relays) ledRelay.on(); else ledRelay.off();
}
}
void relayVirtualButtonPressed(int i)
{
relayStateSet(i, !gState.relays); // toggle
}
//////////////////////////////////////////////////////////////////////
BLYNK_WRITE(RELAY1_BUTTON_VPIN)
{
if (param.asInt() == 1)
{
relayVirtualButtonPressed(0);
}
}
BLYNK_WRITE(RELAY2_BUTTON_VPIN)
{
if (param.asInt() == 1)
{
relayVirtualButtonPressed(1);
}
}
////////////////////////////////////////////////////////////////////
BLYNK_CONNECTED()
{
//Blynk.syncAll(); // writes all vpins from server, e.g. causes BLYNK_WRITE(.)
for(int i = 0; i < gRelays; i++) if (gState.relays) ledRelay.on(); else ledRelay.off();
Serial.println(F("BLYNK CONNECTED"));
}
// This is called when Smartphone App is opened
BLYNK_APP_CONNECTED()
{
Serial.println(F("BLYNK_APP_CONNECTED"));
}
// This is called when Smartphone App is closed
BLYNK_APP_DISCONNECTED()
{
Serial.println(F("BLYNK_APP_DISCONNECTED"));
}
void setup()
{
Serial.begin(115200);
while(!Serial); // time to get serial running
Serial.println(F("\n\nWeather Station"));
//////////////////////////////////
EEPROM.begin(sizeof(STATE));
loadState();
relaysPinsInit();
relaysPinsSet();
//////////////////////////////////
for(auto & b: gaBtns) b.init();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
unsigned status;
// default settings
status = bme.begin(0x76);
// You can also pass in a Wire library object like &Wire2
// status = bme.begin(0x76, &Wire2)
if (!status)
{
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
Serial.println();
WiFi.begin(ssid, pass);
Blynk.config(auth);
}
uint32_t lastTime;
float gTemperature;
float gPressure;
float gHumidity;
float gAltitude;
void loop()
{
Blynk.run();
/////////////////////////////////////////////////////////
for(int i = 0; i < gRelays; i++)
{
if (gaBtns.update() && gaBtns.state())
{
relayStateSet(i, !gState.relays); // toggle
}
}
////////////////////////////////////////////////////////
uint32_t curTime = millis();
if ((curTime - lastTime) > 500)
{
static uint8_t i;
if (++i&1)
{
gTemperature = bme.readTemperature();
gPressure = bme.readPressure() / 133.3223684F; // mm Hg
gAltitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
gHumidity = bme.readHumidity();
Blynk.virtualWrite(VPIN_TEMP, gTemperature);
Blynk.virtualWrite(VPIN_HUMD, gHumidity);
Blynk.virtualWrite(VPIN_PRES, gPressure);
Blynk.virtualWrite(VPIN_ALT , gAltitude);
}
else
{
printValues();
}
lastTime = curTime;
}
yield();
}
void printValues()
{
display.clearDisplay();
display.setTextColor(WHITE, BLACK); // set text color to white and black background
display.setTextWrap(false); // disable text wrap
display.setTextSize(1);
// print temp
display.setCursor(0, 2);
display.printf("Temperature");
display.setCursor(0, 36);
display.printf("Atmosphere pressure");
display.setCursor(75, 2);
display.printf("Humidity");
display.setTextSize(2);
display.setCursor(0, 14);
display.printf("%+02.0f %C", gTemperature, (char)247);
//display.printf("%+02.1f %", gTemperature);
//print pressure
display.setTextSize(2);
display.setCursor(16, 48);
display.printf(" %d mm", (int)(gPressure));
// высоту на дисплей не выводим
//print Влажности
display.setCursor(65, 14);
display.printf(" %d %%", (int)(gHumidity));
display.display(); // update the display
}
В связи с отключением Blink решил перейти на новую версию.
При попытке заливки скетча программа выдает ошибку. Эта прошивка прям сейчас установлена и работает, просто токен решил сменить, в чем может быть проблема?
Метеостанция в двумя реле, 2 кнопки и 2 контрольных светодиода.
Скетч прилагаю
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSerif9pt7b.h>
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "5Hlbjm0jsGCuNaSdfnIftY3A9aq2Unik";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "iwireless";
char pass[] = "vt3ENCndej";
// давление на высоте уровня моря в hPa
// давление на высоте уровня моря (можно оставить по умолчанию; 760 миллиметров ртутного столба — это нормальное атмосферное давление)
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing reset pin)
// initialize Adafruit display library
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//////////////////////////////////////////////////////////////////////
#define VPIN_TEMP V0
#define VPIN_HUMD V1
#define VPIN_PRES V2
#define VPIN_ALT V3
// RELAY /////////////////////////////////////////////////////////////
// LOW or HIGH
#define RELAY_ACTIVE_LEVEL HIGH
uint8_t gRelayPins[] = { D5, D6 };
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
const int gRelays = ARRAY_SIZE(gRelayPins);
#define RELAY1_BUTTON_VPIN V4
#define RELAY2_BUTTON_VPIN V5
uint8_t gRelayLedVPins[gRelays] = { V6, V7 };
#include "Button.h"
Button gaBtns[gRelays] = {(D3), (D4)};
//////////////////////////////////////////////////////////////////////
WidgetLED ledRelay[gRelays] = { (gRelayLedVPins[0]), (gRelayLedVPins[1]) };
const uint8_t RELAY_LVL_ON = (RELAY_ACTIVE_LEVEL==LOW)?LOW:HIGH;
const uint8_t RELAY_LVL_OFF = (RELAY_LVL_ON==LOW)?HIGH:LOW;
#include <EEPROM.h>
#include "crc8.h"
#pragma pack(push, 1)
struct STATE
{
bool relays[gRelays];
uint8_t crc; // should be last
}
gState;
#pragma pack(pop)
void loadState()
{
EEPROM.get(0, gState);
if (crc8((uint8_t *)&gState, sizeof(gState)-sizeof(gState.crc)) != gState.crc)
{
Serial.println(F("Settings read error, using defaults."));
// инициализационные значения
for(auto & state: gState.relays) state = false; // выключенны по умолчанию
}
else
{
Serial.println(F("Settings read ok."));
}
}
void storeState()
{
gState.crc = crc8((uint8_t *)&gState, sizeof(gState)-sizeof(gState.crc));
EEPROM.put(0, gState);
EEPROM.commit();
Serial.println(F("Settings stored."));
}
void relaysPinsInit()
{
for(auto & pin : gRelayPins) pinMode(pin, OUTPUT);
}
void relayPinSet(int i)
{
uint8_t pinval = gState.relays?RELAY_LVL_ON:RELAY_LVL_OFF;
digitalWrite(gRelayPins, pinval);
}
void relaysPinsSet()
{
for(int i = 0; i < gRelays; i++) relayPinSet(i);
}
void relayStateSet(int i, bool state)
{
if (state != gState.relays)
{
gState.relays = state;
relayPinSet(i);
storeState();
// forward to blynk
if (gState.relays) ledRelay.on(); else ledRelay.off();
}
}
void relayVirtualButtonPressed(int i)
{
relayStateSet(i, !gState.relays); // toggle
}
//////////////////////////////////////////////////////////////////////
BLYNK_WRITE(RELAY1_BUTTON_VPIN)
{
if (param.asInt() == 1)
{
relayVirtualButtonPressed(0);
}
}
BLYNK_WRITE(RELAY2_BUTTON_VPIN)
{
if (param.asInt() == 1)
{
relayVirtualButtonPressed(1);
}
}
////////////////////////////////////////////////////////////////////
BLYNK_CONNECTED()
{
//Blynk.syncAll(); // writes all vpins from server, e.g. causes BLYNK_WRITE(.)
for(int i = 0; i < gRelays; i++) if (gState.relays) ledRelay.on(); else ledRelay.off();
Serial.println(F("BLYNK CONNECTED"));
}
// This is called when Smartphone App is opened
BLYNK_APP_CONNECTED()
{
Serial.println(F("BLYNK_APP_CONNECTED"));
}
// This is called when Smartphone App is closed
BLYNK_APP_DISCONNECTED()
{
Serial.println(F("BLYNK_APP_DISCONNECTED"));
}
void setup()
{
Serial.begin(115200);
while(!Serial); // time to get serial running
Serial.println(F("\n\nWeather Station"));
//////////////////////////////////
EEPROM.begin(sizeof(STATE));
loadState();
relaysPinsInit();
relaysPinsSet();
//////////////////////////////////
for(auto & b: gaBtns) b.init();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
unsigned status;
// default settings
status = bme.begin(0x76);
// You can also pass in a Wire library object like &Wire2
// status = bme.begin(0x76, &Wire2)
if (!status)
{
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
Serial.println();
WiFi.begin(ssid, pass);
Blynk.config(auth);
}
uint32_t lastTime;
float gTemperature;
float gPressure;
float gHumidity;
float gAltitude;
void loop()
{
Blynk.run();
/////////////////////////////////////////////////////////
for(int i = 0; i < gRelays; i++)
{
if (gaBtns.update() && gaBtns.state())
{
relayStateSet(i, !gState.relays); // toggle
}
}
////////////////////////////////////////////////////////
uint32_t curTime = millis();
if ((curTime - lastTime) > 500)
{
static uint8_t i;
if (++i&1)
{
gTemperature = bme.readTemperature();
gPressure = bme.readPressure() / 133.3223684F; // mm Hg
gAltitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
gHumidity = bme.readHumidity();
Blynk.virtualWrite(VPIN_TEMP, gTemperature);
Blynk.virtualWrite(VPIN_HUMD, gHumidity);
Blynk.virtualWrite(VPIN_PRES, gPressure);
Blynk.virtualWrite(VPIN_ALT , gAltitude);
}
else
{
printValues();
}
lastTime = curTime;
}
yield();
}
void printValues()
{
display.clearDisplay();
display.setTextColor(WHITE, BLACK); // set text color to white and black background
display.setTextWrap(false); // disable text wrap
display.setTextSize(1);
// print temp
display.setCursor(0, 2);
display.printf("Temperature");
display.setCursor(0, 36);
display.printf("Atmosphere pressure");
display.setCursor(75, 2);
display.printf("Humidity");
display.setTextSize(2);
display.setCursor(0, 14);
display.printf("%+02.0f %C", gTemperature, (char)247);
//display.printf("%+02.1f %", gTemperature);
//print pressure
display.setTextSize(2);
display.setCursor(16, 48);
display.printf(" %d mm", (int)(gPressure));
// высоту на дисплей не выводим
//print Влажности
display.setCursor(65, 14);
display.printf(" %d %%", (int)(gHumidity));
display.display(); // update the display
}