Last updeted sensor's time

Moderator: Telldus

Post Reply
philipp
Posts: 6
Joined: Thu Jan 18, 2018 11:08 am

Last updeted sensor's time

Post by philipp » Thu Jan 18, 2018 11:08 am

Hei!
Could anybody can help to make some VBScript to get and convert the regbinary value "lastUpdated" of sensors to some clear for human format of date? Had tried any functions but didn't get result. :(
Please... :wave:

ReneOrtmann
Posts: 85
Joined: Thu Jan 18, 2018 11:08 am
Location: Strömstad, Sverige
Contact:

Re: Last updeted sensor's time

Post by ReneOrtmann » Thu Jan 18, 2018 11:08 am

You have to convert the datetime from Unix.
Try something like this:
CDate(unixDateTime/(86400 + 25569))
* HomeStick - A free Windows App for your Tellstick.NET device *
http://www.reor-software.eu/HomeStick/

philipp
Posts: 6
Joined: Thu Jan 18, 2018 11:08 am

Re: Last updeted sensor's time

Post by philipp » Thu Jan 18, 2018 11:08 am

Thank You for answer. But something didn't understand cause of can't receive real result by any ways. This is VBScript code am using. What is wrong?

Code: Select all

x = ReadHexDataRegValues("HKCU", "Software\Telldus\TelldusCenter\com.telldus.sensors\sensors\2\values\values\0\values\lastUpdated")
Debug.Write x

const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
 strComputer & "\root\default:StdRegProv") 
 
oReg.GetBinaryValue HKEY_CURRENT_USER, "Software\Telldus\TelldusCenter\com.telldus.sensors\sensors\2\values\values\0\values", "lastUpdated", strRetVal  
WScript.Echo vbcrlf  & RegBinaryToString(strRetVal)
WScript.Echo vbcrlf  & CDate(x/(86400 + 25569))
  
 
function RegBinaryToString(arrValue)  
 output=""
 strInfo=""  
  for i=0 to ubound(arrValue)  
   if arrValue(i)<>0 then strInfo=strInfo & chr(arrValue(i))  
  next
   RegBinaryToString=strInfo
end function

function ReadHexDataRegValues (RegRoot, RegValue)
Dim WshShell
Set WshShell = WScript.CreateObject("Wscript.Shell")

    CurrentValue = WSHShell.RegRead(RegRoot & "\" & RegValue)
    For I = LBound(CurrentValue) To UBound(CurrentValue)
        tmphex = CStr(Hex(CurrentValue(I)))
        if Len(tmphex)=1 then tmphex = "0" & tmphex
        hexstr = tmphex & hexstr
    Next
    
'    While Len(hexstr) <16
'        hexstr = "0" & hexstr
'    Wend
    ReadHexDataRegValues = HexDateToDate(hexstr)
End Function

Function HexDateToDate(hDate)
    highPart = CDbl("&h" & Left(hDate,8))
    lowPart = CDbl("&h" & Right(hDate,8))
    intInstalledOn = highPart * (2^32) + lowPart 
    intInstalledOn = intInstalledOn / (60 * 10000000)
    intInstalledOn = intInstalledOn / 1440
    HexDateToDate = intInstalledOn + #1/1/1601#
End Function

ReneOrtmann
Posts: 85
Joined: Thu Jan 18, 2018 11:08 am
Location: Strömstad, Sverige
Contact:

Re: Last updeted sensor's time

Post by ReneOrtmann » Thu Jan 18, 2018 11:08 am

What is the result you get?
I am not using VBScript and can not help you with any code.

But to show the converted value, you need to show the right format. I made som Goolge searches and find this page:
https://www.mikesdotnetting.com/article ... n-vbscript
* HomeStick - A free Windows App for your Tellstick.NET device *
http://www.reor-software.eu/HomeStick/

philipp
Posts: 6
Joined: Thu Jan 18, 2018 11:08 am

Re: Last updeted sensor's time

Post by philipp » Thu Jan 18, 2018 11:08 am

Thanks for answer. Don't understand the algorithm of converting self.
Could You show me a principle on this example:

The real date is 04.11.2017 18:28:50
Reg_bynary value is
40 0 56 0 61 0 72 0 69 0 61 0 6E 0 74 0 28 0 0 0 0 0 0 0 10 0 0 0 25 0 81 0 CE 0 3 0 F7 0 E6 0 50 0 0 0 29 0
or in decimal
64 0 86 0 97 0 114 0 105 0 97 0 110 0 116 0 40 0 0 0 0 0 0 0 16 0 0 0 37 0 129 0 206 0 3 0 247 0 230 0 80 0 0 0 41 0

How, what way, could I received a real result?
CDate function didn't work.
The table from http://microsoft.public.vc.language.nar ... -time-code don't describe it too.

The Google sends me already to devil.

:banghead:

Post Reply