Sub mqtt_MessageArrived(Topic As String, payload()As Byte)
Log("Topic recu =",Topic," Payload=",payload)
If Topic = bc.StringFromBytes(GlobalStore.slot7) Then 'cas message rfbridge
audit(0) = 1
audit(1) = 1
' case payload from rfbridge + sos_key is the googd one, we store this alarm
If (bc.IndexOf(payload,GlobalStore.Slot11)= 87) Or (bc.IndexOf(payload,GlobalStore.Slot12)= 87) Then
bc.ArrayCopy(bc.SubString2(payload,2,29),hr_last)
If sosnb = 0 Then bc.ArrayCopy(bc.SubString2(payload,2,29),hr_start)
bc.ArrayCopy(bc.SubString2(payload,86,94),sos_key)
If sosnb < 999 Then
sosnb = sosnb + 1
Else
sosnb = 0
End If
End If
End If
If Topic = bc.StringFromBytes(GlobalStore.Slot8) Then 'cas message android
'request from mobile => we have to provide answer
Dim Topic_out As String
Dim payload_out() As Byte
Topic_out = bc.StringFromBytes(GlobalStore.slot10)
If audit(1) = 1 Then
payload_out = "rf_OK ".getbytes
Else
payload_out = "rf_NOK ".getbytes
End If
If bc.IndexOf(payload,"reset") = 0 Then
sosnb = 0
' payload_out = JoinBytes( Array(payload_out," Available RAM=".getbytes))
' payload_out = JoinBytes( Array(payload_out,(bc.StringfromBytes(AvailableRAM)).getbytes))
' payload_out = JoinBytes( Array(payload_out," Stack level=".getbytes))
' payload_out = JoinBytes( Array(payload_out,StackBufferUsage))
End If
If sosnb > 0 Then
payload_out = JoinBytes( Array(payload_out,"SOSnb:".getbytes))
Dim ss As String = sosnb
Dim sas() As Byte = " "
bc.ArrayCopy(bc.StringToBytes(ss),sas)
payload_out = JoinBytes( Array(payload_out,sas))
payload_out = JoinBytes( Array(payload_out," ".getbytes))
payload_out = JoinBytes( Array(payload_out,hr_start))
If sosnb > 1 Then
payload_out = JoinBytes( Array(payload_out," ".getbytes))
payload_out = JoinBytes( Array(payload_out,hr_last))
End If
payload_out = JoinBytes( Array(payload_out," SOS=".getbytes))
payload_out = JoinBytes( Array(payload_out,sos_key))
End If
Log("Topic out=",Topic_out," / ","payload=",payload_out)
If WiFi.IsConnected = True Then
mqtt.Publish(Topic_out, payload_out)
End If
End If
End Sub