ESP8266+MAX7219+DS18B20+BME280
- Войдите на сайт для отправки комментариев
В общем решил освоить ESP8266, не то чтоб совсем 0 знания, ну гугл в помощь + метод проб ошибок потихоньку получается. Каких-то заморочек с веб интерфейсом мне пока что не нужно, Банальный вывод информации на простенькую страничку не более, что б было реализовано.
С дисплеем пришлось повозиться, изначально делал с библиотекой Max72xxPanel, но как я ее не мучил, не получалось вывести символ градуса цельсия, да и шрифты дефолтные какие-то корявенькие у нее.
В общем в итоге перешел на MD_MAX72xx, тут и шрифты красивее, и символ градуса получилось сделать.
https://cloud.mail.ru/public/Z3CL/4sMbu5Hcv изначальный исходник такой, был найден на просторах интернета, в последствии добавив в него датчики, у меня получилась вот такая модификация:
https://cloud.mail.ru/public/4aay/5uUXo8AJd
Вот короче такой ужас, но работает
/*
*
*
*/
#include "FS.h"
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <Ticker.h>
#include <EEPROM.h>
#include "Timer.h"
#include <OneWire.h>
//#include <DallasTemperature.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <EasyNTPClient.h>
#include <ArduinoJson.h>
#include <Wire.h> // Подключаем библиотеку Wire
#include <Adafruit_BME280.h>
//#include <Adafruit_BMP280.h> // Подключаем библиотеку Adafruit_BME280
#include <Adafruit_Sensor.h> // Подключаем библиотеку Adafruit_Sensor
#include "Fonts.h"
#define SEALEVELPRESSURE_HPA (1013.25) // Задаем высоту
Adafruit_BME280 bme; // Установка связи по интерфейсу I2C
// контакт для передачи данных подключен к D1 на ESP8266 12-E (GPIO16):
//#define ONE_WIRE_BUS 0
// создаем экземпляр класса oneWire; с его помощью
// можно коммуницировать с любыми девайсами, работающими
// через интерфейс 1-Wire, а не только с температурными датчиками
// от компании Maxim/Dallas:
//OneWire oneWire(ONE_WIRE_BUS);
// передаем объект oneWire объекту DS18B20:
//DallasTemperature DS18B20(&oneWire);
char temperatureCString[6];
char temperatureFString[6];
char temperatureBMPString[6];
char temperatureString[6];
char pressureString[7];
#define MAX_DEVICES 4
#define CLK_PIN D5 // or SCK
#define DATA_PIN D7 // or MOSI
#define CS_PIN D8 // or SS
MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
// Global data
typedef struct
{
textEffect_t effect; // text effect to display
char * psz; // text string nul terminated
uint16_t speed; // speed multiplier of library default
uint16_t pause; // pause multiplier for library default
} sCatalog;
sCatalog catalog[] =
{
{ PA_SLICE, "SLICE", 1, 1 },
{ PA_MESH, "MESH", 10, 1 },
{ PA_FADE, "FADE", 20, 1 },
{ PA_WIPE, "WIPE", 5, 1 },
{ PA_WIPE_CURSOR, "WPE_C", 4, 1 },
{ PA_OPENING, "OPEN", 3, 1 },
{ PA_OPENING_CURSOR, "OPN_C", 4, 1 },
{ PA_CLOSING, "CLOSE", 3, 1 },
{ PA_CLOSING_CURSOR, "CLS_C", 4, 1 },
{ PA_BLINDS, "BLIND", 7, 1 },
{ PA_DISSOLVE, "DSLVE", 7, 1 },
{ PA_SCROLL_UP, "SC_U", 5, 1 },
{ PA_SCROLL_DOWN, "SC_D", 5, 1 },
{ PA_SCROLL_LEFT, "SC_L", 5, 1 },
{ PA_SCROLL_RIGHT, "SC_R", 5, 1 },
{ PA_SCROLL_UP_LEFT, "SC_UL", 7, 1 },
{ PA_SCROLL_UP_RIGHT, "SC_UR", 7, 1 },
{ PA_SCROLL_DOWN_LEFT, "SC_DL", 7, 1 },
{ PA_SCROLL_DOWN_RIGHT, "SC_DR", 7, 1 },
{ PA_SCAN_HORIZ, "SCANH", 4, 1 },
{ PA_SCAN_VERT, "SCANV", 3, 1 },
{ PA_GROW_UP, "GRW_U", 7, 1 },
{ PA_GROW_DOWN, "GRW_D", 7, 1 },
};
Timer t;
#include "global.h"
#include "NTP.h"
// Include the HTML, STYLE and Script "Pages"
#include "Page_Admin.h"
#include "Page_Script.js.h"
#include "Page_Style.css.h"
#include "Page_NTPSettings.h"
#include "Page_Information.h"
#include "Page_General.h"
#include "Page_NetworkConfiguration.h"
extern "C" {
#include "user_interface.h"
}
Ticker ticker;
os_timer_t myTimer;
//*** Normal code definition here ...
#define LED_PIN 2
#define buttonPin 0
#define analogPIN A0
WiFiUDP udp;
EasyNTPClient ntpClient(udp, "pool.ntp.org", ((3*60*60))); // IST = GMT + 2
char timestr[10];
String inputString = "99";
String timeString = "99";
//unsigned int New = 0;
//unsigned int debug_en = 2;
//unsigned int narodmon_en = 2;
String tmpdata_header = "ds18b20.lan ";
char tmpdata_arr[1492];
char rootpage[500];
//char helppage[500];
char uptime[30];
//int minus = 0;
//int temperature = 99;
//int temperature_dec = 99;
OneWire ds (0);
byte data[12];
byte addr1[8] = {0x28, 0xC0, 0x9B, 0x07, 0xD6, 0x01, 0x3C, 0xD1};
//byte addr1[8] = {0x28, 0xED, 0xF6, 0x7C, 0x02, 0x00, 0x00, 0xB2};
int16_t raw;
float temp1;
long lastUpdateTime = 0; // Переменная для хранения времени последнего считывания с датчика
const int TEMP_UPDATE_TIME = 1000; // Определяем периодичность проверок
String weatherKey;
String ipstring;
String Text;
char buf[256];
String y; // год
String mon; // месяц
String wd; // день недели
String d; // дени
String h; // часоы
String m; // минуты
String s; // секунды
int disp=0;
int rnd;
int lp=0;
unsigned long eventTime=0;
int buttonstate =1;
String weatherMain = "";
String weatherDescription = "";
String weatherLocation = "";
String country;
int humidity;
int pressure;
float temp;
String tempz;
float lon;
float lat;
int clouds;
float windSpeed;
int windDeg;
String date;
String date1;
String currencyRates;
String weatherString;
String weatherString1;
String weatherStringz;
String weatherStringz1;
String weatherStringz2;
String cityID;
WiFiClient client;
String chipID;
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 handleRoot()
{
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
temp1 = DS18B20(addr1);
// getTemperature();
// float tempC;
//// BME280GetData();
// DS18B20.requestTemperatures();
// tempC = DS18B20.getTempCByIndex(0);
// dtostrf(tempC, 2, 1, temperatureCString);
String message = "<!DOCTYPE html>\n<html>\n<head>\n";
message += "\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
message += "\t<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n";
message += "\t<meta http-equiv=\"refresh\" content=\"30\">\n";
message += "\t<title>Метеостанция</title>\n";
//message += "\t<link rel=\"icon\" href=\"/Temp-out.png\" sizes=\"35x35\" />\n";
message += "\t<link rel=\"stylesheet\" href=\"/Style.css\">\n";
message += "</head>\n<body>\n";
message += "\t<h1>Метеостанция</h1>\n";
message += "\t<table>\n\t\t<tr>\t\n\t\t\t<th>Параметр</th>\n\t\t\t<th>Показания</th>\n\t\t</tr>\n";
message += "\t\t<tr>\n\t\t\t<td>Температура на улице:</td>\n";
message += "\t\t\t<td><span class=\"sensor\">" + String(temperatureCString) + "°C</span></td>\n\t\t</tr>\n";
message += "\t\t<tr>\n\t\t\t<td>Температура в квартире:</td>\n";
message += "\t\t\t<td><span class=\"sensor\">" + String(bme.readTemperature()) + "°C </span></td>\n\t\t</tr>\n";
message += "\t\t<tr>\n\t\t\t<td>Давление:</td>\n";
message += "\t\t\t<td><span class=\"sensor\">" + String(bme.readPressure() / 133.3) + " мм.рт.ст.</span></td>\n\t\t</tr>\n";
message += "\t\t<tr>\n\t\t\t<td>Влажность:</td>\n";
message += "\t\t\t<td><span class=\"sensor\">" + String(bme.readHumidity()) + " %</span></td>\n\t\t</tr>\n";
message += "\t\t<tr>\n\t\t\t<td style=\"width: 350px;\">";
message += "<span class=\"sensor\">Время работы системы:</span></td>\n";
message += "\t\t\t<td>" + String(hr) + ":" + String(min % 60) + ":" + String(sec % 60) + "</td>\n";
// message += "\t\t<tr>\n\t\t\t<td style=\"width: 350px;\">";
// message += "<span class=\"sensor\"><img src=\"/Time.png\"> Страница обновлена:</span></td>\n";
// message += "\t\t\t<td>" + getDate() + " " + ntpClient.getFormattedTime() + "</td>\n\t\t</tr>\n";
message += "\t</table>\n</body>\n</html>\n";
server.send(200, "text/html", message);
}
void handleUptime()
{
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
int curtemp = 22;
snprintf(uptime, 30, "Uptime: %02d:%02d:%02d\r\n", hr, min % 60, sec % 60);
server.send(200, "text/html", uptime);
}
char* ntp(char *result) {
unsigned long epoch = (ntpClient.getUnixTime());
unsigned int hours = ((epoch % 86400L) / 3600);
unsigned int minutes = ((epoch % 3600) / 60);
unsigned int seconds = (epoch % 60);
sprintf(result, "%02d:%02d:%02d", hours, minutes, seconds);
return result;
}
String* udpsend(String tmpdata)
{
tmpdata = tmpdata_header + tmpdata;
tmpdata.toCharArray(tmpdata_arr,sizeof(tmpdata_arr));
// udp.beginPacket("192.168.10.1",514);
udp.write(tmpdata_arr);
udp.endPacket();
delay(500);
}
//==================================================================================
// Считывание температуры
//==================================================================================
float DS18B20(byte *adres){
ds.reset();
ds.select(adres);
ds.write(0x44,1); // start conversion, with parasite power on at the end
if (millis() - lastUpdateTime > TEMP_UPDATE_TIME)
{
lastUpdateTime = millis();
ds.reset();
ds.select(adres);
ds.write(0xBE); // Read Scratchpad
for (byte i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read ();
}
raw = (data[1] << 8) | data[0];//=======Пересчитываем в температуру
float celsius = (float)raw / 16.0;
dtostrf(temp1, 2, 1, temperatureCString);
return celsius;
}
}
//void getTemperature() {
// float tempC;
// float tempF;
// do {
// DS18B20.requestTemperatures();
// tempC = DS18B20.getTempCByIndex(0);
// dtostrf(tempC, 2, 2, temperatureCString);
// tempF = DS18B20.getTempFByIndex(0);
// dtostrf(tempF, 3, 2, temperatureFString);
// delay(100);
// } while (tempC == 85.0 || tempC == (-127.0));
// server.send(200, "text/plain", (temperatureCString));
//}
void getWeather() {
float t;
float p;
t = bme.readTemperature();
p = (bme.readPressure() * 7.5006e-3);
dtostrf(t, 5, 1, temperatureString);
dtostrf(p, 6, 1, pressureString);
delay(100);
}
void handleFileList() {
String path = "/";
Dir dir = SPIFFS.openDir(path);
path = String();
String output = "[";
while (dir.next()) {
File entry = dir.openFile("r");
if (output != "[") output += ' ';
bool isDir = false;
output += "{\"type\":\"";
output += (isDir) ? "dir" : "file";
output += "\",\"name\":\"";
output += String(entry.name()).substring(1);
output += "\"}\n";
entry.close();
}
output += "]\n";
server.send(200, "text/json", output);
}
void setup() {
SPIFFS.begin();
{
Dir dir=SPIFFS.openDir("/");
while (dir.next()){
String fileName=dir.fileName();
size_t fileSize=dir.fileSize();
}
udpsend("system,info Internal SPIFFS activated!");
}
P.begin();
P.setInvert(false);
P.setFont(fontBG);
//P.setIntensity(0);
bool CFG_saved = false;
int WIFI_connected = false;
//DS18B20.begin(); // по умолчанию разрешение датчика – 9-битное;
// если у вас какие-то проблемы, его имеет смысл
// поднять до 12 бит; если увеличить задержку,
// это даст датчику больше времени на обработку
// температурных данных
Serial.begin(115200);
// pinMode(LED_PIN,OUTPUT);
// pinMode(buttonPin,INPUT);
// digitalWrite(buttonPin, HIGH);
// digitalWrite(LED_PIN, HIGH);
//**** Network Config load
EEPROM.begin(512); // define an EEPROM space of 512Bytes to store data
CFG_saved = ReadConfig();
// Connect to WiFi acess point or start as Acess point
if (CFG_saved) //if no configuration yet saved, load defaults
{
// Connect the ESP8266 to local WIFI network in Station mode
Serial.println("Booting");
WiFi.mode(WIFI_STA);
if (!config.dhcp)
{
WiFi.config(IPAddress(config.IP[0], config.IP[1], config.IP[2], config.IP[3] ), IPAddress(config.Gateway[0], config.Gateway[1], config.Gateway[2], config.Gateway[3] ) , IPAddress(config.Netmask[0], config.Netmask[1], config.Netmask[2], config.Netmask[3] ) , IPAddress(config.DNS[0], config.DNS[1], config.DNS[2], config.DNS[3] ));
}
WiFi.begin(config.ssid.c_str(), config.password.c_str());
printConfig();
WIFI_connected = WiFi.waitForConnectResult();
if(WIFI_connected!= WL_CONNECTED ){
Serial.println("Connection Failed! activating to AP mode...");
Serial.print("Wifi ip:");Serial.println(WiFi.localIP());
Serial.print("Email:");Serial.println(config.email.c_str());
}
}
if ( (WIFI_connected!= WL_CONNECTED) or !CFG_saved){
// DEFAULT CONFIG
scrollConnect();
Serial.println("Setting AP mode default parameters");
config.ssid = "UFA Iot"; // SSID of access point
config.password = "" ; // password of access point
config.dhcp = true;
config.IP[0] = 192; config.IP[1] = 168; config.IP[2] = 1; config.IP[3] = 100;
config.Netmask[0] = 255; config.Netmask[1] = 255; config.Netmask[2] = 255; config.Netmask[3] = 0;
config.Gateway[0] = 192; config.Gateway[1] = 168; config.Gateway[2] = 1; config.Gateway[3] = 1;
config.DNS[0] = 192; config.DNS[1] = 168; config.DNS[2] = 1; config.DNS[3] = 1;
config.ntpServerName = "0.ru.pool.ntp.org"; // to be adjusted to PT ntp.ist.utl.pt
config.Update_Time_Via_NTP_Every = 10;
config.timeZone = 3;
config.isDayLightSaving = true;
config.DeviceName = "API ключь";
config.email = "cityID";
WiFi.mode(WIFI_AP);
WiFi.softAP(config.ssid.c_str());
Serial.print("Wifi ip:");Serial.println(WiFi.softAPIP());
}
if (!bme.begin(0x76)) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
/* Настройки по умолчанию */
//bme.setSampling(Adafruit_BME280::MODE_NORMAL, /* Режим работы */
//Adafruit_BME280::SAMPLING_X2, /* Температура передискретизация */
//Adafruit_BME280::SAMPLING_X16, /* Давление передискретизация */
//Adafruit_BME280::FILTER_X16, /* Фильрация. */
//Adafruit_BME280::STANDBY_MS_500); /* Интервал включения. */
bme.setSampling(Adafruit_BME280::MODE_NORMAL,
Adafruit_BME280::SAMPLING_X2, // temperature
Adafruit_BME280::SAMPLING_X16, // pressure
Adafruit_BME280::SAMPLING_X1, // humidity
Adafruit_BME280::FILTER_X16,
Adafruit_BME280::STANDBY_MS_0_5 );
server.serveStatic("/Style.css", SPIFFS, "/Style.css", "max-age=2592000");
// server.serveStatic("/Temp-in.png", SPIFFS, "/Temp-in.png", "max-age=2592000");
// server.serveStatic("/Temp-out.png", SPIFFS, "/Temp-out.png", "max-age=2592000");
// server.serveStatic("/Humdity.png", SPIFFS, "/Humdity.png", "max-age=2592000");
// server.serveStatic("/Pressure.png", SPIFFS, "/Pressure.png", "max-age=2592000");
server.serveStatic("/Background.jpg", SPIFFS, "/Background.jpg", "max-age=2592000");
server.on("/", handleRoot);
server.on("/index.html", handleRoot);
server.on("/uptime", handleUptime);
// server.on("/ds18b20", getTemperature);
server.on("/list", handleFileList);
server.on("/ntp", []()
{
server.send(200, "text/plain", ntp(timestr));
});
server.on("/data", []()
{
server.send(200, "text/plain", timeString + ": " + inputString);
});
server.onNotFound(handleNotFound);
server.begin();
// *********** OTA SETUP
ArduinoOTA.setHostname(config.DeviceName.c_str());
ArduinoOTA.onEnd([]() { // do a fancy thing with our board led at end
ESP.restart();
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
ESP.restart();
});
/* setup the OTA server */
ArduinoOTA.begin();
Serial.println("Ready");
for(int i=0; i<3; i++){ // Bling the LED to show the program started
digitalWrite(LED_PIN, LOW);
delay(200);
digitalWrite(LED_PIN, HIGH);
delay(200);
}
// start internal time update ISR
// tkSecond.attach(1, ISRsecondTick);
//**** Normal Sketch code here...
ipstring = (
String(WiFi.localIP()[0]) +"." +
String(WiFi.localIP()[1]) + "." +
String(WiFi.localIP()[2]) + "." +
String(WiFi.localIP()[3])
);
{
for (uint8_t i=0; i<ARRAY_SIZE(catalog); i++)
{
catalog[i].speed *= P.getSpeed();
catalog[i].pause *= 500;
}
}
t.every(1000, ISRsecondTick);
if (WiFi.status() == WL_CONNECTED) {
getTime();
scrollIP();
temp1 = DS18B20(addr1);
delay(1000);
// float tempC;
float p;
// DS18B20.requestTemperatures();
// tempC = DS18B20.getTempCByIndex(0);
// dtostrf(tempC, 2, 1, temperatureCString);
dtostrf(bme.readTemperature(), 2, 1, temperatureBMPString);
p = (bme.readPressure() / 133.3);
dtostrf(p, 3, 0, pressureString);
delay(100);
// t.every(10000, getTime);
}
getTime();
// getWeatherData();
// getWeatherDataz();
//weatherKey = config.DeviceName.c_str();
//cityID = config.email.c_str();
}
// the loop function runs over and over again forever
void loop() {
// OTA request handling
ArduinoOTA.handle();
// WebServer requests handling
server.handleClient();
// feed de DOG :)
customWatchdog = millis();
Serial.print("Temp1=");
Serial.print(temperatureCString);
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
//**** Normal Skecth code here ...
t.update();
if (lp >= 10) lp=0;
if (disp ==0){
temp1 = DS18B20(addr1);
// float tempC;
float p;
// DS18B20.requestTemperatures();
// tempC = DS18B20.getTempCByIndex(0);
// dtostrf(tempC, 2, 1, temperatureCString);
dtostrf(bme.readTemperature(), 2, 1, temperatureBMPString);
p = (bme.readPressure() / 133.3);
dtostrf(p, 3, 0, pressureString);
delay(100);
getTime();
disp=1;
lp++;
}
if (disp ==1){
rnd = random(0, ARRAY_SIZE(catalog));
Text = h + ":" + m;
displayInfo();
}
if (disp ==2){
Text = wd + " " + d + " " + mon + " " + y;
scrollText();
}
if (disp ==3){
Text = "На улице " + String(temperatureCString) + "\x1CС";
scrollText1();
}
if (disp ==4){
Text = "В комнате " + String(temperatureBMPString) + "\x1CС";
scrollText2();
}
if (disp ==5){
Text = "Давление " + String(pressureString) + " мм.рт.ст.";
scrollText3();
}
// if (disp ==5){
// rnd = random(0, ARRAY_SIZE(catalog));
// Text = h + ":" + m;
// displayInfo2();
// }
// if (disp ==6){
// Text = weatherStringz + " " + weatherStringz1;
// scrollText2();
// }
//============длительное нажатие кнопки форматирует EEPROM
int buttonstate=digitalRead(buttonPin);
if(buttonstate==HIGH) eventTime=millis();
if(millis()-eventTime>5000){ // при нажатии 15 секунд -
digitalWrite(16, LOW);
ResetAll(); // форматируем EEPROM
Serial.println("EEPROM formatted");
ESP.restart();
}
else
{
digitalWrite(16, HIGH);
}
//============длительное нажатие кнопки форматирует EEPROM
}
void ResetAll(){
EEPROM.begin(512);
// write a 0 to all 512 bytes of the EEPROM
for (int i = 0; i < 512; i++){
EEPROM.write(i, 0);
}
EEPROM.end();
ESP.reset();
}
//==========================================================
void getTime(){
getNTPtime();
h = String (DateTime.hour/10) + String (DateTime.hour%10);
m = String (DateTime.minute/10) + String (DateTime.minute%10);
s = String (DateTime.second/10 + String (DateTime.second%10));
d = String (DateTime.day);
y = String (DateTime.year);
if (DateTime.month == 1) mon = "Января";
if (DateTime.month == 2) mon = "Февраля";
if (DateTime.month == 3) mon = "Марта";
if (DateTime.month == 4) mon = "Апреля";
if (DateTime.month == 5) mon = "Мая";
if (DateTime.month == 6) mon = "Июня";
if (DateTime.month == 7) mon = "Июля";
if (DateTime.month == 8) mon = "Августа";
if (DateTime.month == 9) mon = "Сентября";
if (DateTime.month == 10) mon = "Октября";
if (DateTime.month == 11) mon = "Ноября";
if (DateTime.month == 12) mon = "Декабря";
if (DateTime.wday == 2) wd = "Понедельник";
if (DateTime.wday == 3) wd = "Вторник";
if (DateTime.wday == 4) wd = "Среда";
if (DateTime.wday == 5) wd = "Четверг";
if (DateTime.wday == 6) wd = "Пятница";
if (DateTime.wday == 7) wd = "Суббота";
if (DateTime.wday == 1) wd = "Воскресенье";
Brightnes();
}
void Brightnes(){
// Яркость дисплея
if ((DateTime.hour >= 0 && DateTime.hour < 6) || DateTime.hour >= 23) P.setIntensity(0);
else P.setIntensity(5);
}
//==========================================================
void displayInfo(){
if (P.displayAnimate()){
utf8rus(Text).toCharArray(buf, 256);
P.displayText(buf, PA_CENTER, catalog[rnd].speed, 15000, PA_PRINT, PA_PRINT);
if (!P.displayAnimate()) disp = 2;
}
}
//==========================================================
void displayInfo1(){
if (P.displayAnimate()){
utf8rus(Text).toCharArray(buf, 256);
P.displayText(buf, PA_CENTER, catalog[rnd].speed, 5000, PA_PRINT, PA_PRINT);
if (!P.displayAnimate()) disp = 4;
}
}
//==========================================================
void displayInfo2(){
if (P.displayAnimate()){
utf8rus(Text).toCharArray(buf, 256);
P.displayText(buf, PA_CENTER, catalog[rnd].speed, 5000, PA_PRINT, PA_PRINT);
if (!P.displayAnimate()) disp = 6;
}
}
//==========================================================
void displayInfo3(){
if (P.displayAnimate()){
utf8rus(Text).toCharArray(buf, 256);
P.displayText(buf, PA_CENTER, catalog[rnd].speed, 5000, PA_PRINT, PA_PRINT);
if (!P.displayAnimate()) disp = 0;
}
}
//==========================================================
void scrollText(){
if (P.displayAnimate()){
utf8rus(Text).toCharArray(buf, 256);
P.displayScroll(buf, PA_LEFT, PA_SCROLL_LEFT, 40);
if (!P.displayAnimate()) disp = 3;
}
}
//==========================================================
void scrollText1(){
if (P.displayAnimate()){
utf8rus(Text).toCharArray(buf, 256);
P.displayScroll(buf, PA_LEFT, PA_SCROLL_LEFT, 40);
if (!P.displayAnimate()) disp = 4;
}
}
//==========================================================
void scrollText2(){
if (P.displayAnimate()){
utf8rus(Text).toCharArray(buf, 256);
P.displayScroll(buf, PA_LEFT, PA_SCROLL_LEFT, 40);
if (!P.displayAnimate()) disp = 5;
}
}
//==========================================================
void scrollText3(){
if (P.displayAnimate()){
utf8rus(Text).toCharArray(buf, 256);
P.displayScroll(buf, PA_LEFT, PA_SCROLL_LEFT, 40);
if (!P.displayAnimate()) disp = 0;
}
}
//==========================================================
//void scrollText4(){
// if (P.displayAnimate()){
// utf8rus(Text).toCharArray(buf, 256);
// P.displayScroll(buf, PA_LEFT, PA_SCROLL_LEFT, 40);
// if (!P.displayAnimate()) disp = 0;
// }
//}
//==========================================================
void scrollIP(){
Text = "Ваш IP: "+ipstring;
if (P.displayAnimate()){
utf8rus(Text).toCharArray(buf, 256);
P.displayScroll(buf, PA_LEFT, PA_SCROLL_LEFT, 15);
}
}
//==========================================================
void scrollConnect(){
Text = "Отсутствует подключение к WIFI. Подключитесь к точке доступа 'UFA Iot' и войдите в веб интерфейс 192.168.4.1" ;
if (P.displayAnimate()){
utf8rus(Text).toCharArray(buf, 256);
P.displayScroll(buf, PA_LEFT, PA_SCROLL_LEFT, 40);
if (!P.displayAnimate()) disp = 3;
}
}
String utf8rus(String source)
{
bool up = false;
if (up == true) source.toUpperCase();
int i, k;
String target;
unsigned char n;
k = source.length(); i = 0;
while (i < k) {
n = source[i]; i++;
switch (n) {
case 208: {
n = source[i]; i++;
if (n == 134) { n = 143; break; } // Р†
if (n == 129) { n = 168; break; }
if (n >= 144 && n <= 191) n = n + 48;
if (n >= 224 && up == true) n = n - 32;
break;
}
case 209: {
n = source[i]; i++;
if (n == 150) { n = 144; break; } // С–
if (n == 145) { n = 184; break; }
if (n >= 128 && n <= 143) n = n + 112;
if (n >= 224 && up == true) n = n - 32;
break;
}
case 210: {
n = source[i]; i++;
switch (n) {
case 146: n = 129; break; // Т’
case 147: n = 130; break; // Т“
case 154: n = 131; break; // Тљ
case 155: n = 132; break; // Т›
case 162: n = 133; break; // Тў
case 163: n = 134; break; // ТЈ
case 176: n = 137; break; // Т°
case 177: n = 138; break; // Т±
case 174: n = 139; break; // Т®
case 175: n = 140; break; // ТЇ
case 186: n = 141; break; // Тє
case 187: n = 142; break; // h
break;
}
break;
}
case 211: {
n = source[i]; i++;
switch (n) {
case 152: n = 127; break; // У
case 153: n = 128; break; // У™
case 168: n = 135; break; // УЁ
case 169: n = 136; break; // У©
break;
}
break;
}
break;
case 226: {
n = source[i]; i++;
switch (n) {
case 132:{
n = source[i]; i++;
switch (n) {
case 150: {
n = 35; break; // в„–
}
}
}
}
}
}
target += char(n);
}
return target;
}
И собственно нравится почти все, за исключением статического двоеточия в часах, а как его заставить мигать в MD_MAX72xx не могу найти.
И собственно нравится почти все, за исключением статического двоеточия в часах, а как его заставить мигать в MD_MAX72xx не могу найти.
Ну а если в MD_MAX72xx этого нет - что ж, и мигать нельзя? Не обязательно же это делать через библиотеку. Что мешает на полсекунды зажигать двоеточие. на полсекунды гасить - вот вам и решение
из замечаний по коду - функция handleUptime() меньше чем через сутки начнет врать, проверьте размерность переменных.
Ну и конечно, чтоит поучиться использовать массивы, вычисление месяца и дня недели через цепочку if - это стыдно.
Подозреваю, что в коде еще есть что улучшить и кроме этого
Ну из конкретных глюков замечено только ребуты ESPшки, при заходе в веб, но через какой-то достаточно большой промежуток времен работы...Причем когда этот глюк возникает, перезагрузка не помогает, вроде бы как эксперементировал - помогает перепрошивка данных которое "Sketch Data Upload". Но пока не копал, хотя надо, подозреваю где-то с какой-то переменной что-то не так, или типа того. А так я и не спорю, в коде дофига косяков :D