first commit

master
cheetah 2 years ago
commit 1e7950b671

@ -0,0 +1 @@
Subproject commit 1a0e347eb0534a2b1a1970110cdba4d3126db764

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

@ -0,0 +1,20 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:seeed_xiao_esp32c3]
platform = espressif32
board = seeed_xiao_esp32c3
framework = arduino
monitor_speed = 115200
monitor_port = /dev/ttyACM0
upload_port = /dev/ttyACM0
lib_deps =
paulstoffregen/OneWire@^2.3.7
milesburton/DallasTemperature@^3.11.0

@ -0,0 +1,200 @@
#include <Arduino.h>
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */
void print_wakeup_reason() {
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
case ESP_SLEEP_WAKEUP_GPIO : Serial.println("Wakeup caused by GPIO0"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
}
}
void deepsleep_fix_check() {
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_GPIO :
esp_cpu_reset(0);
esp_cpu_reset(1);
break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
}
}
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(D0);
DallasTemperature sensors(&oneWire);
uint8_t sensorCount = 0;
DeviceAddress devices[20];
int32_t rawTemperatures[20];
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include <BLECast.h>
BLECast bleCast("cat");
void tempSetup() {
sensors.begin();
sensors.setResolution(12);
}
void tempLoop() {
uint8_t scanOffset = 0;
do {
byte i;
if (!oneWire.search(devices[scanOffset])) {
oneWire.reset_search();
delay(250);
break;
}
Serial.print("ScanOffset="); Serial.print(scanOffset);
Serial.print(" ROM =");
for (i = 0; i < 8; i++) Serial.print(devices[scanOffset][i], HEX);
Serial.println();
scanOffset++;
} while (true);
delay(250);
Serial.print("Requesting temperatures...");
sensors.requestTemperatures();
Serial.println("DONE");
//
for (uint8_t addressIndex = 0; addressIndex < scanOffset; addressIndex++) {
sensors.setResolution(devices[addressIndex], 12);
Serial.print("ScanOffset="); Serial.print(addressIndex);
Serial.print("=");
for (uint8_t i = 0; i < 8; i++) Serial.print(devices[addressIndex][i], HEX);
Serial.print("=");
int32_t temp = sensors.getTemp(devices[addressIndex]);
Serial.print(temp);
Serial.print("=");
Serial.println(sensors.rawToCelsius(temp));
rawTemperatures[addressIndex] = temp;
}
sensorCount = scanOffset;
}
uint16_t batteryMillivolts = 0;
uint8_t batteryLevel = 0;
void battSetup(){
pinMode(A1, INPUT);
}
void battLoop() {
uint32_t Vbatt = 0;
for (int i = 0; i < 16; i++) Vbatt = Vbatt + analogReadMilliVolts(A1); // denoise ADC
Serial.println(Vbatt / 16, 3);
float Vbattf = 1.455 * Vbatt / 16; /// 1000.0;
Serial.println(Vbattf, 3);
batteryMillivolts = (uint16_t)Vbattf;
delay(1000);
}
void setup() {
Serial.begin(115200);
delay(1000);
deepsleep_fix_check();
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
tempSetup();
battSetup();
bleCast.begin();
}
struct AdvDataTemps {
uint16_t vBatt;
uint16_t addr1;
int16_t temp1;
uint16_t addr2;
int16_t temp2;
uint16_t addr3;
int16_t temp3;
uint16_t addr4;
int16_t temp4;
uint16_t addr5;
int16_t temp5;
} advdat;
uint16_t getSensorAddrShort(uint8_t index) {
uint16_t res = 0x0000;
res = devices[index][6] << 8;
res = res | devices[index][7];
return res;
}
uint8_t sensorOffset = 0;
uint8_t loopCounter = 0;
void loop() {
if (loopCounter++ >= 3){
Serial.println("going to sleep now");
delay(1000);
bleCast.end();
oneWire.reset();
esp_deep_sleep_start();
return;
}
tempLoop();
battLoop();
advdat.vBatt = batteryMillivolts;
advdat.addr1 = getSensorAddrShort(sensorOffset);
advdat.temp1 = (int16_t)rawTemperatures[sensorOffset];
sensorOffset++;
if (sensorOffset >= sensorCount) sensorOffset = 0;
advdat.addr2 = getSensorAddrShort(sensorOffset);
advdat.temp2 = (int16_t)rawTemperatures[sensorOffset];
sensorOffset++;
if (sensorOffset >= sensorCount) sensorOffset = 0;
advdat.addr3 = getSensorAddrShort(sensorOffset);
advdat.temp3 = (int16_t)rawTemperatures[sensorOffset];
sensorOffset++;
if (sensorOffset >= sensorCount) sensorOffset = 0;
advdat.addr4 = getSensorAddrShort(sensorOffset);
advdat.temp4 = (int16_t)rawTemperatures[sensorOffset];
sensorOffset++;
if (sensorOffset >= sensorCount) sensorOffset = 0;
advdat.addr5 = getSensorAddrShort(sensorOffset);
advdat.temp5 = (int16_t)rawTemperatures[sensorOffset];
sensorOffset++;
if (sensorOffset >= sensorCount) sensorOffset = 0;
Serial.print("ManufData=");
for (uint8_t i = 0; i < sizeof(advdat); i++) Serial.print(((char*)&advdat)[i], HEX);
Serial.println();
bleCast.setManufacturerData((char*)&advdat, sizeof(advdat));
delay (1000);
}

@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
Loading…
Cancel
Save