Возможно ли не обладая особыми знаниями ужать эту программу со 126%, чтобы она влезла на esp32, или это мертвый номер?
#include <TFT_eSPI.h>
#include <SimpleBLE.h>
#include "BLEDevice.h"
#include <NTPClient.h>
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson.git
#include <NTPClient.h> //https://github.com/taranais/NTPClient
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define TFT_GREY 0x5AEB
#define lightblue 0x01E9
#define darkred 0xA041
#define blue 0x5D9B
#include <WiFi.h>
#include <WiFiUdp.h>
#include <HTTPClient.h>
float z;
float r;
const int pwmFreq = 5000;
const int pwmResolution = 8;
const int pwmLedChannelTFT = 0;
const char* ssid = "redmizzzz"; ///EDIIIT
const char* password = "12345678"; //EDI8IT
String town="Brest"; //EDDIT
String Country="BY"; //EDDIT
const String endpoint = "http://api.openweathermap.org/data/2.5/weather?q="+town+","+Country+"&units=metric&APPID=";
const String key = "625b4ccea1d992842825753689c5a3f0"; /*EDDITTTTTTTTTTTTTTTTTTTTTTTT */
String payload=""; //whole json
String tmp="" ; //temperatur
String hum="" ; //humidity
int i=0;
StaticJsonDocument<1000> doc;
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
// Variables to save date and time
String formattedDate;
String dayStamp;
String timeStamp;
int backlight[5] = {10,30,60,120,220};
byte b=1;
#define temperatureCelsius
//BLE Server name (the other ESP32 name running the server sketch)
#define bleServerName "BME280_ESP32"
/* UUID's of the service, characteristic that we want to read*/
// BLE Service
static BLEUUID bmeServiceUUID("91bad492-b950-4226-aa2b-4ede9fa42f59");
// BLE Characteristics
#ifdef temperatureCelsius
//Temperature Celsius Characteristic
static BLEUUID temperatureCharacteristicUUID("cba1d466-344c-4be3-ab3f-189f80dd7518");
#else
//Temperature Fahrenheit Characteristic
static BLEUUID temperatureCharacteristicUUID("f78ebbff-c8b7-4107-93de-889a6a06d408");
#endif
// Humidity Characteristic
static BLEUUID humidityCharacteristicUUID("ca73b3ba-39f6-4ab3-91ae-186dc9577d99");
//Flags stating if should begin connecting and if the connection is up
static boolean doConnect = false;
static boolean connected = false;
//Address of the peripheral device. Address will be found during scanning...
static BLEAddress *pServerAddress;
//Characteristicd that we want to read
static BLERemoteCharacteristic* temperatureCharacteristic;
static BLERemoteCharacteristic* humidityCharacteristic;
//Activate notify
const uint8_t notificationOn[] = {0x1, 0x0};
const uint8_t notificationOff[] = {0x0, 0x0};
//Variables to store temperature and humidity
char* temperatureChar;
char* humidityChar;
//Flags to check whether new temperature and humidity readings are available
boolean newTemperature = false;
boolean newHumidity = false;
//Connect to the BLE Server that has the name, Service, and Characteristics
bool connectToServer(BLEAddress pAddress) {
BLEClient* pClient = BLEDevice::createClient();
// Connect to the remove BLE Server.
pClient->connect(pAddress);
// Obtain a reference to the service we are after in the remote BLE server.
BLERemoteService* pRemoteService = pClient->getService(bmeServiceUUID);
if (pRemoteService == nullptr) {
return (false);
}
// Obtain a reference to the characteristics in the service of the remote BLE server.
temperatureCharacteristic = pRemoteService->getCharacteristic(temperatureCharacteristicUUID);
humidityCharacteristic = pRemoteService->getCharacteristic(humidityCharacteristicUUID);
if (temperatureCharacteristic == nullptr || humidityCharacteristic == nullptr) {
return false;
}
//Assign callback functions for the Characteristics
temperatureCharacteristic->registerForNotify(temperatureNotifyCallback);
humidityCharacteristic->registerForNotify(humidityNotifyCallback);
return true;
}
//Callback function that gets called, when another device's advertisement has been received
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
if (advertisedDevice.getName() == bleServerName) { //Check if the name of the advertiser matches
advertisedDevice.getScan()->stop(); //Scan can be stopped, we found what we are looking for
pServerAddress = new BLEAddress(advertisedDevice.getAddress()); //Address of advertiser is the one we need
doConnect = true; //Set indicator, stating that we are ready to connect
}
}
};
//When the BLE Server sends a new temperature reading with the notify property
static void temperatureNotifyCallback(BLERemoteCharacteristic* pBLERemoteCharacteristic,
uint8_t* pData, size_t length, bool isNotify) {
//store temperature value
temperatureChar = (char*)pData;
newTemperature = true;
}
//When the BLE Server sends a new humidity reading with the notify property
static void humidityNotifyCallback(BLERemoteCharacteristic* pBLERemoteCharacteristic,
uint8_t* pData, size_t length, bool isNotify) {
//store humidity value
humidityChar = (char*)pData;
newHumidity = true;
}
/////////////////////////////////////////////////////////////////////////
//function that prints the latest sensor readings in the OLED display
void printReadings(){
tft.setCursor(6, 82);
tft.println(town);
tft.println(temperatureChar);
tft.println(temperatureChar);
tft.fillRect(68,152,1,74,TFT_GREY);
}
//////////////////////////////////////////////////////////////////////////
void setup(void) {
WiFi.mode(WIFI_AP_STA);
pinMode(0,INPUT_PULLUP);
pinMode(35,INPUT);
tft.init();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE,TFT_BLACK); tft.setTextSize(1);
ledcSetup(pwmLedChannelTFT, pwmFreq, pwmResolution);
ledcAttachPin(TFT_BL, pwmLedChannelTFT);
ledcWrite(pwmLedChannelTFT, backlight[b]);
tft.print("Connecting to ");
tft.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(300);
tft.print(".");
}
delay(500);
tft.setTextColor(TFT_WHITE,TFT_BLACK); tft.setTextSize(1);
tft.fillScreen(TFT_BLACK);
tft.setSwapBytes(true);
tft.setCursor(2, 232, 1);
tft.println(WiFi.localIP());
tft.setCursor(80, 204, 1);
tft.println("BRIGHT:");
tft.setCursor(80, 152, 2);
tft.println("SEC:");
tft.setTextColor(TFT_WHITE,lightblue);
tft.setCursor(4, 152, 2);
tft.println("TEMP:");
tft.setCursor(4, 192, 2);
tft.println("HUM: ");
tft.setTextColor(TFT_WHITE,TFT_BLACK);
tft.setCursor(6, 82);
tft.println(town);
tft.println(z);
tft.println(r);
tft.fillRect(68,152,1,74,TFT_GREY);
for(int i = 0;i<b+1;i++)
tft.fillRect(78+(i*7),216,3,10,blue);
// Initialize a NTPClient to get time
timeClient.begin();
// Set offset time in seconds to adjust for your timezone, for example:
// GMT +1 = 3600
// GMT +8 = 28800
// GMT -1 = -3600
// GMT 0 = 0
timeClient.setTimeOffset(10800); /*EDDITTTTTTTTTTTTTTTTTTTTTTTT */
getData();
delay(500);
BLEDevice::init("");
BLEScan* pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true);
pBLEScan->start(5);
}
String tt="";
int count=0;
bool inv=1;
int press1=0;
int press2=0;////
int frame=0;
String curSeconds="";
void loop() {
if(digitalRead(35)==0){
if(press2==0)
{press2=1;
tft.fillRect(78,216,44,12,TFT_BLACK);
b++;
if(b>=5)
b=0;
for(int i=0;i<b+1;i++)
tft.fillRect(78+(i*7),216,3,10,blue);
ledcWrite(pwmLedChannelTFT, backlight[b]);}
}else press2=0;
if(digitalRead(0)==0){
if(press1==0)
{press1=1;
inv=!inv;
tft.invertDisplay(inv);}
}else press1=0;
if(count==0)
getData();
count++;
if(count>2000)
count=0;
tft.setCursor(2, 187);
tft.println(tmp.substring(0,3));
tft.setCursor(2, 227);
tft.println(hum+"%");
tft.setTextColor(TFT_ORANGE,TFT_BLACK);
tft.setTextFont(2);
tft.setCursor(6, 44);
tft.println(dayStamp);
tft.setTextColor(TFT_WHITE,TFT_BLACK);
while(!timeClient.update()) {
timeClient.forceUpdate();
}
// The formattedDate comes with the following format:
// 2018-05-28T16:00:13Z
// We need to extract date and time
formattedDate = timeClient.getFormattedDate();
int splitT = formattedDate.indexOf("T");
dayStamp = formattedDate.substring(0, splitT);
timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1);
if(curSeconds!=timeStamp.substring(6,8)){
tft.fillRect(78,170,48,28,darkred);
tft.setCursor(81, 192);
tft.println(timeStamp.substring(6,8));
curSeconds=timeStamp.substring(6,8);
}
String current=timeStamp.substring(0,5);
if(current!=tt)
{
tft.fillRect(3,8,120,30,TFT_BLACK);
tft.setCursor(5, 34);
tft.println(timeStamp.substring(0,5));
tt=timeStamp.substring(0,5);
}
// If the flag "doConnect" is true then we have scanned for and found the desired
// BLE Server with which we wish to connect. Now we connect to it. Once we are
// connected we set the connected flag to be true.
if (doConnect == true) {
if (connectToServer(*pServerAddress)) {
//Activate the Notify property of each Characteristic
temperatureCharacteristic->getDescriptor(BLEUUID((uint16_t)0x2902))->writeValue((uint8_t*)notificationOn, 2, true);
humidityCharacteristic->getDescriptor(BLEUUID((uint16_t)0x2902))->writeValue((uint8_t*)notificationOn, 2, true);
connected = true;
} else {
}
doConnect = false;
}
//if new temperature readings are available, print in the OLED
if (newTemperature && newHumidity){
newTemperature = false;
newHumidity = false;
printReadings();
}
delay(80);
}
void getData()
{
tft.fillRect(1,170,64,20,TFT_BLACK);
tft.fillRect(1,210,64,20,TFT_BLACK);
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
HTTPClient http;
http.begin(endpoint + key); //Specify the URL
int httpCode = http.GET(); //Make the request
if (httpCode > 0) { //Check for the returning code
payload = http.getString();
// Serial.println(httpCode);
}
else {
}
http.end(); //Free the resources
}
char inp[1000];
payload.toCharArray(inp,1000);
deserializeJson(doc,inp);
String tmp2 = doc["main"]["temp"];
String hum2 = doc["main"]["humidity"];
String town2 = doc["name"];
tmp=tmp2;
hum=hum2;
}