0

i've connected 2 RA-02 modules to my ESP8266 s. Both are capable of transmitting and receiving data between each other. and also esp8266 s are represented as access points to whatever client that wants to connect to them. then esp would send the received data from its RA-02 to the client. But when i send a string from one end, there's no reception on the other side. i can see in the serial monitor that the transmission was successful but i can't receive anything on the other side.

Here's the code:

#include <ESP8266WiFi.h>
#include <ArduinoWiFiServer.h>
#include <SPI.h>
#include <LoRa.h>

#ifndef STASSID
#define STASSID "ESP_SD-192-168-1-184-3434"
#define STAPSK  "hta-1401"
#endif

#define ss 15
#define rst 16
#define dio0 4

const char* ssid     = STASSID;
const char* password = STAPSK;
String s;
String str="";
ArduinoWiFiServer server(3434);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
    Serial.begin(57600);
    Serial.println();
    LoRa.setPins(ss, rst, dio0);
    if (!LoRa.begin(433E6)){
        Serial.println("Starting LoRa failed!");
        return;
    }else{
        Serial.println("LoRa started successfully");
    }
    
    IPAddress local_IP(192, 168, 1, 184);
    IPAddress gateway(192, 168, 1, 1);
    IPAddress subnet(255, 255, 0, 0);
    if (!WiFi.softAPConfig(local_IP, gateway, subnet))
        Serial.println("config failed");
    WiFi.mode(WIFI_AP);
    WiFi.softAP(ssid, password, 1, false);
    
    server.begin();
    IPAddress ip = WiFi.softAPIP();
    Serial.println();
    Serial.println(ip);
}
///////////////////////////////////////////////////////////////////////////////////////////
void loop() {
    WiFiClient client = server.available();
    if (client) {
        s = client.readStringUntil('\n');
        s.trim();
        Serial.println(s);
    }
    
    if(s.length() != 0){
        LoRa.beginPacket();
        LoRa.print(s);
        LoRa.endPacket();
        s.remove(0);
        Serial.println("Done");
    }

    int packetSize = LoRa.parsePacket();
    if (packetSize == 0){
        return;
    }
    byte loraRead[packetSize];
    int count = 0;
    Serial.println("Receiving packet...");
    while(LoRa.available()){
        str += static_cast<char>(LoRa.read());
        Serial.println(str);
    }
    server.println(str);
    server.flush();
    str.remove(0);
}

i tried different pins, using println instead of print while sending but no result.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.