Hello,
There is a log function that is not yet described in our documentation. In an upcoming release, we will be releasing this information within the new documentation for mcStudio and the mcDemo205. That said, we do have some code that you can modify for your use to log information into the flash of the device. The below code is for an example using our partner, Losant, so you may want to modify this for your needs. The code is meant to log GPS coordinates and temperature and then, when in range of a gateway, you would press SW1 and the information would then be transferred to the Losant cloud to populate onto a map onto a dashboard.
here is the code and there are also some additional notes below:
Class gpsTracker
Shared Locations As ListOfObject
Const GPS_TIMEOUT_uS As Integer = 120000000 '120s
'Const GPS_TIMEOUT_uS As Integer = 1000000 '1s
Const GPS_MIN_SATS As Integer = 3 '3 sattelites minimum
Const LosantDeviceID As String = "YOUR LOSANT DEVICE ID"
Const LosantTopic As String = "losant/" + LosantDeviceID + "/state"
Shared Event Boot()
Locations = New ListOfObject()
End Event
Shared Event StartLocationAcquisition() RaiseEvent Every 7 Minutes
Led2 = True
Thread.Sleep(100000)
Led2 = False
Device.StartGPS(GPS_TIMEOUT_uS, GPS_MIN_SATS)
End Event
Shared Event LocationDelivery()
Dim lat As Float = Device.GetLatitude()
Dim lon As Float = Device.GetLongitude()
Dim tmp As Float = TempSensor.GetTemp()
If lat.IsNaN() Or lon.IsNaN() Then
Else
Dim entry As ListOfByte = New ListOfByte()
entry.AddFloat(tmp)
entry.AddFloat(lat)
entry.AddFloat(lon)
Log.Write(0, entry)
End If
End Event
Shared Event SW1FallingEdge()
Led3 = True
Thread.Sleep(100000)
Led3 = False
Dim count As Integer = 0
Dim offset As Integer = 0
Dim lo As ListOfObject
lo = Log.Read(offset)
While lo <> Nothing
Dim o As Object
o = lo(0)
offset = o.Cast(Integer)
o = lo(1)
Dim dtm As DateTime = o.Cast(DateTime)
o = lo(2)
Dim type As Integer = o.Cast(Integer)
o = lo(3)
Dim entry As ListOfByte = o.Cast(ListOfByte)
Dim tmp As Float = entry.ExtractFloat(0)
Dim lat As Float = entry.ExtractFloat(4)
Dim lon As Float = entry.ExtractFloat(8)
Dim jDate As Json = New Json()
jDate.Add("$date", dtm)
Dim jData As Json = New Json()
jData.Add("temperature", tmp)
Dim locStr As String = lat.ToString() + "," + lon.ToString()
jData.Add("location", locStr)
Dim jPayload As Json = New Json()
jPayload.Add("time", jDate)
jPayload.Add("data", jData)
While Not Lplan.Publish2(LosantTopic, jPayload.ToListOfByte)
Thread.Sleep(10000)
End While
count += 1
If count = 30 Then
Thread.Sleep(30000000)
count = 0
End If
lo = Log.Read(offset)
End While
End Event
End Class
Additional notes -
1) you'll also want to add the temperature sensor library and the below GPS library if you want to use the code above with Losant:
Class GpsLocation
Public Latitude As Float
Public Longitude As Float
Public Timestamp As DateTime
Public Sub New(lat As Float, lon As Float, dtm As DateTime)
Latitude = lat
Longitude = lon
Timestamp = dtm
End Sub
End Class
2) I believe the flash will keep storing until you have enough data to start overwriting. If you do want to clear the flash, you can include or run the below function on a new script
Log.Erase()
3) if you are interested in working with the above code for a test, keep in mind that the device needs to be powered and in-range of an mcGateway for a suggested 30 minutes to ensure that the device grabs the time from the gateway. This is so that you can associated a time with the GPS coordinates
4) And, if you are going to use the above code and leave it unmodified to work with Losant, you'll notice at the end of the code that we have a time delay. This is due to how the Losant platform works which can only consumer a certain amount of data every 30 seconds. The time delay allows the device to send out a batch of data then wait and keep sending to ensure that Losant receives all the messages.
Hope that helps!