Commit eefaf6ba authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca
Browse files

Some bug fix and test Arduino prj - add mechanical drawings for laser cutter

parent 401460af
Loading
Loading
Loading
Loading
+113 −0
Changes for HalfDuplex/HalfDuplex/HalfDuplex.ino: 113 added lines, 0 removed lines.
Original line number Diff line number Diff line
#include <SPI.h>
#include <LoRa.h>

// Pin definetion of WIFI LoRa 32
// HelTec AutoMation 2017 support@heltec.cn 
#define SCK     5    // GPIO5  -- SX127x's SCK
#define MISO    19   // GPIO19 -- SX127x's MISO
#define MOSI    27   // GPIO27 -- SX127x's MOSI
#define SS      18   // GPIO18 -- SX127x's CS
#define RST     14   // GPIO14 -- SX127x's RESET
#define DI00     26   // GPIO26 -- SX127x's IRQ(Interrupt Request)

#define BAND    915E6  //you can set band here directly,e.g. 868E6,915E6
#define PABOOST true
  
byte localAddress = 0xBB;     // address of this device
byte destination = 0xFF;      // destination to send to

String outgoing;              // outgoing message
byte msgCount = 0;            // count of outgoing messages
long lastSendTime = 0;        // last send time
int interval = 2000;          // interval between sends

void setup()
{
  Serial.begin(115200);                   // initialize serial
  while (!Serial);

  Serial.println("LoRa Duplex with callback");

  SPI.begin(SCK,MISO,MOSI,SS);
  LoRa.setPins(SS,RST,DI00);// set CS, reset, IRQ pins

  LoRa.enableCrc();
  LoRa.setSyncWord(0xF3);
  
  if (!LoRa.begin(BAND))
  {
    Serial.println("LoRa init failed. Check your connections.");
    while (true);                       // if failed, do nothing
  }

  LoRa.onReceive(onReceive);
  LoRa.receive();
  Serial.println("LoRa init succeeded.");
}

void loop()
{
  if (millis() - lastSendTime > interval)
  {
    String message = "Hello World!";   // send a message
    sendMessage(message);
    Serial.println("Sending " + message);
    lastSendTime = millis();            // timestamp the message
    interval = random(2000) + 1000;     // 2-3 seconds
    LoRa.receive();                     // go back into receive mode
  }
}

void sendMessage(String outgoing)
{
  LoRa.setSyncWord(0xF3);
  LoRa.beginPacket();                   // start packet
  LoRa.write(destination);              // add destination address
  LoRa.write(localAddress);             // add sender address
  LoRa.write(msgCount);                 // add message ID
  LoRa.write(outgoing.length());        // add payload length
  LoRa.print(outgoing);                 // add payload
  LoRa.endPacket();                     // finish packet and send it
  msgCount++;                           // increment message ID
}

void onReceive(int packetSize)
{
  if (packetSize == 0) return;          // if there's no packet, return

  // read packet header bytes:
  int recipient = LoRa.read();          // recipient address
  byte sender = LoRa.read();            // sender address
  byte incomingMsgId = LoRa.read();     // incoming msg ID
  byte incomingLength = LoRa.read();    // incoming msg length

  String incoming = "";                 // payload of packet

  while (LoRa.available())             // can't use readString() in callback
  {
    incoming += (char)LoRa.read();      // add bytes one by one
  }

  if (incomingLength != incoming.length())   // check length for error
  {
    Serial.println("error: message length does not match length");
    return;                             // skip rest of function
  }

  // if the recipient isn't this device or broadcast,
  if (recipient != localAddress && recipient != 0xFF)
  {
    Serial.println("This message is not for me.");
    return;                             // skip rest of function
  }

  // if message is for this device, or broadcast, print details:
  Serial.println("Received from: 0x" + String(sender, HEX));
  Serial.println("Sent to: 0x" + String(recipient, HEX));
  Serial.println("Message ID: " + String(incomingMsgId));
  Serial.println("Message length: " + String(incomingLength));
  Serial.println("Message: " + incoming);
  Serial.println("RSSI: " + String(LoRa.packetRssi()));
  Serial.println("Snr: " + String(LoRa.packetSnr()));
  Serial.println();
}
+7 −5
Changes for LoRaReceiverInterrupt/LoRaReceiverInterrupt.ino: 7 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -71,11 +71,10 @@ void setup() {

  SPI.begin(SCK,MISO,MOSI,SS);
  LoRa.enableCrc();
  LoRa.setTxPower(20,14);
  LoRa.setSignalBandwidth(7.8E3);
  LoRa.setSpreadingFactor(12);
  LoRa.setTxPower(20,PA_OUTPUT_PA_BOOST_PIN);
  LoRa.setPreambleLength(8);
  LoRa.setPins(SS,RST,DI0);
  if (!LoRa.begin(BAND)) {
  if (!LoRa.begin(BAND, PABOOST)) {
    drawTextOLED("Starting LoRa failed!");
    while (1);
  }
@@ -121,10 +120,12 @@ void loop() {

  if(isLoRaOnSenderMode)
  {
    delay(2000);
    for(int i = 0; i < 10; i++)
    {
      LoRa.beginPacket();
      LoRa.print(lastCommand);
      LoRa.endPacket();
    }
    
    LoRa.receive();
    isLoRaOnSenderMode = false;
@@ -187,6 +188,7 @@ String read_r2 = String(RELE_READ_2, DEC);

void onReceive(int packetSize)
{
  //LoRa.crc();
  // received a packet
  String str = "";
  for (int i = 0; i < packetSize; i++)
+35 −13
Changes for LoRaSender/LoRaSender.ino: 35 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ WiFiServer server(80);
#define RST     14   // GPIO14 -- SX127x's RESET
#define DI0     26   // GPIO26 -- SX127x's IRQ(Interrupt Request)

#define BAND    915E6  //you can set band here directly,e.g. 868E6,915E6
#define BAND    868E6  //you can set band here directly,e.g. 868E6,915E6
#define PABOOST true

SSD1306  display(0x3c, 4, 15);
@@ -41,6 +41,11 @@ String signalLevel = "";

void setup(void)
{
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  
  //-------- DISPLAY INIT --------------

  pinMode(16, OUTPUT);
@@ -62,17 +67,16 @@ void setup(void)
  
  SPI.begin(SCK, MISO, MOSI, SS);
  LoRa.enableCrc();
  LoRa.setTxPower(20,14);
  LoRa.setSignalBandwidth(7.8E3);
  LoRa.setSpreadingFactor(12);
  LoRa.setTxPower(20,PA_OUTPUT_PA_BOOST_PIN);
  LoRa.setPreambleLength(8);
  LoRa.setPins(SS, RST, DI0);
  if (!LoRa.begin(BAND)) {
  if (!LoRa.begin(BAND, PABOOST)) {
    drawTextOLED("Starting LoRa failed!", "", "", "");
    while (1);
  }

  // register the receive callback
  LoRa.onReceive(onReceive);
  WiFi.mode (WIFI_STA);
  WiFi.setSleep(false);
  
  // Connect to WiFi network
  WiFi.begin(ssid, password);
@@ -126,6 +130,13 @@ void loop(void)
  
  drawTextOLED(lastCommand, ipAddr, lastReceived, signalLevel);

  long rssi = WiFi.RSSI();

  if(rssi == 0)
  {
    ESP.restart();
  }
  
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
@@ -221,6 +232,7 @@ void loop(void)

void onReceive(int packetSize)
{
  //LoRa.crc();
  // received a packet
  // read packet
  String str;
@@ -231,19 +243,20 @@ void onReceive(int packetSize)
  }

  if (str.indexOf("r : ") == 0) {
    lastCommand = str;
    lastReceived = str;
  }

  if (str.indexOf("p : ") == 0) {
    lastCommand = str;
    lastReceived = "";
  }

  if (str.indexOf("b : ") == 0) {
    lastCommand = str;
    lastReceived = "";
  }
  
  lastCommand = str;
  
  signalLevel = String(LoRa.packetRssi(), DEC);
}

@@ -255,15 +268,18 @@ void pinRequest(String req)
{
  req = req.substring(req.lastIndexOf('/') + 1);
  int reqInt = req.toInt();

  for(int i=0;i < 10;i++)
  {
    // send packet
    LoRa.beginPacket();
    LoRa.print("p : ");
    LoRa.print(reqInt);
    LoRa.endPacket();

  delay(1);
  }

  // put the radio into receive mode
  LoRa.onReceive(onReceive);
  LoRa.receive();
}

@@ -271,15 +287,17 @@ void setBrightness(String req)
{
  req = req.substring(req.lastIndexOf('/') + 1);
  int reqInt = req.toInt();
  for(int i=0;i < 10;i++)
  {
    // send packet
    LoRa.beginPacket();
    LoRa.print("b : ");
    LoRa.print(reqInt);
    LoRa.endPacket();

  delay(1);
  }
  
  // put the radio into receive mode
  LoRa.onReceive(onReceive);
  LoRa.receive();
}

@@ -287,12 +305,16 @@ void pinRequestRead(String req)
{
  req = req.substring(req.lastIndexOf('/') + 1);
  int reqInt = req.toInt();
  for(int i=0;i < 10;i++)
  {
    // send packet
    LoRa.beginPacket();
    LoRa.print("r : ");
    LoRa.print(reqInt);
    LoRa.endPacket();
  }
  
  // put the radio into receive mode
  LoRa.onReceive(onReceive);
  LoRa.receive();
}
+1 −0
Changes for mechanical drawings/assieme_taglio.rd: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
қ҉ppp韛]p		pB	9Iлϻˉϻďīpp-]p+pp			ċ		B	П	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