Not so much a feature but a lesson or some expamples of use.
Posted:
Thu Jan 26, 2017 8:52 pm
by forlotto
Cleaver ways to store more varibles using arrays or JSON would be excellent.
If you take a look at the relay clock example it is great but it has a limitation due to the amount of variables stored in memory.
Now looking at it.
I would think a weekly timer would indeed be possible with proper use or tools.
So you could check day of week then check the times for relay to do as needed just by going through an array or JSON file and loading one set of info into the timer at a time.
I see how to use arrays to some degree for comparisons etc and JSON has very little when it comes to examples .
It would be nice to easily address and from stored flash to be used as variables or even in a word list.
Re: Not so much a feature but a lesson or some expamples of
Posted:
Sat Jan 28, 2017 9:49 pm
by forlotto
Lets say you have 3 functions that you would like to carry out only if the status you enable them with some sort of start flag or register.
In most cases we would use:
routine1 = 1 or 0
routine2 = 1 or 0
routine3 = 1 or 0
below we would do if then statements to decide if we wanted to execute.
The problem with this is that we now have more registers in ram so in thinking about this you know there is a lot more code space then there is for ram. I believe there is a limitation on 70 registers in ram as well which is a lot of registers and most use cases would not touch this but something like a weekly timer it may in fact be possible to store more times or something like electrogaurds easynet it may also be possible to use less registers without completely disabling anything.
The beginning of your code you could use a number based on bits 0 or 1 to enable or disable the 3 function while it is not truely a bit based flag you could do it this way...
Let us just say for a moment that we have enable disable (0 or 1)
we have 3 routines we wish to enable or disable
Routine1 = 1 or 0 (On or Off) The first flag in the chain of 3 1xx
Routine2 = 1 or 0 (On or Off) The second flag of chain x1x
Routine3 = 1 or 0 (On or Off) The third flag of the chain xx1
startflag = 111 ' all 3 startup routines are on.
if startflag = 111 then goto [routine1]
if startflag = 110 then goto [routine1]
if startflag = 100 then goto [routine1]
if startflag = 101 then goto [routine1]
if startflag = 111 then goto [routine2]
if startflag = 110 then goto [routine2]
if startflag = 011 then goto [routine2]
if startflag = 010 then goto [routine2]
if startflag = 111 then goto [routine3]
if startflag = 011 then goto [routine3]
if startflag = 001 then goto [routine3]
if startflag = 101 then goto [routine3]
Now you may say well this is going to take up a lot of code space even though I am saving memory right?
So what could a person do to solve that and shorten code? Use string functions before checking if the flag is on. So you would search the string to find the value of each position then in your if statement compare the value of the position rather then comparing every single variation of what the flag could be like I did above.
In the event of a weekly timer I don't know how one could make this useful but it is possible it could be something like this...
Lets say we have 3 lists of 10 timers for each day
dayX for instance so day 1 is sunday day 7 is saturday, so X would be the lists to load
Timer = 33 would mean that we will be using list 3 for tuesday
now you could also have 1 long list of times and just supplement times in place using this in the program
if timer = 31 then time1 = 1:00
if timer = 32 then time1 = 2:30
if timer = 33 then time1 = 3:45
So now you have a method of switching between times just with a simple flag.
Again there is likely way to simplify things I am just thinking out loud here of possibles.
How could we access and ensure specific lists you ask simple access can be had to load specific sets of timers using this flag as it will load the specific times to that list dependant upon the flag and how it is set it will load those variables to the 10 timers to edit. Now during normal operation we would simply check through the lists using this same method Get the day of the week and the time if the day of the week is sunday we can set this variable at 31 after edits to variables for days of the week we would have to refresh the page I am guessing.
All of this is untested just trying to get input on some of the methods people are using or have used to skirt around some of the issues introduced by variable limitation. And obviously there has been another fella that created a relay clock a real world proof of why I thought investigation into these things may hold some weight.
We are dealing with IOT and what IOT enables is automation of something weather it is the automation of collecting, giving, doing, or waiting. These things can all easily be heavily dependent upon one thing and that is time and for most people weeks are fairly structured so we can depend on doing things most of the time at certain times. So the less interaction and the more automation the better set it forget it if you need to make a change make that possible as well.