B4R Question ESP8266 - software serial - not receive data

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends, please very much for help,

I am using two esp 8266 connected via sofware serial

ESP1 to ESP2 (see picture with pinout in attachement)
pin 14 --> pin 12
pin 12 --> pin 14
GND --> GND
both esp are connected to usb

I have this simple code in both esp:

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 500
#End Region
'
Sub Process_Globals

    Public Serial1 As Serial                'Serial connection for Debug..
    Public Serial2 As SoftwareSerial      
    Public astream As AsyncStreams
    Public timer As Timer
'
End Sub

'
Private Sub AppStart
     Serial1.Initialize(115200)
     Log("AppStart")'
'  
    Serial2.Initialize(9600,12,14)    'pin ESP07
    astream.Initialize(Serial2.Stream,"astream_newdata","astream_error")
'
    timer.Initialize("timer_Tick",2000)
    timer.Enabled=True

End Sub

Sub timer_Tick
    Log("tick")
    Dim msg() As Byte ="hallo"
    astream.Write(msg)
End Sub


Sub astream_newdata (Buffer() As Byte)    '
Log("from esp:",Buffer)
End Sub

'
Sub astream_error
    Log("Serial - No Connection")
End Sub

I am using board setting - please see picture

but I am trying it this simle connection second day and I cant receive data....

Please, where I am doing mistake?
I want use software serial and in the past I know that I had success with this, but now I dont know where I am doing mistake...

Please for help..
Thank you
p4ppc
 

Attachments

  • 1.jpg
    1.jpg
    43 KB · Views: 434
  • 2.jpg
    2.jpg
    41.8 KB · Views: 344
Last edited:

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear Tigrot,

thank you very much for your answer. I have not osciloscope. On red PCB is pin 13 but not 15.
so
I have tried to set one ESP pin 13 as received pin and I have same result, I cant receive data...
Best regards
p4ppc

EDIT: I have tried to set one ESP pin 13 as TX pin and I have same result
 
Last edited:
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Just to note I have successfully used pins 12 (D6) and 14 (D5) for Software Serial in the past. @tigrot 's pin choice may be better, I don't know. These are just ones I chose.
Though when updating an old project recently it stopped working. I assumed I had been a bit rough with the hardware and broke my 232 breakout board. I have ordered some new ones, but they haven't arrived yet.

I have also setup a new project in Arduino, using the same pins for RS485 comms via Software Serial and it too works fine.
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Barx,

Just to note I have successfully used pins 12 (D6) and 14 (D5) for Software Serial in the past.
Yes, I have the same trouble. In the past I have success with pin 12 and 14, but now it is not functioned. Very interresting is that Sendig is OK, but receiving in NOT ok.

I have 2 peaces of HW, one old and one absolute new. On both is this trouble. I have tried the same - create new project in b4r, but this not sole this situation.
I am using same board settings.
p4ppc
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Barx,


Yes, I have the same trouble. In the past I have success with pin 12 and 14, but now it is not functioned. Very interresting is that Sendig is OK, but receiving in NOT ok.

I have 2 peaces of HW, one old and one absolute new. On both is this trouble. I have tried the same - create new project in b4r, but this not sole this situation.
I am using same board settings.
p4ppc
Very interesting indeed.

Mine was same. I linked my ESP8266 project to a USB to RS232 lead connected to laptop and software on laptop to monitor. Again I could transmit from ESP8266 to laptop, but could not receive when transmitted from laptop.

Maybe it is a bug that has recently been introduced. My original project is a couple of years old and was working fine until I updated it. I also tried putting back to a backup of existing code and still didn't work. Hence I assumed I had broken the 232 board.

I also tried other pins, no joy.

Once my new 232 boards arrive I will be trying the new hardware.

@Erel has the SoftwareSerial or AsyncStreams libs been updated in a way that could casue this? or any other reason you can think of that may cause the issue?
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
I just realised today is Saturday. Erel is resting ?
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Barx,

very interesting. So I will buy new ESP module for certain and with this two old peaces I will try to connect them to other module - for example bluetooth, and I will write the result here.

I am fighting with absolutely same situation as you described....
Thank you very much
p4ppc

EDIT:
I am using B4R 2.80
rSoftwareSerial Version 1.00
rCore 2.01
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Looking more like a software issue for sure.
The B4R library files appear to be non-compiled code, so a little editting should be possible.

Once I get some working hardware again I will try to add some logging lines to try see where the code gets stuck.

In the function
B4X:
AsyncStreams::checkForData
(The sub I think will have the issue)
There appears to be some commented out logs anyway,
Example:
B4X:
// ::Serial.print("is connected: ");

so hopefully copying that format and logging different remarks for each step throughout that sub should give some good indication.

I am currently using B4R v3.31
Not sure what version my old project was originally comiled with as it now shows 3.31 because I have re-compiled it recently.

Looking at B4R changelog, async streams was updated at version 2.00. Maybe it broke here and was never picked up. The mystery continues
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Thank you for your tips Barx
We're just 2 people trying to figure the same problem ?

I have tried the direct stream access with my assumed bad hardware, I never get any bytes on the stream so i guess my hardware really is busted ?
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Barx,

yes...

and

realy you have tried:
B4X:
swserial.Initialize(9600,12,14)

and in timer (I have set tick= 1 second)

B4X:
If swserial.Stream.BytesAvailable> 1 Then
        Dim b(swserial.Stream.BytesAvailable) As Byte
        Dim len As Int = swserial.Stream.ReadBytes(b, 0, b.Length)
        Log (b)
End If

here is pin=12 for receiving. With my HW this solutions is ok. It is not ok when I am using ASTREAM - i am still looking for astream solution...

Sorry if your hardware is not ok :( I know your feelings. ;)
p4ppc
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
@petr4ppc ? It's is ok, but thanks.

My own fault. I broke it, trying to fix it, when it wasn't broke LOL.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
This is for Erel when he swings by in the morning.

In the AsyncStreams lib file. The Initialize method adds an item to a Poller, I half understand what this is doing.

Also, in the same file the method
B4X:
void AsyncStreams::checkForData(void* b)
Appears to expect an arg/parameter 'void* b'.

What I don't understand is how this parameter is passed?

When the item is added to the Poller, no such parameter is mentioned.

The reason I point this out is I am wondering if the NewData sub in B4R never gets called because in the lib
B4X:
int av = me->stream->BytesAvailable();
never has any bytes because the line
B4X:
AsyncStreams* me = (AsyncStreams*) b;
may just be creating a blank AsyncStream object as 'b' may never actually be passed.

That's my theory so far ?
I don't fully understand the Arduino / c language so I could be totally wrong.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
well, my 232 boards still haven't shownup. Slightly annoying not being able to make any progress.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Well, I can't get my breath. Post arrived today with what appears to be my delivery I have been waiting 2 weeks for......... All I have is an empty envelope with a little tear in it. :mad:
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
I think I'm about to give up on this.
I have my new hardware and put it together. I tested with simple arduino project and get a loopback response so I know hardware is good.

I have a small test project in b4r and spent about 3 hours last night going through the b4r libraries, mainly AsyncStreams and B4RStream.
The issue as far as I can tell is that when the B4RStream library does readBytes with the line

B4X:
Int i = wrappedStream->readBytes(((Byte*)Buffer->data + StartOffset + total), MaxCount);

The returned value 'i' is -1.
If you log the action directly with
B4X:
::Serial.println(wrappedStream->readBytes(((Byte*)Buffer->data + StartOffset + total), MaxCount));

the returned value is 4294967295 which is higher than the max value of the Int variable (2147483647) so is possibly why it returns -1 (overflow maybe?)

This in turn returns to the AsyncStream lib the value of read bytes as 0
So then in this code in AsyncStream
B4X:
        if (index > 0 && (!me->prefixMode || index == maxSize)) {
            arr->length = index;
            sender->wrapPointer(b);
            B4R::StackMemory::cp += index;
            ::Serial.print("Lib - Data4");
            me->NewDataSub(arr);
        }
'i' is always 0 and so NewDataSub is never called.

Also, interestingly. When accessing the stream direct in b4r with
B4X:
    If swserial.Stream.BytesAvailable> 1 Then
        Dim b(swserial.Stream.BytesAvailable) As Byte
        Dim len As Int = swserial.Stream.ReadBytes(b, 0, b.Length)
        Log ("b4r - ", b)
        Log ("Length = ", len)
    Else
        Log("No data")
    End If
in the log, Length = 0. Which again uses the B4RStream lib and returns 0 like when using AsyncStream.

Any thoughts on this @Erel?
 
Upvote 0
Top