Dear friends,
I am experimenting with EBYTE E32-433T30D modules for LORA. The modules are correctly configured. I am able to transmit and receive data using two NODEMCU devices using c/c++ code in Arduino IDE. But when I tried the same(similar!) approach with B4R , the transmit code works fine but the receive code fails. The RX pin activity is seen as I have used D4( GPIO2 with built-in LED). The Astream_Newdata event does not fire at all.
B4R version:3.00
ESP8266 ARDUINO CORE version:2.6.3
Here is my transmit and receive code :
I am experimenting with EBYTE E32-433T30D modules for LORA. The modules are correctly configured. I am able to transmit and receive data using two NODEMCU devices using c/c++ code in Arduino IDE. But when I tried the same(similar!) approach with B4R , the transmit code works fine but the receive code fails. The RX pin activity is seen as I have used D4( GPIO2 with built-in LED). The Astream_Newdata event does not fire at all.
B4R version:3.00
ESP8266 ARDUINO CORE version:2.6.3
Here is my transmit and receive code :
TX CODE:
Sub Process_Globals
Public Serial1 As Serial
Public softserial As SoftwareSerial
Private d1 As NodeMCU_ESP12_pins
Private timer1 As Timer
Private ser As B4RSerializator
Dim TEMP As Float
Dim HUMIDITY As Float
Private astream As AsyncStreams
Dim i As Long
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
softserial.Initialize(9600,d1.D4,d1.D3)
astream.Initialize(softserial.Stream,"astream_Newdata","astream_Error")
RunNative("setup",Null)
Delay (100)
timer1.Initialize("timer1_Tick",5000)
timer1.Enabled=True
End Sub
Sub Timer1_Tick
RunNative("read",Null)
Log(TEMP)
Log(HUMIDITY)
Dim msg As String=JoinStrings(Array As String(i,",",TEMP,",",HUMIDITY,CRLF))
astream.Write(msg.GetBytes)
Log(msg)
i=i+1
End Sub
Sub astream_Newdata (Buffer() As Byte)
Log("NewData from ESP:",Buffer)
End Sub
Sub Astream_Error
Log("Error.")
End Sub
#if C
#include <Wire.h>
#include "Adafruit_SHT31.h"
Adafruit_SHT31 sht31 = Adafruit_SHT31();
void setup(B4R::Object* o){
sht31.begin(0x44);
}
void read (B4R::Object* o) {
b4r_main::_temp=sht31.readTemperature();
b4r_main::_humidity=sht31.readHumidity();
}
RX CODE:
Sub Process_Globals
Public Serial1 As Serial
Private astream As AsyncStreams
Private softserial As SoftwareSerial
Dim d1pins As NodeMCU_ESP12_pins
Dim bc As ByteConverter
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("Appstart")
softserial.Initialize(9600, d1pins.D4, d1pins.D3)
astream.Initialize(softserial.Stream, "Astream_Newdata", "Astream_Error")
End Sub
Sub Astream_Newdata (Buffer() As Byte)
Log(Buffer)
End Sub
Sub Astream_Error
Log("Error.")
End Sub
TX CODE C/C++ WORKING:
#include <SoftwareSerial.h>
#include <Arduino.h>
#include <Wire.h>
#define SOFT_TX D3
#define SOFT_RX D4
#include "Adafruit_SHT31.h"
Adafruit_SHT31 sht31 = Adafruit_SHT31();
SoftwareSerial softSerial(SOFT_RX, SOFT_TX); // RX, TX
long i;
void setup() {
pinMode(SOFT_RX, INPUT);
pinMode(SOFT_TX, OUTPUT);
sht31.begin(0x44);
Serial.begin(115200);
softSerial.begin(9600);
}
void loop() {
String msg="";
i++;
float t = sht31.readTemperature();
float h = sht31.readHumidity();
msg=msg+i+","+t+","+h+"\r";
softSerial.println (msg );
delay(2000);
Serial.println (msg);
delay(2000);
}
RX CODE C/C++ WORKING:
#include <SoftwareSerial.h>
#define SOFT_TX D3
#define SOFT_RX D4
SoftwareSerial softSerial(SOFT_RX, SOFT_TX); // RX, TX
void setup() {
pinMode(SOFT_RX, INPUT);
pinMode(SOFT_TX, OUTPUT);
Serial.begin(115200);
softSerial.begin(9600);
}
void loop() {
if(softSerial.available()){
char i;
i = softSerial.read();
Serial.print(i);
delay (10);
}
}