B4R Question Wemos and GSM Module

BarryW

Active Member
Licensed User
Longtime User
No response coming from SoftwareSerial but when I'm using arduino it is working. Same RX and TX pin.
Here is my code. IT should reply with AT+OK

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Public SoftwareSerial As SoftwareSerial
    Public Stream As AsyncStreams
    Public Timer As Timer
    Dim DP As D1Pins
End Sub

Private Sub AppStart
    Serial1.Initialize(9600)
    
    SoftwareSerial.Initialize(9600, DP.D1, DP.D2)
    
    Stream.Initialize(SoftwareSerial.Stream, "Stream_NewData", "Stream_Error")
    
    Timer.Initialize("Timer_Tick", 2500)
    Timer.Enabled = True
    
    SoftwareSerial.Listening = True
    
    Delay(1000)
    
    Log("Ready...")
End Sub

Sub Stream_NewData (Buffer() As Byte)
    Log("Stream_NewData")
    Log(Buffer)
End Sub

Sub Stream_Error
    
End Sub

Sub Timer_Tick
    Log("Sending...")
    Stream.Write("AT".GetBytes)
    Stream.Write(CRLF)
End Sub
 

Michael1968

Active Member
Licensed User
Longtime User
No response coming from SoftwareSerial but when I'm using arduino it is working. Same RX and TX pin.
Here is my code. IT should reply with AT+OK

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Public SoftwareSerial As SoftwareSerial
    Public Stream As AsyncStreams
    Public Timer As Timer
    Dim DP As D1Pins
End Sub

Private Sub AppStart
    Serial1.Initialize(9600)
   
    SoftwareSerial.Initialize(9600, DP.D1, DP.D2)
   
    Stream.Initialize(SoftwareSerial.Stream, "Stream_NewData", "Stream_Error")

stream.WaitForMoreDataDelay = 100 '<-add this
   
    Timer.Initialize("Timer_Tick", 2500)
    Timer.Enabled = True
   
    SoftwareSerial.Listening = True
   
    Delay(1000)
   
    Log("Ready...")
End Sub

Sub Stream_NewData (Buffer() As Byte)
    Log("Stream_NewData")
    Log(Buffer)
End Sub

Sub Stream_Error
   
End Sub

Sub Timer_Tick
    Log("Sending...")
    Stream.Write("AT".GetBytes)
    Stream.Write(CRLF)
End Sub

add row 22 to your code and check it
 
Upvote 0

rodmcm

Active Member
Licensed User
Can you use the second RX/TX port. I ran two ports on an ESP32 with the following
B4X:
    Public Serial1 As Serial
    Public SerialNative2 As Stream
    Public astream As AsyncStreams                    ' B4x method to transmit and recieve data

and then in setup
B4X:
' enabling hardware serial 2
#if C
HardwareSerial Serial2(2); // Second Hardware Port
void SerialNative2(B4R::Object* unused)
{
::Serial2.begin(115200);
b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#End If


Public Sub AppStart
    Serial1.Initialize(115200)   
    RunNative("SerialNative2", Null)
    astream.Initialize(SerialNative2,"RecieveRTX2", "Astream_Error")      ' astream onto Serial2
 
Upvote 0
Top