B4R Question astream.Initializeprefix problem

Discussion in 'B4R Questions' started by mrossen, Apr 11, 2018.

  1. mrossen

    mrossen Active Member Licensed User

    Hi,

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

    Code:
    SerialCom.Initialize(960020)
        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

    Code:
    SerialCom.Initialize(960020)
        astreamCom.Initialize(SerialCom.Stream, 
    False"astreamCom_NewData""astreamCom_Error")
    Mogens
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    What is connected to the other side of the serial connection?
     
  3. mrossen

    mrossen Active Member Licensed 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.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Why are you using pin 0 for SoftwareSerial? This is the pin that is used by the hardware serial port.
     
  5. mrossen

    mrossen Active Member Licensed User

    The AI Thinker module have only GPIO0 and GPIO02
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    If this pin is used for other things then it will add "garbage" to the connection and will cause problems. Especially with prefix mode.
     
  7. mrossen

    mrossen Active Member Licensed User

    So I have to use the RX and TX pins?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    No. You need to use two pins that are not used for anything else.
     
  9. mrossen

    mrossen Active Member Licensed User

  10. mrossen

    mrossen Active Member Licensed 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
     
  11. mrossen

    mrossen Active Member Licensed 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
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    I can only guess that there is some data left when you start reading from the serial port and it causes the prefix counting to be broken. Don't use prefix mode.
     
  13. mrossen

    mrossen Active Member Licensed 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?


    Code:
    SerialCom.Initialize(960020)
        astreamCom.Initializeprefix(SerialCom.Stream, 
    True"astreamCom_NewData""astreamCom_Error")
    I also change the

    Code:
    astreamCom.WaitForMoreDataDelay = 3
    From 5 to 3. This seems to be more reliable. With the value = 5 the last bytes are wrong sometimes.
     
  14. Erel

    Erel Administrator Staff Member Licensed User

Loading...