#F formatting seems not to work

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
_Cyber_
Normal user
Posts: 113
Joined: 20 Oct 2019, 09:46

#F formatting seems not to work

#1 Post by _Cyber_ » 08 Jun 2021, 09:32

hi,

hardware is a wemos D1 mini with a relay shield where the relay switches a babyphone behind. release used is ESP_Easy_mega_20201102_normal_ESP8266_4M1M

I am using the webgui.esp and calculate there the last switch, and out of it the sleeping time. :D

now there seems to be an issue with the #F formatting (see line Let,5,[INT#4#F] ): it does not round down, it rounds above .5 up. this leads to negative minutes. :shock:
Devices.png
Devices.png (13.75 KiB) Viewed 3789 times
rules:

Code: Select all

on System#Boot do
 GPIO,5,0
 Monitor,GPIO,5
endon

on Clock#Time=All,**:** do
 TaskValueSet,2,1,%syshour_0%
 TaskValueSet,2,2,%sysmin_0%
 event,calcsleeptime
endon

on GPIO#5 do
 TaskValueSet,2,3,%syshour_0%
 TaskValueSet,2,4,%sysmin_0%
 event,calcsleeptime
endon

on calcsleeptime do
 if [Babyphone#State] = 1
  Let,1,(([Time#Hour]*60)+[Time#Min])
  Let,2,(([Time#HourSw]*60)+[Time#MinSw])
  Let,3,([INT#1]-[INT#2])
  Let,4,([INT#3]/60)
  Let,5,[INT#4#F]
  Let,6,(([VAR#4]-[INT#5])*60)
 else
  Let,5,0
  Let,6,0
 endif
endon
logoutput:

Code: Select all

129687402: EVENT: calcsleeptime
129687428: ACT : Let,1,((8*60)+31)
129687434: ACT : Let,2,((7*60)+59)
129687438: ACT : Let,3,(511-479)
129687442: ACT : Let,4,(32/60)
129687446: ACT : Let,5,1
129687449: ACT : Let,6,((0.53-1)*60)
expected: Let,5,0

webgui.esp:

Code: Select all

<!DOCTYPE html>
<html><head>
<meta http-equiv="refresh" content="30; URL=http://192.168.10.127/webgui.esp">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.circle {width:100px; height:60px;border-radius:50%;display: inline-flex;cursor:pointer;color:white;font-size:90%;font-weight:bold;align-items:center;justify-content:center;}
a {text-decoration: none;color:white;}
table {vertical-align:middle;font-size:220%;font-weight:bold;}
.c0 {background-color:red;}
.c1 {background-color:green;}
p { cursor:text; }
.no-link {color:black;text-decoration:underline;}
</style><title>Babyphone</title></head><body>

<br><br><table align="center">
<tr><td>Babyphone Status:</td><td>&nbsp;</td>
<td align="center"><div class="circle c[Babyphone#State]"><a class="circle link" href="webgui.esp?cmd=GPIOtoggle,5">[Babyphone#State]</a></div></td></tr>
<tr><td>zuletzt geschaltet:</td><td>&nbsp;</td><td align="center">[Time#HourSw#D2]:[Time#MinSw#D2]</td></tr>
<tr><td align="center">zuletzt aktualisiert:</td><td>&nbsp;</td><td align="center">[Time#Hour#D2]:[Time#Min#D2]</td></tr>
<tr><td align="center">schl&auml;ft seit:</td><td>&nbsp;</td><td align="center">[INT#5]:[INT#6#D2]</td></tr>
<tr><td colspan="3" align="center"><a class="no-link" href="webgui.esp">Aktualisieren</a></td></tr>
</table>
I tried to update to ESP_Easy_mega_20210114_normal_ESP8266_4M1M.bin and encountered the following issues:
* Dummdevice not filled any more - found out that it does not like the "Time" as Name for the Dummydevice
* %syshour_0% not working any more (leads always to 0)
* requesting the webgui.esp leads to reboots (Software-watchdog as reason - in log I can see it tries to do bitwise stuff most probably caused by the brackets in the webgui.esp ? )

:-(

Any ideas how to get rid of the failing #F formatting to calculate the time correctly? :-)

Thanks!

BR
Alois

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: #F formatting seems not to work

#2 Post by Ath » 08 Jun 2021, 09:45

_Cyber_ wrote: 08 Jun 2021, 09:32

Code: Select all

on calcsleeptime do
 if [Babyphone#State] = 1
  Let,1,(([Time#Hour]*60)+[Time#Min])
  Let,2,(([Time#HourSw]*60)+[Time#MinSw])
  Let,3,([INT#1]-[INT#2])
  Let,4,([INT#3]/60)
  Let,5,[INT#4#F]
  Let,6,(([VAR#4]-[INT#5])*60)
 else
  Let,5,0
  Let,6,0
 endif
endon
I think the [INT#4] is already rounding in the wrong direction, so to solve that you should probably use Let,5,[VAR#4#F] instead, so there is actually something to 'floor'.
/Ton (PayPal.me)

_Cyber_
Normal user
Posts: 113
Joined: 20 Oct 2019, 09:46

Re: #F formatting seems not to work

#3 Post by _Cyber_ » 08 Jun 2021, 09:55

yes, you are right - thanks. :-)

Code: Select all

316416: EVENT: calcsleeptime
316442: ACT : Let,1,((9*60)+54)
316449: ACT : Let,2,((9*60)+20)
316452: ACT : Let,3,(594-560)
316456: ACT : Let,4,(34/60)
316460: ACT : Let,5,0
316463: ACT : Let,6,((0.57-0)*60)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: #F formatting seems not to work

#4 Post by TD-er » 08 Jun 2021, 23:53

Ath wrote: 08 Jun 2021, 09:45
_Cyber_ wrote: 08 Jun 2021, 09:32

Code: Select all

on calcsleeptime do
 if [Babyphone#State] = 1
  Let,1,(([Time#Hour]*60)+[Time#Min])
  Let,2,(([Time#HourSw]*60)+[Time#MinSw])
  Let,3,([INT#1]-[INT#2])
  Let,4,([INT#3]/60)
  Let,5,[INT#4#F]
  Let,6,(([VAR#4]-[INT#5])*60)
 else
  Let,5,0
  Let,6,0
 endif
endon
I think the [INT#4] is already rounding in the wrong direction, so to solve that you should probably use Let,5,[VAR#4#F] instead, so there is actually something to 'floor'.
The [int#] notation is just a cast to int as would be done in C++.
The [int#4#F] does not really make sense as a floor operation is something that would make sense on floating point values, not int values.
In pseudo code, the #F is something like static_cast<int>(floatingpointvalue + 0.5)
Casting to int is just throwing away the fractional part.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 26 guests