B4R Question astream.Initializeprefix problem

mrossen

Active Member
Licensed User
Longtime User
Hi,

I have made a scenario where I use astream.Initializeprefix on both the WiFi and Serial streams with a ESP8266 module

B4X:
SerialCom.Initialize(9600, 2, 0)
    astreamCom.Initializeprefix(SerialCom.Stream, False, "astreamCom_NewData", "astreamCom_Error")

If I do that I get the 4 prefix bytes in the begining when I receive data from serial to WiFi.

And I am then missing the 4 last bytes!

I dont know why?

Anyone can explain that?

If I not using the prefix mode I get the hole data set include the first 4 bytes

B4X:
SerialCom.Initialize(9600, 2, 0)
    astreamCom.Initialize(SerialCom.Stream, False, "astreamCom_NewData", "astreamCom_Error")

Mogens
 

mrossen

Active Member
Licensed User
Longtime User
A device there also uses the prefix mode.

I have the same setup (Android <--> Bluetooth <--> device) with a bluetooth module. This works fine.

It is a standard bluetooh module, where I not have made the software for.
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
I have look in Espressif Systems Documentation.

It look like that GPIO1 is TX and GPIO3 is RX?

And GPIO0 / GPIO2 are unused.

upload_2018-4-12_11-48-59.png
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi,

I have made the same setup with a Wemos D1 R2. I use GPIO4 & GPIO5 as RX/TX. This is the same result.


This is what I receive :
000300160170018001902002100220802300

This is what I receive correct with Bluetooth:
01601700180019020021002208023002412825026000
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Now I got it to work,

I change the "BigEndian" option to True instead of false. But I dont understand why this works.
From Android/iPhone to ESP8266 I use the False, but then it has to be True from ESP8266 to my device?


B4X:
SerialCom.Initialize(9600, 2, 0)
    astreamCom.Initializeprefix(SerialCom.Stream, True, "astreamCom_NewData", "astreamCom_Error")

I also change the

B4X:
astreamCom.WaitForMoreDataDelay = 3

From 5 to 3. This seems to be more reliable. With the value = 5 the last bytes are wrong sometimes.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top