B4R Question How to Check two or more variables

Status
Not open for further replies.

AndroidMadhu

Active Member
Licensed User
Hello,
I want to check both humid and temp received from Arduino at Esp8266.
Below is the code

B4X:
Private Sub Arduino_Received_Data(humid () As Byte,temp As Byte)
    If bc.IndexOf(humid,"80") > -1 Then  <===== Here the value "80" will be different at times
        Log("Received from Arduino : ",humid)
        'timer1_Tick
    End If
End Sub
How to check humid and temp all at once with different value. Or any other way to check the status whether data has been received at esp8266 side from Arduino
 

AndroidMadhu

Active Member
Licensed User
@Erel,
yes.... I got your point. But One details I am not able to understand.
1. I want to send humid, and temp from dht11 sensor from Arduino to esp8266
2. Esp will receive the data from Arduino and send to Cloud server.

Here I received the data from Arduino and it is like below at Esp8266 side...
B4X:
Humid from Ardiono :33.3977.99  <----here both Temp & Humid are coming
Temp from Arduino :33.3977.99  <----here both Temp & Humid are coming
At Arduino the below is code to send to Esp
B4X:
Private Sub Timer1_Tick
    'Dim FixedValue As String=80
    Dim humid(),temp() As Byte
    humid="33.39"
    temp="77.99"
    'Astrem.Write(ser.ConvertBytesToArray(humid,data))
    Astrem.Write(humid)
    Astrem.Write(temp)
    Log("Send to Esp8266 Successfully!!")
End Sub
At ESP receiving Side
B4X:
Private Sub Arduino_Received_Data(buffer() As Byte)
Log("Humid from Ardiono :",buffer)
Log("Temp from Arduino :",buffer)
End Sub
I want to separate the values and send to cloud server
 

AndroidMadhu

Active Member
Licensed User
I have using B4RSerializator at ESp8266 side. And I getting the below error while compiling

B4X:
Public Serial1 As Serial
    Public softser As SoftwareSerial
    Public bc As ByteConverter
    Public wifi As ESP8266WiFi
    'Private timer1 As Timer
    Public Astream As AsyncStreams
    Private ser As B4RSerializator
    Private BE(2) As Object
Private Sub Arduino_Received_Data(buffer() As Byte)

Dim data() As Object=ser.ConvertBytesToArray(buffer,BE)
'Log("Humid from Ardiono :",data(0))
'Log("Temp from Arduino :",data(1))

End Sub
And I am getting the error as "Smart strings are not supported"
 

AndroidMadhu

Active Member
Licensed User
I incorporated B4RSerializator at Arduino Side
B4X:
Private Sub Timer1_Tick
    'Dim FixedValue As String=80
    Dim humid(),temp() As Byte
    humid="33.39"
    temp="77.99"
    Astrem.Write(ser.ConvertArrayToBytes(Array(humid,temp)))
    'Astrem.Write(humid)
    'Astrem.Write(temp)
    Log("Send to Esp8266 Successfully!!")
End Sub
At ESP8266 Side



B4X:
Public Serial1 As Serial
    Public softser As SoftwareSerial
    Public bc As ByteConverter
    Public wifi As ESP8266WiFi
    'Private timer1 As Timer
    Public Astream As AsyncStreams
    Private ser As B4RSerializator
    Private BE(2) As Object
Private Sub Arduino_Received_Data(buffer() As Byte)
ser.ConvertBytesToArray(buffer,BE)
Log("Humid from Ardiono :",BE(0))
Log("Temp from Arduino :",BE(1)) 
End Sub
It is running as expected. But after 1 minute, I am getting error as "Out of bounds error. Array length = 2, Index = 65535".

B4X:
Wifi Connected Successfully!!!
Humid from Ardiono :33.39
Temp from Arduino :77.99
Humid from Ardiono :33.39
Temp from Arduino :77.99
Humid from Ardiono :33.39
Temp from Arduino :77.99
Humid from Ardiono :33.39
Temp from Arduino :77.99
Humid from Ardiono :33.39
Temp from Arduino :77.99
Humid from Ardiono :33.39
Temp from Arduino :77.99
Out of bounds error. Array length = 2, Index = 65535
Please advice...
 
Status
Not open for further replies.
Top