Sub CloudSyncDevice As Int
'Record Sync Time
Dim LastSynced As Long
LastSynced = Subs.GetParamIntLong("LastSyncDateDevice")
Dim DeviceToSyncC As Cursor
DeviceToSyncC = Main.WiE3SQL.ExecQuery("SELECT DeviceSN, Drawing, PosTop, PosLeft, DeviceType, ApplicationID, ConfigByte, ConfigOptions, MinDaylightLevel FROM Device WHERE DeviceSN > 1000 AND LastEdit > " & LastSynced)
If DeviceToSyncC.RowCount = 0 Then
DeviceToSyncC.Close
Return 0
Else
'Create a List of Device Maps
Dim DeviceList As List
DeviceList.Initialize
For i = 0 To DeviceToSyncC.RowCount - 1
DeviceToSyncC.Position = i
Dim DeviceRecord As Map
DeviceRecord.Initialize
DeviceRecord.Put("DeviceSN",DeviceToSyncC.GetInt("DeviceSN"))
DeviceRecord.Put("Drawing",DeviceToSyncC.GetString("Drawing"))
DeviceRecord.Put("PosTop",DeviceToSyncC.GetInt("PosTop"))
DeviceRecord.Put("PosLeft",DeviceToSyncC.GetInt("PosLeft"))
DeviceRecord.Put("DeviceType",DeviceToSyncC.GetInt("DeviceType"))
DeviceRecord.Put("DeviceTypeID",DeviceToSyncC.GetInt("ApplicationID"))
DeviceRecord.Put("ConfigByte",DeviceToSyncC.GetInt("ConfigByte"))
DeviceRecord.Put("ConfigOptions",DeviceToSyncC.GetInt("ConfigOptions"))
DeviceRecord.Put("MinDaylightLevel",DeviceToSyncC.GetInt("MinDaylightLevel"))
DeviceList.Add(DeviceRecord)
Next
'Create the JSON Object
Dim DeviceJSON As JSONGenerator
DeviceJSON.Initialize2(DeviceList)
If Main.CloudConnected AND Main.CloudEnabled Then
ToastMessageShow("JSON for " & DeviceToSyncC.RowCount & " Devices Sent to " & "DeviceUpload.aspx",False)
Dim myTimeStored As Long
myTimeStored = DateTime.Now
'Create String to Post
Dim myPostString As String
myPostString = "PostCode=" & Main.ActivePostcode & _
"&UserID=1" & _
"&Collator=" & Main.AndroidID & _
"&TimeStored=" & myTimeStored & _
"&DeviceJSON=" & DeviceJSON.ToString
'Initialise HTTP Job
Dim Job1 As HttpJob
Job1.Initialize("JobUploadDeviceJSON",Me)
'Default timeout is 30 seconds. Use line below to change it
'Job1.GetRequest.Timeout = 30000
Log(myPostString)
'Post the String inc JSON
Job1.PostString(Main.HTTPServer & "DeviceUpload.aspx",myPostString)
End If
'Get Sync Count before closing cursor
Dim myDevicesSynced As Int
myDevicesSynced = DeviceToSyncC.RowCount
'Close Cursor and Return
DeviceToSyncC.Close
Return myDevicesSynced
End If
End Sub