Hi All
Have done a lot of work integrating the smart bulb in the same code.
Works very well, I can now turn my lounge room into a disco (well almost)
This is using a USA version, so probably have to add functionality once I get home.
The Smart Bulb has a lot more info available, and the json strings were becoming a real problem,
so I rewrote that in the only way I know how.(Simple Step by Step)
The commands to read the devices stay as json strings, but after that I call StripRxData which operates on .RxData
Code: Select all
Sub StripRxData
'===================================================================
'Called from last statement in DataTxRx.
'===================================================================
ErrControl.Routine = "PrintRxData;"
If Control.PrintFlag = 3 Then Print ErrControl.Routine
Dim as Integer Cnt,Cnt2,LFcount,Colon
Dim as String Srch,Srch2,Srch3,Srch4
Dim Char as String * 1
'-----------------------------------------------------------
'First strip all the undesirables and replace commas with LF
'-----------------------------------------------------------
Srch = NetDevice(Control.Device).RxData
For Cnt = 1 to Len(Srch)
Char = Mid(Srch,Cnt,1)
If (Char <> "{") And (Char <> "}") And (Char <> Chr(34)) And (Char <> Chr(91)) And (Char <> Chr(93)) And (Char <> Chr(9)) Then
If Char = "," Then Char = Chr(&H0A)
Srch2 = Srch2 + Char
EndIf
Next
'-----------------------------------------------------------
'Next put each string (upto LF) into 1 of n Reply(n)
'-----------------------------------------------------------
Cnt = 0
While Cnt < Len(Srch2)
Cnt += 1
Char = Mid(Srch2,Cnt,1) 'get next chr from string
If (Char = Chr(&H0A)) Then 'if it is a LF
LFcount += 1 'inc counter for Reply(n)
Srch3 = Left(Srch2,Cnt) 'put all chr's to the left into Srch3
Reply(LFcount) = Srch3 'if it wasn't a sysinfo command, just save it.
Srch2 = Right(Srch2,Len(Srch2) - Cnt) 'shorten the string for next round.
Cnt = 0 'set cnt to beginning of that shortened string.
EndIf
Wend
'-----------------------------------------------------------
'But the last one fell through, so add it.
'-----------------------------------------------------------
LFcount += 1
Reply(LFcount) = Srch2
End Sub
Then I call Getvalue with a Srch String from within SavePlugSpec or SaveBulbSpec.(example below)
Code: Select all
With PlugStat(Control.Device)
.SwVer = GetValue("system:get_sysinfo:sw_ver:")
.HwVer = GetValue("hw_ver:")
.Types = GetValue("type:")
.Model = GetValue("model:")
.MAC = GetValue("mac:")
.DevName = GetValue("dev_name:")
And finally the GetValue Function.
Code: Select all
Function GetValue(byref Srch as String) as string
Dim as short Xq,Cnt
Dim as String Repl
For Xq = 1 to 70
If Instr(Reply(Xq),Srch) > 0 Then 'if Srch was found inside Reply(Xq)
Cnt = InStr(Reply(Xq),Srch) 'record the location
Repl = Mid(Reply(Xq),Cnt + Len(Srch),Len(Reply(Xq))-Cnt) 'then save starting @ Cnt + len of Srch, till the end of String
Return Repl 'Return that as the result.
EndIf
Next Xq
Return "Fail"
End Function
The GUI code is all written and functional except for the implementation of schedules.
@badidea, I have been trying to get this info to you so as to avoid you spending to much time on the getJsonValue Function, but
the site being down so frequently made that difficult.
Regards