- Wed Oct 19, 2016 1:03 pm
#56785
A boast?! No, just a desire to thank everyone without whose help I could not have finished this. Also, this will need to be polished a lot more till I'd consider it boast-worthy
Anyway, here we are;
Code: Select alldim msg(6) 'Array for incoming password entries
relay = 0 'Relay on gpio.0
led = 3 'Led on gpio.3
switch = 2 'Door switch on gpio.2
dht.setup(11,1) 'model, pin1
timer 1000, [blipLED]
interrupt switch, [shutter]
button "Exit", [Out]
dlay = 1000 'Time the relay would be on
io(po,relay,0)
pwd = read.val("myfile")
udpbegin 5001
n = 1
[begin]
udpbranch [udpreceived]
wait
[udpreceived]
msg = udpread()
'UDPREPLY msg 'Acknowledge BACK to sender
'delay (50) 'for keypad beeps
if msg = "Clear" then
n = 1
UDPREPLY "Password?"
' print "Clear"
goto [begin]
endif
'UDPREPLY n
If n = 1 then UDPREPLY "*"
If n = 2 then UDPREPLY "* *"
If n = 3 then UDPREPLY "* * *"
If n = 4 then UDPREPLY "* * * *"
If n = 5 then UDPREPLY "* * * * *"
msg(n) = msg
'print n & " " & msg(n)
if n = 5 then
msg = msg(1)*10000+msg(2)*1000+msg(3)*100+msg(4)*10+msg(5)
if msg = pwd then
UDPREPLY "right"
io(po,relay,1)
delay (dlay)
io(po,relay,0)
UDPREPLY "ledoff"
else
UDPREPLY "wrong"
delay (dlay)
UDPREPLY "ledoff"
endif
n = 1
goto [begin]
endif
n = n+1
return
[blipLED] 'Flash the LED, and read the DHT sensor and upload to Thingspeak
io(po,led,1)
delay 1 ' (blink and you miss it!)
io(po,led,0)
t = dht.temp()
h = dht.hum()
c = c+1
d = d+1
' print t & degree
UDPREPLY " " & t
if c = 15 then
c = 0
thing = t & "&field2=" & h
sendts("XXDF54BWWFYXXXXX", "1",thing)
endif
goto [begin]
[shutter] 'Got here because door switch changed
if io(laststat,switch) = 1 then UDPREPLY "open" else UDPREPLY "closed"
goto [begin]
[Out] 'Enables interrupting program and access main menu
Exit
B4A is considered an excellent product to develop Android apps, and is considered to be fairly easy to use, specially if you're used to VB. I'm not, so I'm still learning.
I agree with your observation about their pricing strategy, however. I purchased their version that had a 2 year upgrades support, and I got a decent price thru' a referral. I can live without the updates after that, I guess.
On the ESP8266Basic side, just configure your ESP to work as a station and connect to your router in the settings page, define a fixed ip of 192.168.1.250 (also in the settings page; the B4A app is written to work with this ip) and no more credentials will have to be defined in the code.
The password file 'myfile.dat' is a simple file with a 5 digit number, and has to reside in the \data folder in the ESP spiff
The hardware is so simple, I guess a schematic isn't really required. Anybody needs any more information, just holler!