-->
Page 1 of 4

MASTER / SLAVE STAT V3 - Help Request

PostPosted: Wed Aug 17, 2016 8:22 am
by joeman2116
Hello all,
The code is in V3 A39.

I have started to work on a simple temperature control program which turns off / on a relay and sends a udp code to turn on /off a slave esp relay.
I had it working well in V2 but only until recently could I make it work on V3 .
The code is for a simple Master ESP. - which is working ok
Picture attached.

I am looking for some simple UDP based slave code

The master code is made up from pieces of code found thru out the forum and some stuff I added .
Thanks to coders like Electroguard and many others, there are some very elaborate examples of udp master slave controlling. Amazing network stuff!

However, I am looking for help to develop the simplest Slave code to have the master esp turn on or off an esp slave relay.
The overall aim is to provide a working example for a simple esp master / slave control V3 application .
Once it is working , it should help users, and provide a working example for a real world application..
A simple foundation to build on.

I believe the Master code udpwrite commands ok . The code controls a relay depending on temperature setting. It works..


1. In master esp - the setp code in the textbox setp , where the temperature is set. The space allocated for input is to long. I only wish to have around 6 digit spacing at best.
Does anyone have a solution to have it allocate less input space??

2. Esp slave coding - anyone have a simple solution?

MASTER CODE:

'ESPBASIC V32 A39 MASTER STAT B with slave control
'DB1820S Temp Sensor Data PIN IS D4
'Pin D2 for led or relay output inside
'Pin D5 for led or relay output outside

memclear
cls
let tf = 0
let curr = 0
let outc = 0 'for second temp sensor
setp = 22
settemp = 22
let stat = On
let statout = On
let setpout = 22

cssclass "button", "background-color: #99e6e6;"
cssclass "align-self: center;"

wprint "<head>"
wprint "<meta http-equiv='refresh'content='5;URL=/input?'>"
wprint "</head>"
wprint "<body bgcolor='#527a7a'>"

wprint "<table align='center' width='150' bgcolor='lightblue' border='6' cellpadding='5'>"
wprint "<th><b>MASTER Stat B</b></th>"
wprint "<th</th></table><br>"

wprint "<table align='center' width='180' bgcolor='lightblue' border='4' cellpadding='5'>"
wprint "<td>"
Button " 5 SECOND FAN TEST", [fon2]
wprint "</td>"
wprint "<th</th></table><br>"

wprint "<table align='center' width='185' bgcolor='lightblue' border='4' cellpadding='3'>"
wprint "<td>"
wprint "<b>A/C ASSIST Fan-<b/>"
wprint "<mark>"
wprint htmlvar(stat)
wprint "</mark>"
wprint "<br>"
wprint "</td>"
wprint "<th</th></table>"
wprint "<br>"
wprint "<table align='center' width='330' bgcolor='#00cca3' border='5' cellpadding='5'>"
wprint "<td>"
Button "Set A/C ASSIST",[setpt]
textbox setp
wprint "<th</th></table><br>"
wprint "<br>"
wprint "<table align='center' width='250' bgcolor='LIGHTBLUE' border='5' cellpadding='6'>"
wprint "<td>"
wprint "<b>A/C VENT TEMP= <b/>"
wprint htmlvar(curr)
wprint "(C)"
wprint "</td>"
wprint "<th</th></table><br>"

wprint "<table align='center' width='250' bgcolor='#00ace6' border='5' cellpadding='5'>"
wprint "<td>"
wprint "<b>A/C VENT TEMP= <b/>"
wprint htmlvar(tfout)
wprint "(F)"
wprint "</td>"
wprint "<th</th></table><br>"
'wprint "<br>"

wprint "<table align='center' width='60' bgcolor='lightblue' border='4' cellpadding='5'>"
wprint "<td>"
Button " exit", [quit]
wprint "</td>"
wprint "<th</th></table><br>"
timer 4000, [refresh]
wait

[on2] ' FIRST SENSOR DB1820S ---------
io(po,d5,1)
let stat = "ON"
udpwrite "192.168.1.213", 5001, "ON" 'SEND UDP COMMAND TO SLAVE 192.168.1.213 RELAY D5 "ON"
wait

[off2] ' FIRST SENSOR DB1820S ---------
io(po,d5,0)
let stat = "OFF"
udpwrite "192.168.1.213", 5001, "OFF"
wait

[fon2] ' TEST FAN ON ----------
io(po,d5,1)
let stat = "ON"
wait

[setpt]
wprint "<head>"
wprint "<meta http-equiv='refresh' content='5;URL=/input?'>"
wprint "</head>"
wait

[refresh]
curr = temp(1) 'curr ' read current temperature for device 1 db1820 SECOND SENSOR
outc = temp(0) ' outc ' read current temperature for device 0 db1820 FIRST SENSOR
tf = curr * 9 ' Fahrenheit CONVERSON
tf = tf / 5
tf = tf + 32
tfout = outc * 9
tfout = tfout / 5
tfout = tfout + 32
if curr < setp then goto [on2] else goto [off2] 'FAN ON IF CURRENT TEMP < GREATER THEN SETP
wait

[outcon] ' second db1820s sensor TURN RELAY D5 ON AND STAT ON
io(po,d5,1)
let statout = "ON"
wait

[outcoff] ' second db1820s sensor - TURN RELAY D5 OFF AND STAT OFF
io(po,d5,0)
let statout = "OFF"
wait

[quit]
timer 0
wprint "<a href='/'>Menu</a>"
end


Any help / assistance is appreciated
Thanks

Joe

Re: MASTER / SLAVE STAT V3 - Help Request

PostPosted: Wed Aug 17, 2016 8:59 am
by joeygbsn
Hey I have some code that I have been meaning to post using one master esp controlling one slave with a relay using udp. I have to work all day but i will post it later tonight.

Re: MASTER / SLAVE STAT V3 - Help Request

PostPosted: Wed Aug 17, 2016 9:37 am
by joeman2116
joeygbsn,

Excellent,

Looking forward to the code

Thanks

Joe

Re: MASTER / SLAVE STAT V3 - Help Request

PostPosted: Wed Aug 17, 2016 2:04 pm
by Oldbod
It's not udp but there is an extremely simple example posted by mmiscool doing this with multiple slave devices. Google mmiscool master slave. Running just the slave and saving the appropriate command as a favorite/bookmark, from my phone i can turn off/on an led on my nodemcu.(i use ddns to do that from outside my home network. )


I'm trying to stay away from reading other peoples examples of udp, especially for iot. Want t write from scratch without subconciously or conciously using others code ideas. (Which is exactly the opposite of what I'd suggest anybodyelse do, btw... only doing it because i'm new to espbasic and this is how i learn best. )