This is a work in progress, so don't take things too litterally, but it does work.
All the ADC stuff is prevent the battery from getting too low and causing damage.
Code: [Local Link Removed for Guests]
'********************************************************************************
'* *
'* Remote BME280 Transmitter *
'* Config MUST be set to Fast Boot *
'* Sept 2021 *
'* Using ESP-12f *
'* V1.1.0 27/09/2022 Changed I2C from 2,0 to 4,5 *
'* Added IO(12) as linkable configuration. *
'* Moved BME280 Vcc from 3v3 to IO(14) *
'* Added select/case/sleep based on voltage. *
'* Added 2nd sensor 05/10/2022 *
'* Added Vstart for new battery detection 26/05/2023 *
'* *
'********************************************************************************
Started = millis
Vstart=ADC/242 '240 is nominal.
'OPTION.CPUFREQ 80 'saves a little power but takes 20mS longer.
WIFI.APMODE "Give the AP a name", "and a password", 11 'Required for ESPNOW on channel 11
pin.mode 14,output'BME280 Vcc
pin(14) = 1 'Turn on the BME280
pin.mode 2,output 'Onboard LED
pin(2) = 0 'Turn on onboard LED
pin.mode 12,input 'Linkable IO
ESP_Tx$="":N=0:ESP_Rx$=""
i2c.setup 4,5
word.setparam ESP_Tx$,"Name","Sens2"
Gosub GetValues
'Do while ( wifi.channel <> 11)
'Pause 10
'Loop
ESPNOW.BEGIN
ESPNOW.add_peer("2c:f4:32:a5:5f:0e")'sonoff 1
'##########################################################################
Do
gosub SendData
If (pin(12) = 0) AND (V <= Vstart) then
Sleep S
else
Vstart = V
Pause 2000
Gosub GetValues
Pin(2) = 1'LED Off
pause 1200
Pin(2) = 0'LED On
EndIf
Loop
'###########################################################################
SendData:
ms = millis - started
word.setparam ESP_Tx$,"ms",STR$(ms,"%2.2f")
ESPNOW.WRITE(ESP_Tx$)
if espnow.error$ <> "" then
pause 50
ESPNOW.WRITE(ESP_Tx$) 'Retry
endif
Return
'###########################################################################
GetValues:
V=ADC/242
Select Case V 'Adjust volages to suit specific battery.
Case 0 to 3.50
S = 3600 '1 Hour
Case 3.50 to 3.60
S = 2400 '20 minutes
Case 3.60 to 3.65
S = 1200 '10 minutes
Case 3.65 to 3.70
S = 900 '5 minutes
Case 3.70 to 3.75
S = 600 '3 minutes
Case 3.75 to 3.80
S = 300 '2 minutes
Case 3.80 to 3.85
S = 240 '1 minute
Case 3.85 to 3.90
S = 180 '30 seconds
Case 3.90 to 4.00
S = 60 '20 seconds
Case 4.00 to 4.18
S = 30 '10 seconds
Case 4.18 to 4.2
S = 10 '5 seconds
Case > 4.2
S = 5
Case else
S = 15
End Select
Ret=BME280.setup(&h76)
T=bme280.temp
H=bme280.hum
H=(H*1.0275)+0.03 'Humidity calibration
P=bme280.qfe
word.setparam ESP_Tx$,"T1",STR$(T,"%2.2f")
word.setparam ESP_Tx$,"H1",STR$(H,"%2.2f")
word.setparam ESP_Tx$,"P1",STR$(P,"%2.2f")
Ret=BME280.setup(&h77)
T=bme280.temp
H=bme280.hum
H=(H*1.0055)+1.45 'Humidity calibration
P=bme280.qfe
word.setparam ESP_Tx$,"T2",STR$(T,"%2.2f")
word.setparam ESP_Tx$,"H2",STR$(H,"%2.2f")
word.setparam ESP_Tx$,"P2",STR$(P,"%2.2f")
word.setparam ESP_Tx$,"V",STR$(V,"%2.2f")
word.setparam ESP_Tx$,"S",STR$(S,"%2.2f")
Return
'###########################################################################
P.S. Don't forget to link GPIO 16 to RST.
Not easy on a ESP-01
You do not have the required permissions to view the files attached to this post.