Commit graph

50 commits

Author SHA1 Message Date
rbaron
82eabe778a Fixes BTHome encoding 2022-08-30 21:02:51 +02:00
rbaron
81f0af3cf2 Fixes humidity factor & removes illumminance
The reason for removing illuminance is to leave enough space for the
full name AD element "prst". There may be options for also sending the
illuminance (extended adv, scan response etc), with different power
consumption/overhead/complexity tradeoffs. For now let's keep it simple.
2022-08-29 21:17:17 +02:00
rbaron
ce4c496f4d Uses newly minted 0x14 sensor type for moisture
I also comment out the illiminance sensor, since we need the space for
encoding the device's name - "prst".
2022-08-28 22:47:21 +02:00
rbaron
6ea0bb8525 First stab at an alternative, BTHome compatible BLE protocol
This protococol (https://bthome.io/) allows for automatic sensor
detection in Home Assistant, as long as the device broadcasts its
sensors in the expected format.
2022-08-28 18:58:16 +02:00
rbaron
5cfd69479a Advertises while in deep sleep.
Related to the investigation in #48
2022-08-08 19:34:07 +02:00
rbaron
a7732f106b Introduces new config flag PRST_BLE_EXPERIMENTAL_LONG_RANGE
This flags makes use of the Coded PHY from Bluetooth 5. It should be
treated as an experimental feature and it's disabled by default.
Note that clients (such as ESPHomme) would also have to scan on the
Coded PHY to be able to find b-parasites operating in this mode.
Currently, no client does that. Thus the feature is disabled and marked
as experimental.
2022-08-03 23:14:06 +02:00
rbaron
99abae6f50 Adds comment about valid BLE protocol versions 2022-03-15 08:56:06 +01:00
rbaron
8fd4d7222a Implements BLE protocol v2
The only change from v1 is how the temperature is encoded. In v2, two
bytes at offset 4 and 5  represent a 16-bit signed int (in big-endian).
It contains the temperature in degrees Celsius *  100.

Fixes #29
2022-03-14 18:23:49 +01:00
rbaron
77f398757a Fixes MAC address in the BLE advertisement packet
The bug was introduced in https://github.com/rbaron/b-parasite/pull/26.
2022-02-12 18:38:57 +01:00
rbaron
1abff035cb Adds PRST_BLINK_LED config to save battery 2022-02-12 18:37:43 +01:00
rbaron
e16f61509c Add support for using the nRF52 preprogrammed random MAC address
Each nRF52 chip comes preprogrammed with a random static MAC address.
This is the default MAC address that is used if we don't specify one.

Fixes #25
2022-01-06 22:12:34 +01:00
rbaron
85643fe41e Cleans up debugging code 2021-10-09 09:33:50 +02:00
rbaron
79384cd6b2 Accidentally cleaned up too much 2021-10-09 09:33:23 +02:00
rbaron
ded36d1c3d Cleanup leftover tests 2021-10-09 09:33:23 +02:00
rbaron
bebf8c0a13 Adds code for reading the phototransistor values 2021-10-09 09:33:23 +02:00
Jan-Henrik Bruhn
44adefedb3 Fix overflow in very dark or noisy situations 2021-09-30 10:24:51 +02:00
rbaron
ef2bfcdadd Updates #ifdef's to #if in main.c 2021-09-22 22:43:49 +02:00
rbaron
e1f385adbd Fixes #if PRST_HAS_LDR check in ble.c 2021-09-22 22:39:19 +02:00
rbaron
d8aea1d4ef Introduces version-specific config & condition BLE lux encoding
In the BLE service data payload, one of the reserved bits is now used to
indicate whether or not the ambient lux value is encoded in the packet.
Bit 0 of the first byte is now the `has_lux` bit. If it is set, bytes
16-17 in the service data will contain the ambient lux. If `has_lux` is
not set, bytes 16-17 may not exist (for compatibility with older
firmwares) or may hold meaningless values.

This commit also introduces version-specific configuration in
prst_config.h. Photoresistor config, for example, is only meaninful for
version 1.1.x.
2021-09-22 22:39:11 +02:00
rbaron
a00559a98b Uses better LDR x lux model 2021-09-22 22:38:30 +02:00
rbaron
6f98aa34b1 Calls nrf_gpio_cfg_output(PRST_PHOTO_V) 2021-09-22 22:38:30 +02:00
rbaron
d2daefaf46 Updates ambient brightness estimation code
Also renames the `lux` field from `photo_read_t` to the more generic `brightness`.
2021-09-22 22:38:30 +02:00
rbaron
e32803d44d Improvements to photo resistor-based lux estimation
- Code now compiles
- Estimation of the photo resistor resistance works
- Lux estimation from the photo resistor resistance needs more work and calibration
- Lux is now encoded in the BLE advertisement payload
2021-09-22 22:38:30 +02:00
chentadot
dcd0fc4ae1 Calculate photoresistor and some other fixes (#3)
prst_adc_photo_read() now calculates the photo resistor and return it as the lux level.
Added debug logging and fixed some syntax errors.
2021-09-22 22:38:30 +02:00
chentadot
c9b05859e4 First draft for Photoresistor
the code now should setup and use the photoresistor and read it's value by the adc.
the returned value is 0 just as a place holder until the correct values are measured.
2021-09-22 22:38:30 +02:00
rbaron
795fc46849 Updates docs for data encoding in the BLE advertisement packet 2021-05-02 20:20:39 +02:00
rbaron
837a30ba03 Adds the whole MAC address in the advertisement packet 2021-05-02 12:14:52 +02:00
rbaron
19f9a68b3b Bump RTT logger buffer from 512 to 1024
It was swalloing some of the messages when debugging.
2021-05-02 11:32:45 +02:00
rbaron
c110810334 Attaches two least significant MAC address bytes to advertisement packet 2021-04-26 20:41:41 +02:00
rbaron
f0b3294f0f Fixes possible overflow in the soil moisture BLE encoding 2021-04-26 20:40:54 +02:00
rbaron
e54449bf84 Adds make lint and make lint-fix 2021-04-10 18:19:37 +02:00
rbaron
9057d67c0c Clean up unused code and done TODO 2021-04-10 18:05:44 +02:00
rbaron
463fdb5ef4 Corrects the raw ADC soil mesasure given the current input voltage 2021-03-31 20:12:47 +02:00
rbaron
d215d5f4a7 Sets transmitting power to +8dB 2021-03-31 18:37:50 +02:00
rbaron
3c7180fefa Adds run_counter to ble advertising packet 2021-03-28 10:44:33 +02:00
rbaron
37fd1173ec Sets MAC address to a random static value 2021-03-26 17:18:38 +01:00
rbaron
6ec48b7188 Puts soil moisture reading into the BLE advertisement packet 2021-03-26 16:30:09 +01:00
rbaron
30162f4628 Cleans up logging 2021-03-26 13:45:28 +01:00
rbaron
2aa0ffc27b Some debugging info 2021-03-26 11:43:55 +01:00
rbaron
c2e3723eb0 Adds temp and humidity values to the BLE advertisement packet 2021-03-26 10:49:28 +01:00
rbaron
81b33fbd8c Handles SHT3C sensor
...And this is the first time I'm flashing the firmware into a real
b-parasite board!
2021-03-26 10:29:54 +01:00
rbaron
25772def7e ADC works for measuring the battery voltage 2021-03-17 19:08:17 +01:00
rbaron
b521e3f0f6 A hacky fix for PWM + TWI 2021-03-15 22:40:09 +01:00
rbaron
02df5f4595 Initial shtc3 TWI/I2C implementation
Weirdly, it only works ~1/5 of the time.
2021-03-14 16:55:24 +01:00
rbaron
fb07a1244c PWM start/stop in RTC callback.
I initially tried calling prst_pwm_init() in main(), and just using start/stop in
the callback, but that led to a weird behavior in the PWM output. It was set to
high after the end of the callback.

Callnig uninit/re-calling init() inside the RTC callback fixed, but more investigation
is required.
2021-03-14 15:03:33 +01:00
rbaron
05dcb9de84 Hard coded PWM with 500kHz frequency works 2021-03-14 14:30:32 +01:00
rbaron
cf2725e028 Adds dynamic data to ble advertisement
I am very tempted to drop all the ble advertisement abstraction and deal directly with the
31-byte raw payload.
2021-03-14 11:50:26 +01:00
rbaron
20243a26a2 Extracted BLE to src/prst/ble.{c,h} 2021-03-14 11:06:45 +01:00
rbaron
a5c932def2 Extracts RTC stuff to src/rtc.{c,h} 2021-03-13 16:49:55 +01:00
rbaron
7ef278fe40 Initial b_parasite code - a fork from playground 2021-03-13 14:56:37 +01:00