Skip to content

Commit

Permalink
Mudança no WiFi e no gerenciamento de energia
Browse files Browse the repository at this point in the history
Usa esp_wifi.h em vez de WiFi.h
Adicionado esp_wifi_set_ps para forçar o WiFi a estar em modo de economia de energia
Diminuição do clock do processador de 240Mhz (default) para 80Mhz
Diminuição do brilho para 9
  • Loading branch information
SatsCzar committed Jan 4, 2023
1 parent a4580cd commit c922236
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions blockclock/blockclock.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include <HTTPClient.h>
#include <M5StickCPlus.h>
#include <WiFiMulti.h>

#include <cmath>
#include <string>

#include "WiFi.h"
#include "esp32-hal-cpu.h"
#include "esp_wifi.h"

WiFiMulti wifiMulti;
HTTPClient http;

String blockHeightGlobal;
Expand All @@ -18,19 +17,29 @@ const float BATTERY_MIN_VOLTAGE = 3.7;
const float BATTERY_MAX_VOLTAGE = 4.1;

void setup() {
setCpuFrequencyMhz(80); // Lower processor clock to save power
M5.begin(true, true, false);

M5.Lcd.setTextSize(2);
M5.Lcd.setRotation(1);
M5.Axp.ScreenBreath(9);

M5.Lcd.setCursor(10, 10);
M5.Lcd.println("BLOCKCLOCK");
M5.Lcd.setCursor(10, 30);
M5.Lcd.println("Connecting Wifi");
wifiMulti.addAP(SSID, PASSWD);

M5.Lcd.setCursor(10, 50);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASSWD);

while (millis() < 3000 && WiFi.status() != WL_CONNECTED) {
// Await fot WiFi connect
}

esp_wifi_set_ps(WIFI_PS_MAX_MODEM); // Set max power save

if (wifiMulti.run() == WL_CONNECTED) {
M5.Lcd.setCursor(10, 50);
if (WiFi.status() == WL_CONNECTED) {
M5.Lcd.println("Wifi connected");
M5.Lcd.setCursor(10, 70);
delay(500);
Expand All @@ -42,7 +51,7 @@ void setup() {
void loop() {
String blockheight;

if (wifiMulti.run() == WL_CONNECTED) {
if (WiFi.status() == WL_CONNECTED) {
blockheight = getBlockHeight();
if (blockheight != blockHeightGlobal) {
blockHeightGlobal = blockheight;
Expand All @@ -53,7 +62,7 @@ void loop() {
if (!isCharging()) {
printBattery();
}
delay(60000); // 1 minute
delay(60000); // 1 minute
}

String getBlockHeight() {
Expand Down Expand Up @@ -96,3 +105,4 @@ int calculateBatteryPercentage(float voltage) {
}

void clearScreen() { M5.Lcd.fillRect(0, 0, 240, 135, BLACK); }

0 comments on commit c922236

Please sign in to comment.