Skip to content

Commit

Permalink
Merge pull request #253 from kike-canaries/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
hpsaturn authored Jan 8, 2024
2 parents ce49a14 + 8a5fb55 commit 0ec03a2
Show file tree
Hide file tree
Showing 48 changed files with 1,405 additions and 484 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- master
paths-ignore:
- '**/README.md'

jobs:
build:
Expand All @@ -25,9 +27,5 @@ jobs:
platformio update
- name: Build test
run: |
./build all
./build installer
- uses: actions/upload-artifact@v2
with:
name: firmware
path: releases/installer/canairio_installer/
pio run -e TTGO_T7 -e ESP32DEVKIT -e TTGO_TDISPLAY -e M5STICKCPLUS -e ESP32C3LOLIN
4 changes: 3 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- devel
paths-ignore:
- '**/README.md'

jobs:
build:
Expand All @@ -25,5 +27,5 @@ jobs:
platformio update
- name: Build test
run: |
platformio run
pio run -e TTGO_T7 -e TTGO_TDISPLAY -e M5STICKCPLUS -e ESP32C3LOLIN
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

![CanAirIO Community](/images/canairio_collage_community.jpg)

<a href="https://play.google.com/store/apps/details?id=hpsaturn.pollutionreporter" target="_blank"><img src="https://raw.githubusercontent.com/kike-canaries/android-hpma115s0/master/assets/googleplay/gplayicon.png" align="left" width="128" ></a>
<a href="https://play.google.com/store/apps/details?id=hpsaturn.pollutionreporter" target="_blank"><img src="https://raw.githubusercontent.com/kike-canaries/android-hpma115s0/master/assets/googleplay/gplayicon.png" align="left" style="margin: 2px" width="140" ></a>

Citizen science project with mobile and fixed sensors for measuring air quality (PM 2.5 or CO2) using low-cost sensors and smartphones. Built with a `ESP32` module board interfaced with an [CanAirIO Android client app](https://github.com/kike-canaries/canairio_android).
A citizen science project that employs both mobile and fixed sensors to measure air quality (PM 2.5 or CO2) and environmental variables. This is achieved using low-cost sensors and smartphones. The project is built around an ESP32 module board integrated with the [CanAirIO Android client app](https://github.com/kike-canaries/canairio_android).

<table>
<tr>
Expand All @@ -22,15 +22,15 @@ Citizen science project with mobile and fixed sensors for measuring air quality
- Super easy [web installer](https://canair.io/installer), via Chrome or Edge
- Mobile station (via Bluetooth LE for tag GPS variables)
- Fixed station, (using only your WiFi)
- Fast WiFi credentials provisioning via Bluetooth
- Fast WiFi credentials provisioning via Bluetooth or via
- [CLI tool](https://canair.io/docs/cli.html) alternative for configuration and provisioning
- Automatic firmware OTA updates (stable/testing channels)
- Based on [CanAirIO Sensors Library](https://github.com/kike-canaries/canairio_sensorlib#readme) to support more sensors in the future
- Automatic firmware OTA updates (with stable/testing channels)
- Share mobile tracks via [mobile.canair.io](https://mobile.canair.io) or [CanAirIO app](https://github.com/kike-canaries/canairio_android)
- [Home Assistant](https://www.home-assistant.io/) integration, discovery and multisensor support
- Share your fixed station quickly via [Anaire Cloud](https://portal.anaire.org/d/detail/detalle?orgId=1&var-uid=U33TTGOTDA3D46&var-name=&refresh=1m)
- Separated [sensors layer](https://github.com/kike-canaries/canairio_sensorlib#readme) for improve support of new sensors
- PAX Counter feature (default wifi sniffer sensor to count people)
- Multiple boards and sensors support with only one firmware
- Multiple boards and sensors supported with only one firmware

## Boards supported

Expand All @@ -50,12 +50,13 @@ The [last release](https://github.com/kike-canaries/canairio_firmware/releases)
| **ESP32C3OIPLUS** | TTGO-T-OI-Plus | OLED | BLE not supported |
| **ESP32C3LOLIN** | LOLIN Mini C3 | OLED | BLE not supported |
| **ESP32C3SEEDX** | Seeed_xiao_esp32c3 | OLED | BLE not supported |
| **ESP32S3** | T7S3 and Makerfabs | - | In development |

** is possible that the **current firmware supports more boards** and sensors. Also you can choose the sensor brand or type on the CanAirIO Android app.
** is possible that the **current firmware supports more boards** and sensors. Also you can choose the sensor brand or type on the CanAirIO Android app or on the firmware CLI.

# Installation alternatives

We have different alternatives for load the current firmware. In order of complexity they are:
We have different alternatives to load the current firmware. By complexity order, they are:

## Via CanAirIO Web Installer (RECOMMENDED)

Expand All @@ -66,15 +67,15 @@ If you already have a ESP32 board, you can test our CanAirIO firmware on one cli

## Via CanAirIO loader

You will able to install the last version of CanAirIO firmware with internet updates via a simple Arduino sketch that it will doing all for you, you only need to use the official [Arduino IDE](https://www.arduino.cc/en/software) or [Arduino Droid app for Android](https://play.google.com/store/apps/details?id=name.antonsmirnov.android.arduinodroid2&hl=en&gl=US) for load this [simple sketch](https://github.com/hpsaturn/esp32-canairio-loader/blob/master/canairio_loader/canairio_loader.ino). Please follow the instructions [here](https://github.com/hpsaturn/esp32-canairio-loader) or follow the next [YouTube video guide](https://youtu.be/FjfGdnTk-rc) for Android OTG installation alternative.
You will able to install the last version of CanAirIO firmware using a simple Arduino sketch that it will doing all for you, you only need to use the official [Arduino IDE](https://www.arduino.cc/en/software) or [Arduino Droid app for Android](https://play.google.com/store/apps/details?id=name.antonsmirnov.android.arduinodroid2&hl=en&gl=US) for load this [simple sketch](https://github.com/hpsaturn/esp32-canairio-loader/blob/master/canairio_loader/canairio_loader.ino). Please follow the instructions [here](https://github.com/hpsaturn/esp32-canairio-loader) or follow the next [YouTube video guide](https://youtu.be/FjfGdnTk-rc) for Android OTG installation alternative.

## Via binaries

You can download the last firmware version in [releases](https://github.com/kike-canaries/esp32-hpma115s0/releases) section. For example, download the last **production** release from `assets` section, like this:

![releases assets](images/assets.jpg)

please uncompress the zip file and connect your CanAirIO device to your USB and execute the next command for upload the firmware to your model board, for example for an ESP32DevKit board you should run the next commands:
please uncompress the zip file and connect your CanAirIO device to your USB and execute the next command to upload the firmware to your board, for example for an ESP32DevKit board you should run the next commands:

### Linux and MacOSx

Expand All @@ -88,7 +89,7 @@ esptool --port /dev/ttyUSB0 -b 1500000 write_flash 0x0 canairio_ESP32DEVKIT_rev9

### Windows

Please read the [Espressif Uploader](https://canair.io/docs/firmware_upload.html#espressif-uploader) section in the main documentation for details to load the firmware via the oficial **Espressif Download Tool** in Windows.
Please read the [Espressif Uploader](https://canair.io/docs/firmware_upload.html#espressif-uploader) section in the main documentation to have details of how load the firmware via the official **Espressif Download Tool** in Windows.

## Via PlatformIO (Compiling on Linux, Mac or Windows)

Expand Down Expand Up @@ -124,9 +125,9 @@ This build a basic compiler image with all PlatformIO stuff. For build the proje

## OTA WAN updates

CanAirIO has two channels to have remote OTA updates of your device, the production channel and development channel. With that you don't need again install the firmware again for any update, all here is automatic and you only need have WiFi enable on your device for receive this firmware updates.
CanAirIO offers two channels for remote OTA (Over-The-Air) updates for your device: the production channel and the development channel. This means you won't need to reinstall the firmware manually for any updates; it's all automatic. You only need to have Wi-Fi enabled on your device to receive these firmware updates.

If you want the last testing updates, please choose in releases the development firmware (zip file with **dev** name), and upload it to your board or via the web installer choose testing option of each firmare.
If you're interested in the latest testing updates, please go to the releases section and choose and download the development firmware (a zip file with `dev` in its name), then upload it to your board to receive these kind of updates.

# Supporting the project

Expand All @@ -142,15 +143,18 @@ When creating a pull request, we recommend that you do the following:

Also you can consider make a donation, be a patron or buy a device:


- Via **Ethereum**:
- 0x1779cD3b85b6D8Cf1A5886B2CF5C53a0E072C108
- Be a patron: [Github Sponsors](https://github.com/sponsors/hpsaturn), [LiberaPay](https://liberapay.com/CanAirIO)
- **Buy a device**: [CanAirIO Bike in Tindie](https://www.tindie.com/products/hpsaturn/canairio-bike/)
- Inviting us **a coffee**: [buymeacoffee](https://www.buymeacoffee.com/hpsaturn), [Sponsors](https://github.com/sponsors/hpsaturn?frequency=one-time)

<a href="https://raw.githubusercontent.com/kike-canaries/canairio_firmware/master/images/ethereum_donation_address.png" target="_blank"><img src="https://raw.githubusercontent.com/kike-canaries/canairio_firmware/master/images/ethereum_donation_address.png" align="center_horizontal" width="180" ></a>
<a href="https://raw.githubusercontent.com/kike-canaries/canairio_firmware/master/images/ethereum_donation_address.png" target="_blank"><img src="https://raw.githubusercontent.com/kike-canaries/canairio_firmware/master/images/ethereum_donation_address.png" align="left" style="margin: 10px" width="140" ></a>

**NOTE:**
Supporting our Citizen Science Initiative many people be able to fight for air quality rights in many countries with this kind of problems. More info in [CanAir.IO](https://canair.io)

**NOTE:** Supporting our Citizen Science Initiative many people be able to fight for air quality rights in many countries with this kind of problems. More info in [CanAir.IO](https://canair.io)

# CanAirIO device HOWTO guide

Expand All @@ -172,7 +176,7 @@ We have some build guides with different alternatives, please visit our [CanAirI

** W A R N N I N G **

The full updated and last versions for all box versions, are in the [official repository](https://github.com/kike-canaries/canairio_firmware/tree/master/box) because it is more easy for handling the versions than Thingiverse. This page it is only a guide.
The last versions for all box versions, are in the [official repository](https://github.com/kike-canaries/canairio_firmware/tree/master/box) because it is more easy for handling the versions than Thingiverse.

# TODO

Expand All @@ -190,5 +194,7 @@ The full updated and last versions for all box versions, are in the [official re
- [x] Pax counter disable/enable
- [x] Home Assistant integration (with zero-config)
- [x] Anaire cloud integration (Automatic time series of your station)
- [x] Fahrenheit and Kelvin units supported
- [x] Geiger sensor supported
- [ ] Sensor community alternativa for fixed stations
- [ ] Anonymous authentication
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ OWNER="kike-canaries"
REPO="canairio_firmware"
INSDIR=$RELDIR/installer/${NAME}_installer

flavors="TTGO_T7 WEMOSOLED HELTEC TTGO_TQ ESP32DEVKIT TTGO_TDISPLAY ESP32PICOD4 M5STICKCPLUS M5ATOM M5PICOD4 ESP32C3 ESP32C3OIPLUS ESP32C3LOLIN ESP32C3SEEDX"
flavors="TTGO_T7 WEMOSOLED HELTEC TTGO_TQ ESP32DEVKIT TTGO_TDISPLAY ESP32PICOD4 M5STICKCPLUS M5ATOM M5PICOD4 ESP32C3 ESP32C3OIPLUS ESP32C3LOLIN ESP32C3SEEDX ESP32S3 TTGO_T7S3 LORADEVKIT"
#flavors="TTGO_T7 WEMOSOLED ESP32DEVKIT TTGO_TDISPLAY M5STICKCPLUS M5ATOM ESP32C3 ESP32C3OIPLUS ESP32C3LOLIN ESP32C3SEEDX"
#flavors="TTGO_T7 ESP32C3 ESP32C3OIPLUS ESP32C3LOLIN ESP32C3SEEDX"

Expand Down Expand Up @@ -81,6 +81,8 @@ build () {
cp $OUTDIR/$1/firmware.bin $FIRMDIR/${NAME}_${1}_rev${SRC_REV}.bin
if [ $1 == ESP32C3 ] || [ $1 == ESP32C3LOLIN ] || [ $1 == ESP32C3SEEDX ] || [ $1 == ESP32C3OIPLUS ]; then
/usr/bin/python3 ${PIO_HOME}/packages/tool-esptoolpy/esptool.py --chip esp32c3 merge_bin -o $FIRMDIR/${NAME}_${1}_rev${SRC_REV}_merged.bin --flash_mode dio --flash_freq 80m --flash_size 4MB 0x0000 $OUTDIR/$1/bootloader.bin 0x8000 $OUTDIR/$1/partitions.bin 0xe000 ${PIO_HOME}/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 $OUTDIR/$1/firmware.bin
elif [ $1 == ESP32S3 ] || [ $1 == TTGO_T7S3 ]; then
/usr/bin/python3 ${PIO_HOME}/packages/tool-esptoolpy/esptool.py --chip esp32s3 merge_bin -o $FIRMDIR/${NAME}_${1}_rev${SRC_REV}_merged.bin --flash_mode dio --flash_freq 80m --flash_size 8MB 0x0000 $OUTDIR/$1/bootloader.bin 0x8000 $OUTDIR/$1/partitions.bin 0xe000 ${PIO_HOME}/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 $OUTDIR/$1/firmware.bin
else
esptool --chip esp32 merge_bin -o $FIRMDIR/${NAME}_${1}_rev${SRC_REV}_merged.bin --flash_mode dio --flash_freq 40m --flash_size 4MB 0x1000 ${PIO_HOME}/packages/framework-arduinoespressif32@3.20003.220626/tools/sdk/esp32/bin/bootloader_dio_40m.bin 0x8000 $OUTDIR/$1/partitions.bin 0xe000 ${PIO_HOME}/packages/framework-arduinoespressif32@3.20003.220626/tools/partitions/boot_app0.bin 0x10000 $OUTDIR/$1/firmware.bin
fi
Expand Down
Binary file added docs/CO, NH3, Gas Sensor Wiki - DFRobot.pdf
Binary file not shown.
Binary file added docs/dfrobot board size.pdf
Binary file not shown.
Binary file added docs/dfrobot datasheet.pdf
Binary file not shown.
Binary file added docs/t7_s3_v1.2.pdf
Binary file not shown.
Binary file added docs/t7_v1.3.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions include/logmem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <ConfigApp.hpp>
#include <GUILib.hpp>
#include <Sensors.hpp>

void logMemory(const char* msg);
void logMemoryObjects();
4 changes: 4 additions & 0 deletions include/power.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#ifdef CONFIG_IDF_TARGET_ESP32S3
#include "driver/temp_sensor.h"
#endif
#include <driver/rtc_io.h>
#include <esp_bt.h>
#include <esp_bt_main.h>
#include <esp_wifi.h>

#include <Batterylib.hpp>

float powerESP32TempRead();
void powerCompleteShutdown();
void powerDeepSleepButton();
void powerDeepSleepTimer(int);
Expand Down
8 changes: 4 additions & 4 deletions include/wifi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#include <cloud_anaire.hpp>
#include <cloud_hass.hpp>
#include <cloud_influxdb.hpp>
#include <ESP32WifiCLI.hpp>

#ifndef DISABLE_CLI
#include <cli.hpp>
#endif

//#define IFX_RETRY_CONNECTION 5 // influxdb publish retry

Expand All @@ -26,11 +29,8 @@ void wifiInit();
void wifiStop();
void wifiRestart();
void wifiLoop();
void cliInit();
void cliTaskInit();

int getWifiRSSI();
void printWifiRSSI();
String getDeviceInfo();
String getHostId();
void logMemory(const char *msg);
29 changes: 29 additions & 0 deletions lib/batterylib/battery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Battery {
CircularBuffer<float, SAMPLES> buffer;
int isDischarging = -1;

float btDiscVMin = 0.0;
float btDiscVMax = 0.0;
float btCharVMin = 0.0;
float btCharVMax = 0.0;

virtual void init(bool debug = false) = 0;
virtual void update() = 0;
virtual float getVoltage() = 0;
Expand Down Expand Up @@ -54,6 +59,30 @@ class Battery {
this->callback = callbacks;
}

void setLimits(float battDiscVMin, float battDiscVMax, float battChargVMin, float battChargVMax) {
this->btDiscVMin = battDiscVMin;
this->btDiscVMax = battDiscVMax;
this->btCharVMin = battChargVMin;
this->btCharVMax = battChargVMax;
}

void setBattLimits(float battMinV, float battMaxV) {
this->btDiscVMin = battMinV;
this->btDiscVMax = battMaxV;
}

void setChargLimits(float chargMinV, float chargMaxV) {
this->btCharVMin = chargMinV;
this->btCharVMax = chargMaxV;
}

void printLimits(){
Serial.printf("-->[BATT] BVmin:%1.2f BVmax:%1.2f\t: CVmax:%1.2f CVmin:%1.2f\r\n",
btDiscVMin, btDiscVMax,
btCharVMin, btCharVMax
);
}

void loop() {
static uint32_t pmLoopTimeStamp = 0; // timestamp for sensor loop check data
if ((millis() - pmLoopTimeStamp > interval)) { // sample time for each capture
Expand Down
7 changes: 4 additions & 3 deletions lib/batterylib/battery_m5stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
void Battery_M5STACK::init(bool debug) {
this->debug = debug;
M5.Axp.EnableCoulombcounter(); // Enable Coulomb counter.
setLimits(BATTERY_MIN_V, BATTERY_MAX_V, BATTCHARG_MIN_V, BATTCHARG_MAX_V);
}

float Battery_M5STACK::getVoltage() {
Expand All @@ -17,14 +18,14 @@ void Battery_M5STACK::update() {
}

bool Battery_M5STACK::isCharging() {
return M5.axp.GetVBusVoltage() > BATTCHARG_MAX_V;
return M5.axp.GetVBusVoltage() > btCharVMax;
}

int Battery_M5STACK::getCharge() {
if (isCharging()) {
return calcPercentage(curv, BATTCHARG_MAX_V, BATTCHARG_MIN_V);
return calcPercentage(curv, btCharVMax, btCharVMin);
} else {
return calcPercentage(curv, BATTERY_MAX_V, BATTERY_MIN_V);
return calcPercentage(curv, btDiscVMax, btDiscVMin);
}
}

Expand Down
25 changes: 15 additions & 10 deletions lib/batterylib/battery_oled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#elif TTGO_T7
#define ADC_PIN 35
int channel_atten = ADC1_CHANNEL_7;
#elif TTGO_T7S3
#define ADC_PIN 2
int channel_atten = ADC1_CHANNEL_1;
#else
#define ADC_PIN 34
int channel_atten = 0;
Expand All @@ -17,14 +20,15 @@ void Battery_OLED::setupBattADC() {
// TODO: all here is deprecated we need review the documentation
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)channel_atten, (adc_bits_width_t)ADC_WIDTH_BIT_12, 1100, &adc_chars);
analogReadResolution(12);
// 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\r\n", adc_chars.vref);
log_i("[BATT] ADC eFuse Vref \t: %u mV\r\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\r\n", adc_chars.coeff_a, adc_chars.coeff_b);
log_i("[BATT] ADC Two Point coeff_a\t: %umV coeff_b:%umV\r\n", adc_chars.coeff_a, adc_chars.coeff_b);
} else {
Serial.printf("-->[BATT] ADC Default Vref: %u mV\r\n", vref);
log_i("[BATT] ADC Default Vref \t: %u mV\r\n", vref);
}
}

Expand All @@ -40,6 +44,7 @@ void Battery_OLED::init(bool debug) {
delay(10); // suggested by @ygator user in issue #2
setupBattADC();
delay(10); // suggested by @ygator user in issue #2
setLimits(BATTERY_MIN_V, BATTERY_MAX_V, BATTCHARG_MIN_V, BATTCHARG_MAX_V);
}

float Battery_OLED::getVoltage() {
Expand All @@ -51,7 +56,7 @@ bool Battery_OLED::isCharging() {
if (isDischarging >= 0)
charging = !isDischarging;
else
charging = curv > BATTERY_MAX_V + (BATTCHARG_MIN_V - BATTERY_MAX_V) / 2;
charging = curv > btDiscVMax + (btCharVMin - btDiscVMax) / 2;
// if (debug) Serial.printf("-->[BATT] Batt is charging\t: %s\r\n", charging ? "True" : "False");
return charging;
}
Expand All @@ -65,7 +70,7 @@ void Battery_OLED::update() {
digitalWrite(ADC_EN, HIGH);
delay(10); // suggested by @ygator user in issue #2
uint16_t v = analogRead(ADC_PIN);
#ifdef TTGO_T7
#if defined(TTGO_T7) || defined(TTGO_T7S3)
curv = ((float)v / 4095.0) * 7.58;
#else
curv = ((float)v / 4095.0) * 15.83;
Expand All @@ -74,11 +79,11 @@ void Battery_OLED::update() {
}

int Battery_OLED::getCharge() {
if (isCharging()) {
return calcPercentage(curv, BATTCHARG_MAX_V, BATTCHARG_MIN_V);
} else {
return calcPercentage(curv, BATTERY_MAX_V, BATTERY_MIN_V);
}
if (isCharging()) {
return calcPercentage(curv, btCharVMax, btCharVMin);
} else {
return calcPercentage(curv, btDiscVMax, btDiscVMin);
}
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_OLEDBATTERY)
Expand Down
5 changes: 3 additions & 2 deletions lib/batterylib/battery_oled.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#include <battery.hpp>
#include <esp_adc_cal.h>

#ifdef TTGO_T7
#if defined(TTGO_T7) || defined(TTGO_T7S3)
#define BATTERY_MIN_V 3.4
#define BATTERY_MAX_V 4.28
#define BATTCHARG_MIN_V 3.8
#define BATTCHARG_MAX_V 4.34
#else
#define BATTERY_MIN_V 3.4

#define BATTERY_MIN_V 3.1
#define BATTERY_MAX_V 4.04
#define BATTCHARG_MIN_V 4.06
#define BATTCHARG_MAX_V 4.198
Expand Down
Loading

0 comments on commit 0ec03a2

Please sign in to comment.