DO NOT TAMPER WITH THE ORIGINAL GAUGE or TANK, OR LOSS OF LIFE MAY OCCUR!
The transmitter:
Code: [Local Link Removed for Guests]
'gauge sensor v6
PIN.MODE 23, INPUT, PULLUP 'for boot up switch from io 23 to ground avoids sleep command
pause 100
if pin(23) = 0 goto en 'boot up and wait
msg$ = "0"
MAC1$ = "EE:FA:xx:6E:18:xx" ' AP mac of the receiver
WIFI.CONNECT "Propane_Rx", "whatever" 'receiver name and password
pause 300
I2C.SETUP 21, 22 'QMC5883 compass
address = &H0D ' Address of the device QMC5883
ioBuff.dim(0, 6) ' To save the measurement result
i2c.writeRegByte address, &H0A, &B10000000 ' SOFT_RST
pause 100
i2c.writeRegByte address, &H0B, 1 ' start
pause 100
i2c.writeRegByte address, &H09, &B00010001 ' 512 samples, 8 gauss, 10Hz, continuous
pause 100
espnow.begin
espnow.add_peer MAC1$
onEspNowError retry ' set the place where jump in case of TX error
pause 100
i2c.read_ioBuff(0), address, &H00, 6
x = ioBuff.read(0, 0) OR (ioBuff.read(0, 1) << 8)
if x > 32768 then x = x - 65536
y = ioBuff.read(0, 2) OR (ioBuff.read(0, 3) << 8)
if y > 32768 then y = y - 65536
z = ioBuff.read(0, 4) OR (ioBuff.read(0, 5) << 8)
if z > 32768 then z = z - 65536
yaw = atan2(y, x) * 180 / PI
if yaw < 0 then yaw = 360 + yaw
pause 1000
yw = cint(yaw)
print yw
msg$ = str$(yw)
EspNow.Write(msg$, MAC1$)
pause 1000
sleep 86400 'set this for one week if needed
retry:
EspNow.Write(msg$, MAC1$)
print "resend"
return
en:
print "waiting for you"
wait
end
Code: [Local Link Removed for Guests]
'propane_receiver v6 mac$(1) AP(EE:xx:BC:6E:xx:xx)
cls
wifi.connect "yourwifi", "password"
pause 1000
WIFI.APMODE "Propane_Rx", "password", 10
percent$ = "0"
percent = 0
msg$ = "360"
msg = 77
file$ = ""
line$ = ""
a$ = ""
pin.mode 14, input
interrupt 14, view ' turn on display with push button
I2C.SETUP 4, 5 ' set I2C port on pins (4 or D2 on SDA) and (5 or D1 on SCL)
OLED.INIT 1 ' init the OLED upside-down
OLED.CLS ' clear the screen
OLED.COLOR 1
OLED.FONT 3
OLED.PRINT 15,2, "Hello"
pause 2000
oled.cls
espnow.begin
pause 500
onEspNowMsg incoming ' set the place where jump in case of message reception
autorefresh 1000
print "start"
wait
incoming:
print "received"
Msg$ = EspNow.READ$
'Msg$ = "50" 'for testing
Msg = val(Msg$)
print Msg
percent = CONVERT.MAP(Msg, 230, 50, 10, 70) '(number, fromLow, fromHigh, toLow, toHigh) deg. to percentage [ you may need to calibrate this
if percent < 11 goto warning
percent$ = date$ +" "+ str$(cint(percent)) +"%"+" "+"Full"+" "
file$ = "/data.txt" ' you must create this file
line$ = chr$(13) '
file.append file$, line$ ' required to add data to top of column
line$ = percent$ + chr$(13) '
a$ = line$ + file.read$(file$) '
file.save file$, a$ ' create new data file for display
file$ = ""
reboot
return
warning:
EMAIL.SETUP "smtp.gmail.com", 465, "whatisyour@gmail.com", "ynwnbpdeikvyfvvv",1
print EMAIL ("tanklevel@gmail.com", "7892061010@msg.telus.com", "Propane Aert", "Propane below 10%")
OLED.CLS ' clear the screen
OLED.FONT 2
OLED.PRINT 15,2, "PROPANE LOW"
sleep 120
return
view:
if pin(14) = 1 then return
OLED.CLS ' clear the screen
OLED.FONT 3
OLED.PRINT 15,2, file.read$("/data.txt",9,8) 'print percentage from file
OLED.FONT 2
OLED.PRINT 25,35, file.read$("/data.txt",0,8) 'print date from file
pause 6000
OLED.CLS ' clear the screen
Return
end
You also need to create a /data.txt file with this entry "26/12/23 63% Full". This file records the transmitted data for reference and can be accessed
through the editor.
Thanks to all who helped with the code!