Error in sendPacketTimeoutACK

marioemanuel
Posts: 16
Joined: Tue May 30, 2017 5:51 pm

Re: Error in sendPacketTimeoutACK

Post by marioemanuel » Thu Mar 14, 2019 10:40 am

// Include these libraries to transmit frames with SX1272
#include <WaspSX1272.h>
#include <WaspFrame.h>
#include <WaspSensorParking.h>

// it is possible to change PARKING THRESHOLD on WaspSensorParking.h (default 75)
// it is possible to change MAX_TIMEOUT on WaspSX1272.h (default 10 seconds)

// define the destination address to send packets (destination = MESHLIUM)
uint8_t meshlium_address = 1;

// define the Waspmote ID
char nodeID[] = "PARKING648";

// define status variable
int e;

// define counter
int counter;

// Variable to store temperature
int temperature;

// Store parking status
boolean status;
boolean auxStatus;

//address for storing parking status to EEPROM
int ps_address = 3000;

//address for storing counter to EEPROM in order to send battery percentage
int c_address = 3001;

// define the node address value: from 2 to 255
uint8_t node_address = 3;

// Sleep time between measures
char sleepTime[] = "00:00:00:10";
char* time_date;


void sendParkingFrame(boolean status)
{
  // Creating frame to send
  frame.createFrame(ASCII);
  USB.println(F("Frame created"));

  // Add frame fields
  frame.addSensor(SENSOR_PS, status);
  
  // Printing frame
  frame.showFrame();
  
  // 5.1. Sending packet
  //e = sx1272.sendPacketTimeoutACKRetries(meshlium_address, frame.buffer, frame.length);
  e = sx1272.sendPacketTimeoutACK(meshlium_address, frame.buffer, frame.length, 60000);
    
  USB.println(F("----------------------------------------"));
  USB.println(F("Sending:"));
  USB.println(F("----------------------------------------"));
  
  // 5.2. Check sending status: if ACK was received check signal strength
  if( e == 0 )
  {
    USB.println(F("--> Packet sent OK"));
    e = sx1272.getSNR();
    USB.print(F("-> SNR: "));
    USB.println(sx1272._SNR);
    
    e = sx1272.getRSSI();
    USB.print(F("-> RSSI: "));
    USB.println(sx1272._RSSI);
    
    e = sx1272.getRSSIpacket();
    USB.print(F("-> Last packet RSSI value is: "));
    USB.println(sx1272._RSSIpacket);
    
  }
  else
  {
    USB.println(F("--> Error sending the packet"));
    USB.print(F("state: "));
    USB.println(e, DEC);
  }

  USB.println();
}


void sendBatteryFrame()
{
  // Creating frame to send
  frame.createFrame(ASCII);
  USB.println(F("Frame created"));

  // Add frame fields
  frame.addSensor(SENSOR_BAT, (uint8_t) PWR.getBatteryLevel());
  
  // Printing frame
  frame.showFrame();
  
  // 5.1. Sending packet
  // e = sx1272.sendPacketTimeoutACKRetries(meshlium_address, frame.buffer, frame.length);
  e = sx1272.sendPacketTimeoutACK(meshlium_address, frame.buffer, frame.length, 60000);
  
  USB.println(F("----------------------------------------"));
  USB.println(F("Sending:"));
  USB.println(F("----------------------------------------"));
  
  // 5.2. Check sending status: if ACK was received check signal strength
  if( e == 0 )
  {
    USB.println(F("--> Packet sent OK"));
    e = sx1272.getSNR();
    USB.print(F("-> SNR: "));
    USB.println(sx1272._SNR);
    
    e = sx1272.getRSSI();
    USB.print(F("-> RSSI: "));
    USB.println(sx1272._RSSI);
    
    e = sx1272.getRSSIpacket();
    USB.print(F("-> Last packet RSSI value is: "));
    USB.println(sx1272._RSSIpacket);
    
  }
  else
  {
    USB.println(F("--> Error sending the packet"));
    USB.print(F("state: "));
    USB.println(e, DEC);
  }

  USB.println();
}

void setup()
{
  // Turn on the USB and print a start message
  USB.ON();
  USB.println(F("START"));
  USB.println(F("YOU CAN CLOSE THE BOX. I WAIT FOR 1 SECONDS")); // for tests; in future must be 15 seconds
  delay(1000);
  
  // Set the Waspmote ID
  frame.setID(nodeID);

  // Once "calibration start" command is received, calibration starts.
  USB.println(F("Calibration start"));
  
  // The reference coefficients are loaded
  SensorParking.loadReference();
  // Turn on the board
  SensorParking.ON();
  USB.println(F("SENSOR PARKING BOARD ON"));
  delay(2000);
  // Proceed to calibrate
  SensorParking.calibration();
  USB.println(F("Calibration finished"));
  SensorParking.OFF();
 
  // Print the initial values
  USB.print("Initial Values: ");
  USB.print(F("X-Field: "));
  USB.print(SensorParking.initialX);
  USB.print(F(" Y-Field: "));
  USB.print(SensorParking.initialY);
  USB.print(F(" Z-Field: "));
  USB.println(SensorParking.initialZ);
  
  // Init sx1272 module
  sx1272.ON();
  USB.println(F("SX1272 ON"));
  sx1272.setRTCfromMeshlium();
  USB.println(F("SET TIME FROM MESHLIUM"));
  
  delay(100);
  
  // Switch ON RTC
  RTC.ON();
  USB.println(F("RTC ON"));
  
  // Select frequency channel
  e = sx1272.setChannel(CH_16_868);
  USB.print(F("Setting Channel CH_16_868.\t state "));
  USB.println(e);

  // Select implicit (off) or explicit (on) header mode
  e = sx1272.setHeaderON();
  USB.print(F("Setting Header ON.\t\t state "));
  USB.println(e);

  // Select mode: from 1 to 10
  e = sx1272.setMode(1); //Mode 1: medium range, medium data rate, medium battery impact
  USB.print(F("Setting Mode '1'.\t\t state "));
  USB.println(e);

  // Select CRC on or off
  e = sx1272.setCRC_ON();
  USB.print(F("Setting CRC ON.\t\t\t state "));
  USB.println(e);

  // Select output power (Max, High or Low)
  e = sx1272.setPower('H');
  USB.print(F("Setting Power to 'H'.\t\t state "));
  USB.println(e);

  // Select the node address value: from 2 to 255
  e = sx1272.setNodeAddress(node_address);
  USB.print(F("Setting Node Address to '3'.\t state "));
  USB.println(e);

  // Select the maximum number of retries: from '0' to '5'
  e = sx1272.setRetries(3);
  USB.print(F("Setting Max retries to '3'.\t state "));
  USB.println(e);
  USB.println();
  
  time_date = RTC.getTime();
  USB.print(F(" -- time_date: "));
  USB.println(time_date);
  Utils.writeEEPROM(c_address, counter);
  
//RTC.setAlarm2(0,0,1, RTC_OFFSET, RTC_ALM2_MODE4 ); // 1 minute from now
}

void loop()

  USB.println(F("enter deep sleep"));
  PWR.deepSleep(sleepTime, RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
  
  counter = Utils.readEEPROM(c_address);
  counter = counter + 1;
  Utils.writeEEPROM(c_address, counter);
  
  USB.ON();
  delay(100);
  RTC.ON();
  delay(100);
  USB.println(F("Waspmote wakes up!!"));
  USB.print(F("Time: "));
  USB.println(RTC.getTime());
  
  
  if( intFlag & RTC_INT )
  {
  // clear interruption flag
  intFlag &= ~(RTC_INT);
  
    if (counter == 3) // send battery frame after 3 counts; in future change to once per day
    {
      //sx1272.setRTCfromMeshlium();
      USB.println(F("+++ BATTERY PERCENTAGE triggered +++\n\n"));
      sendBatteryFrame();
      Utils.blinkLEDs(300);
      delay(100);
      counter = 0;
      Utils.writeEEPROM(c_address, counter);
      
      //clearIntFlag();
      //PWR.clearInterruptionPin();
      //RTC.setAlarm2(0,0,1, RTC_OFFSET, RTC_ALM2_MODE4 ); // 1 minute from now
    }
  
  delay(100);
  Utils.blinkLEDs(300);
  Utils.blinkLEDs(300);
  
  SensorParking.ON();
  delay(100);

  temperature = SensorParking.readTemperature();
  // Read the sensors
  SensorParking.readParkingSetReset();
  // Print the current values
  USB.print("Values: ");
  USB.print(F("X-Field: "));
  USB.print(SensorParking.valueX);
  USB.print(F(" Y-Field: "));
  USB.print(SensorParking.valueY);
  USB.print(F(" Z-Field: "));
  USB.println(SensorParking.valueZ);
  
  SensorParking.calculateReference(temperature);
  status = SensorParking.estimateState();
  USB.println(status, DEC);
  SensorParking.OFF();

  if(status == PARKING_OCCUPIED)
  {
    USB.println("OCCUPIED");
  } else
  {
    USB.println("EMPTY");
  }
  
  auxStatus = Utils.readEEPROM(ps_address);
  Utils.writeEEPROM(ps_address, status);
  
  USB.print(F(" -- auxStatus: "));
  USB.println(auxStatus,DEC);
  USB.print(F(" -- status: "));
  USB.println(status,DEC);
  
  if (auxStatus == status) {
    USB.println("NO UPDATES");

  } else {
    sendParkingFrame(status);
  }
  
  //auxStatus = Utils.readEEPROM(ps_address);
  
  //USB.println(F("enter deep sleep"));
  //PWR.deepSleep(sleepTime, RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
  }  
}

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Error in sendPacketTimeoutACK

Post by libelium-dev » Mon Mar 18, 2019 10:43 am

Hi,

The configuration seems correct. Maybe you can try to use another antennas with higher power.

Regards

marioemanuel
Posts: 16
Joined: Tue May 30, 2017 5:51 pm

Re: Error in sendPacketTimeoutACK

Post by marioemanuel » Thu Mar 21, 2019 11:38 am

Hi.

Thank you for your analysis.
Are you talking about meshlium antennas or waspmote antennas?

Regards,
Mário LOpes

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Error in sendPacketTimeoutACK

Post by libelium-dev » Tue Mar 26, 2019 11:00 am

Hi,

Apologies for the delayed answer.

We are talking about both antennas.

Regards

marioemanuel
Posts: 16
Joined: Tue May 30, 2017 5:51 pm

Re: Error in sendPacketTimeoutACK

Post by marioemanuel » Tue Apr 02, 2019 10:52 am

Hi,

Ok, thank you for your advice.

One more thing, I would like to change the email address of my libelium forum account. I already tried on the account page and I also sent emails using the "Contact us" link on the end of this webpage but I didn't receive a answer. Can you please provide me a way to change the email address?

Regards,
Mário Lopes

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Error in sendPacketTimeoutACK

Post by libelium-dev » Wed Apr 03, 2019 8:50 am

Hi Mario,

It isn't possible to change the email by yourself but we can change it through our settings. What email do you want to set?

Regards

marioemanuel
Posts: 16
Joined: Tue May 30, 2017 5:51 pm

Re: Error in sendPacketTimeoutACK

Post by marioemanuel » Wed Apr 03, 2019 10:16 am

Hi,

Can you open a private channel? In order to get some data privacy I don't want to post the email here.

Regards,
Mário Lopes

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Error in sendPacketTimeoutACK

Post by libelium-dev » Thu Apr 04, 2019 8:48 am

Hi,

You can fill the RMA form indicating the new email you want to configure and we will change it.
https://www.libelium.com/contact/#rma

Regards

marioemanuel
Posts: 16
Joined: Tue May 30, 2017 5:51 pm

Re: Error in sendPacketTimeoutACK

Post by marioemanuel » Thu Apr 04, 2019 2:27 pm

Hi,

Ok, thank you.

Regards,
Mário Lopes

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Error in sendPacketTimeoutACK

Post by libelium-dev » Fri Apr 05, 2019 8:57 am

Our colleagues changed the email yesterday.
Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest