Dear friends, Just like ESP8266 Firebase push message tutorial can someone post an example for firebase database example? if it is possible.
Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Dim timer1 As Timer
Dim uid As Long
Dim esp As ESP8266extras
Dim bc As ByteConverter
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
uid=esp.UniqueID
If wifi.Connect2("****","****") Then
Log("Connected to router.")
timer1.Initialize("timer1_Tick",2000)
timer1.Enabled=True
Else
Log("Failed to connect to router.")
Return
End If
End Sub
Sub timer1_tick
Dim datetime As String="26/12/2018,18:54:00"
Dim otemp As Float=Rnd(20,30)
Dim o As String=NumberFormat(otemp,1,2)
Dim atemp As Float=Rnd(20,30)
Dim a As String=NumberFormat(atemp,1,2)
Dim u As String=uid
Dim id As String=JoinStrings(Array As String("https://***.firebaseio.com/",u,".json"))
Dim data As String=JoinStrings(Array As String("'",datetime,",",o,",",a,"'"))
Log(id)
Log(data)
HttpJob.Initialize("")
HttpJob.Post(id,data)
End Sub
Sub JobDone (Job As JobResult)
Log("*******************************")
Log("JobName: ", Job.JobName)
If Job.Success Then
Log("Response: ", bc.SubString2(Job.Response, 0, Min(200, Job.Response.Length))) 'truncate to 200 characters
Else
Log("ErrorMessage: ", Job.ErrorMessage)
Log("Status: ", Job.Status)
Log(Job.Response)
End If
End Sub
https://***.firebaseio.com/12615289.json
26/12/2018,18:54:00,28.00,29.00
*******************************
JobName:
ErrorMessage:
Status: 400
{
"error" : "Invalid data; couldn't parse JSON object, array, or value."
}
Sub btnSEND_Click
Dim j As HttpJob
j.Initialize("",Me)
Dim DT As String=DateTime.Date(DateTime.Now)&","&DateTime.Time(DateTime.Now)
Dim otemp As Float=Rnd(20,30)
Dim o As String=NumberFormat(otemp,1,2)
Dim atemp As Float=Rnd(20,30)
Dim a As String=NumberFormat(atemp,1,2)
Dim u As String="12345678"
Dim id As String="https://***b.firebaseio.com/"&u&".json"
Dim data As String="{"& $"""$&"Value"&$"""$&":"& $"""$&DT&","&o&","&a& $"""$&"}"
Log(data)
j.PostString(id,data)
j.Release
End Sub
Dim j As HttpJob
j.Initialize("",Me)
j.Download("https://***.firebaseio.com/12345678.json")
Wait For (j) jobdone (j As HttpJob)
If j.Success Then
'Log(j.GetString)
Dim s As String=j.GetString
Dim parser As JSONParser
parser.Initialize(s)
Dim root As Map = parser.NextObject
Dim FirstValue As String = root.Get("-LUiTbdp89H7EqqBUDCm")
Dim i As Int
Dim otemp(root.size) As String
Dim atemp(root.size) As String
Dim dt(root.size) As String
Dim tm(root.size) As String
For Each Key As String In root.Keys
Dim list1 As List
list1.Initialize
list1.Add (root.Get(Key))
Dim map1 As Map
map1 = list1.Get(0)
Dim d As String=map1.GetValueAt(0)
Log(d)
Dim temp(4) As String=Regex.Split(",",d)
dt(i)=temp(0)
tm(i)=temp(1)
otemp(i)=temp(2)
atemp(i)=temp(3)
i=i+1
Next
Else
Log("Error:" &j.ErrorMessage)
End If
j.Release
End Sub
{"-LUiTbdp89H7EqqBUDCm":{"Value":"12/27/2018,12:34:26,28,26"},"-LUiTsTmgH5MMRwe_-Be":{"Value":"12/27/2018,12:35:36,24,26"},"-LUiXlocwfiQFhPqMnC2":{"Value":"12/27/2018,12:52:36,29,24"},"-LUiZ0VhxFzQTSFW2q1i":{"Value":"12/27/2018,12:58:03,23,23"},"-LUiZ5-nnrthMgBBtUdL":{"Value":"12/27/2018,12:58:22,20,20"},"-LUjDwJMb8E20WST3b6M":{"Value":"12/27/2018,16:05:33,23,26"},"-LUjDyjjYuH5lAWgJgor":{"Value":"12/27/2018,16:05:44,27,25"},"-LUjGeZBqyJLuiOjeTio":{"Value":"12/27/2018,16:17:28,24,25"},"-LUjGjd64loOAwO3U1ee":{"Value":"12/27/2018,16:17:49,22,21"}}
12/27/2018,12:34:26,28,26
12/27/2018,12:35:36,24,26
12/27/2018,16:17:28,24,25
12/27/2018,12:52:36,29,24
12/27/2018,16:17:49,22,21
12/27/2018,12:58:03,23,23
12/27/2018,16:05:33,23,26
12/27/2018,16:05:44,27,25
12/27/2018,12:58:22,20,20
Do it yourself is requested.But I want it ordered please let me know the way!
Hi...I successfully logged into Firebase...but the real problem is to obtained Joan format in B4R...so I converted all the JSON format data into bytes...by ASCII code converter...and it's works for me..@Erel,
How can we port the code in post #10 to B4R? We do not have smart string capability there.