I have a B4J project connected to a RF sender/receiver for controlling rf switches,read sensors etc and it works ok. My aim is now to fetch schedule times for devices and check if it's time to switch on/off. I find this code in a thread that might be a start but I'm unsure how to implement reading from database to the schedule code find from Erel's example :
Data is saved as in pic below (just testdata but structure is real) and I need to check start and stop time (to send to a server and to the devices for action)
Can anyone give a hint how to code the Dim t As Long = FindNextTime(Array As Double(5, 6.5, 20)) part ?
Is there a better way to accomplish this ?
I don't expect anyone to code for me but an example or advice howto is appreciated
Regards Håkan
B4X:
Dim t As Long = FindNextTime(Array As Double(5, 6.5, 20))
Log($"Next time is: $DateTime{t}"$)
Sub FindNextTime(Times As List) As Long
Times.Sort(True)
For Each st As Double In Times
If SetHours(st) > DateTime.Now Then
Return SetHours(st)
End If
Next
Return DateTime.Add(SetHours(Times.Get(0)), 0, 0, 1)
End Sub
Sub SetHours(st As Double) As Long
Dim hours As Int = Floor(st)
Dim minutes As Int = Round(60 * (st - hours))
Return DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), _
DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now), hours, minutes, 0)
End Sub
Data is saved as in pic below (just testdata but structure is real) and I need to check start and stop time (to send to a server and to the devices for action)
Can anyone give a hint how to code the Dim t As Long = FindNextTime(Array As Double(5, 6.5, 20)) part ?
Is there a better way to accomplish this ?
I don't expect anyone to code for me but an example or advice howto is appreciated
Regards Håkan