Skip to content

Commit

Permalink
Merge pull request #199 from kike-canaries/devel
Browse files Browse the repository at this point in the history
solar station mode feature
  • Loading branch information
hpsaturn authored Mar 4, 2022
2 parents 5648496 + 88f57a1 commit b2a8af6
Show file tree
Hide file tree
Showing 33 changed files with 399 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# These are supported funding model platforms
github: hpsaturn
liberapay: CanAirIO
github: hpsaturn

15 changes: 3 additions & 12 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
about: Create a report to help us improve. Thanks to contribute.
title: ''
labels: bug
assignees: ''

---
Thanks for help up and contribute to CanAirIO project. Please edit and fill this template. We recommend at less fill the description.

## Description


## To reproduce
## Overview


## Debug output


## Device config

If apply, please write the next information, you can have it on the settings section `Device info` on the CanAirIO app.
**If apply**, please write the next information, you can have it on the settings section `Device info` on the CanAirIO app.

```
board: please choose any TTGO T7, TTGO T-Display, ESP32DevKit, WemosOLED, etc
firmware version: revxxx
mobile app version: revxxx
sensors: (sensors references and type connection)
OLED: yes/no
TFT: yes/no
Power: Battery/USB
```

## Additional context


2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ assignees: ''

---

**Summary.**
## Summary

8 changes: 2 additions & 6 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
## Description

*Replace this paragraph with a description of what this PR is doing. If you're modifying existing behavior, describe the existing behavior, how this PR is changing it, and what motivated the change. If you're changing visual properties, consider including before/after screenshots (and runnable code snippets to reproduce them).*
*Replace this paragraph with a description of what this PR is doing.*

## Related Issues

*Replace this paragraph with a list of issues related to this PR from our [issue database]. Indicate, which of these issues are resolved or fixed by this PR. There should be at least one issue listed here.*
*Replace this paragraph with a list of issues related to this PR from our [issue database].*

## Tests

I added the following tests:

*Replace this with a list of the tests that you added as part of this PR.
Binary file not shown.
6 changes: 4 additions & 2 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ showHelp () {
echo "example: ./build installer"
echo ""
echo "Supported boards: "
echo "TTGO_T7, WEMOSOLED, HELTEC, TTGO_TQ, ESP32DEVKIT"
echo "TTGO_T7, WEMOSOLED, HELTEC, TTGO_TQ, ESP32DEVKIT, ESP32PICOD4, M5PICOD4"
echo ""
echo "Build installer option will make a installer package for Linux"
echo "with OTA support and USB support"
Expand Down Expand Up @@ -153,14 +153,16 @@ else
;;

all)
clean
build TTGO_T7
build WEMOSOLED
build HELTEC
build TTGO_TQ
build ESP32DEVKIT
build TTGO_TDISPLAY
build ESP32PICOD4
build M5STICKCPLUS
build M5ATOM
build M5PICOD4
printOutput
;;

Expand Down
Binary file added docs/t7_v1.5.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion include/cloud_influxdb.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define IFX_RETRY_CONNECTION 5 // influxdb publish retry
#define IFX_RETRY_CONNECTION 5 // influxdb publish retry
#define IFX_ERROR_COUNT_MAX 5 // max error count before full ESP restart

void influxDbInit();
void influxDbLoop();
Expand Down
14 changes: 14 additions & 0 deletions include/power.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <driver/rtc_io.h>
#include <esp_bt.h>
#include <esp_bt_main.h>
#include <esp_wifi.h>

#include <Batterylib.hpp>

void powerDeepSleepButton();
void powerDeepSleepTimer(int);
void powerLightSleepTimer(int);
void powerEnableSensors();
void powerDisableSensors();
void powerLoop();
void powerInit();
3 changes: 3 additions & 0 deletions include/wifi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#include <GUILib.hpp>
#include <Watchdog.hpp>
#include <Sensors.hpp>
#include <power.hpp>
#include <cloud_anaire.hpp>
#include <cloud_hass.hpp>
#include <cloud_influxdb.hpp>

//#define IFX_RETRY_CONNECTION 5 // influxdb publish retry

#define PUBLISH_INTERVAL 30 // publish to cloud each 30 seconds
#define WIFI_RETRY_CONNECTION 30 // 30 seconds wait for wifi connection
#define MQTT_RETRY_CONNECTION 1 // mqtt publish retry
Expand Down
2 changes: 0 additions & 2 deletions lib/batterylib/battery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class BatteryUpdateCallbacks {

class Battery {
public:

int vref = 1100;
float curv = 0.0;
bool debug;

Expand Down
58 changes: 46 additions & 12 deletions lib/batterylib/battery_oled.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,69 @@
#include <battery_oled.hpp>

#ifndef M5STICKCPLUS
#ifndef TTGO_TDISPLAY
void Battery_OLED::setupBattADC() {
esp_adc_cal_characteristics_t adc_chars;
esp_adc_cal_value_t val_type = esp_adc_cal_characterize((adc_unit_t)ADC_UNIT_1, (adc_atten_t)ADC1_CHANNEL_6, (adc_bits_width_t)ADC_WIDTH_BIT_12, 1100, &adc_chars);
// Check type of calibration value used to characterize ADC
if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
Serial.printf("-->[BATT] ADC eFuse Vref:%u mV\n", adc_chars.vref);
vref = adc_chars.vref;
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
Serial.printf("-->[BATT] ADC Two Point --> coeff_a:%umV coeff_b:%umV\n", adc_chars.coeff_a, adc_chars.coeff_b);
} else {
Serial.printf("-->[BATT] ADC Default Vref: %u mV\n", vref);
}
}

void Battery_OLED::init(bool debug) {
this->debug = debug;
/*
ADC_EN is the ADC detection enable port
If the USB port is used for power supply, it is turned on by default.
If it is powered by battery, it needs to be set to high level
*/
pinMode(ADC_EN, OUTPUT);
digitalWrite(ADC_EN, HIGH);
delay(10); // suggested by @ygator user in issue #2
setupBattADC();
delay(10); // suggested by @ygator user in issue #2
}

float Battery_OLED::getVoltage() {
return 0;
return curv;
}

bool Battery_OLED::isCharging() {
return false;
return curv > BATTERY_MAX_V + (BATTCHARG_MIN_V - BATTERY_MAX_V) / 2;
}

void Battery_OLED::printValues() {
void Battery_OLED::printValues() {
if (!debug) return;
Serial.printf("-->[BATT] Battery voltage \t: %.3fv vref: %i Charge:%i\n", curv, vref, getCharge()); // Output voltage and current of Bat
}

void Battery_OLED::update() {
void Battery_OLED::update() {
digitalWrite(ADC_EN, HIGH);
delay(10); // suggested by @ygator user in issue #2
uint16_t v = analogRead(ADC_PIN);
curv = ((float)v / 4095.0) * 15.83;
digitalWrite(ADC_EN, LOW); // for possible issue: https://github.com/Xinyuan-LilyGO/TTGO-T-Display/issues/6

}

int Battery_OLED::getCharge() {
return 0;
if (isCharging()) {
return calcPercentage(curv, BATTCHARG_MAX_V, BATTCHARG_MIN_V);
} else {
return calcPercentage(curv, BATTERY_MAX_V, BATTERY_MIN_V);
}
// return 0;
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_OLEDBATTERY)
Battery_OLED battery;
#endif

#ifndef M5STICKCPLUS
#ifndef TTGO_TDISPLAY
Battery_OLED battery;
#endif
#endif



#endif
17 changes: 14 additions & 3 deletions lib/batterylib/battery_oled.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
#define battery_oled_hpp

#include <battery.hpp>
#include <esp_adc_cal.h>

#define BATTERY_MIN_V 3.4
#define BATTERY_MAX_V 4.1
#define BATTCHARG_MIN_V 4.65
#define BATTCHARG_MAX_V 4.8
#define BATTERY_MAX_V 4.04
#define BATTCHARG_MIN_V 3.69
#define BATTCHARG_MAX_V 4.198
#define ADC_EN 14

#ifdef M5PICOD4
#define ADC_PIN 36
#else
#define ADC_PIN 34
#endif

class Battery_OLED : public Battery {
public:
Expand All @@ -16,6 +24,9 @@ class Battery_OLED : public Battery {
int getCharge();
void printValues();
void update();
private:
int vref = 1086;
void setupBattADC();
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_OLEDBATTERY)
Expand Down
5 changes: 1 addition & 4 deletions lib/batterylib/battery_tft.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include <battery_tft.hpp>

int vref = 1100;
float curv = 0;

void setupBattADC() {
void Battery_TFT::setupBattADC() {
esp_adc_cal_characteristics_t adc_chars;
esp_adc_cal_value_t val_type = esp_adc_cal_characterize((adc_unit_t)ADC_UNIT_1, (adc_atten_t)ADC1_CHANNEL_6, (adc_bits_width_t)ADC_WIDTH_BIT_12, 1100, &adc_chars);
//Check type of calibration value used to characterize ADC
Expand Down
3 changes: 3 additions & 0 deletions lib/batterylib/battery_tft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class Battery_TFT : public Battery {
int getCharge();
void printValues();
void update();
private:
int vref = 1100;
void setupBattADC();
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_TFTHANDLER)
Expand Down
14 changes: 8 additions & 6 deletions lib/canairioota/src/OTAHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ OTAHandler::OTAHandler(){
}

void OTAHandler::setup(const char* ESP_ID, const char* ESP_PASS) {
#ifdef ENABLE_OTA
_ESP_ID = ESP_ID;
_ESP_PASS = ESP_PASS;
_baud = 1500000;
Expand Down Expand Up @@ -40,16 +41,15 @@ void OTAHandler::setup(const char* ESP_ID, const char* ESP_PASS) {
});

ArduinoOTA.begin();

// Remote OTA config
// TODO: pass host and target via bluetooth

fota.checkURL = "http://influxdb.canair.io:8080/releases/" + String(TARGET) + "/firmware_" + String(FLAVOR) + ".json";


Serial.print("-->[INFO] local OTA updates on\t: ");
Serial.print(ESP_ID);
Serial.print(".local passw: ");
Serial.println(ESP_PASS);
#endif
// Remote OTA config
// TODO: pass host and target via bluetooth
fota.checkURL = "http://influxdb.canair.io:8080/releases/" + String(TARGET) + "/firmware_" + String(FLAVOR) + ".json";
}

void OTAHandler::checkRemoteOTA(bool notify) {
Expand All @@ -74,7 +74,9 @@ void OTAHandler::remoteOTAcheckloop() {
}

void OTAHandler::loop() {
#ifdef ENABLE_OTA
ArduinoOTA.handle();
#endif
remoteOTAcheckloop();
}

Expand Down
6 changes: 5 additions & 1 deletion lib/canairioota/src/OTAHandler.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#ifndef OTA_Handler_H
#define OTA_Handler_H

#ifdef ENABLE_OTA
#include <ArduinoOTA.h>
#endif

#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

#include <esp_system.h>
#include <esp32fota.h>
#include <esp_task_wdt.h>
Expand Down
Loading

0 comments on commit b2a8af6

Please sign in to comment.