EagleIO date stamp incorrect

Questions about the Waspmote v15 and its modules
Post Reply
ccreevey
Posts: 4
Joined: Tue Oct 01, 2019 11:28 am
Company: CM Manufacturing

EagleIO date stamp incorrect

Post by ccreevey » Tue Dec 03, 2019 9:27 am

Hello,

I have just activated my EagleIO trial account, and having issues with the time of the date when received by EagleIO being shown as 2019-01-04 and currently 2019-12-03. I have contacted eagle and this is the response I got:

"Thanks, it doesn't look like there are any errors acquiring the data, as the Events view shows that we are receiving a data record about every 5 minutes. The timestamp of each record comes from the device, so it's possible that this device needs it's clock adjusted."

I currently set up the RTC by the 4G provider, in setup and before each read.

I have attached my code and the output.

Code: Select all

/*  
 *  ------ FRAME_01_ascii_simple - WaspFrame Ascii simple -------- 
 *  
 *  Explanation: This example Creates a simple ASCII frame and shows it. 
 *  
 *  Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details. 
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           3.0
 *  Design:            David Gascón 
 *  Implementation:    Joaquín Ruiz, Yuri Carmona
 */ 
 #include <Wasp4G.h>
#include <WaspFrame.h>
#include <ModbusMaster.h>
  
// define the Waspmote ID 
char moteID[] = "6146157911";

// Instantiate ModbusMaster object as slave ID 1
ModbusMaster rs485Address1(RS485_COM, 1); 

// Define addresses for reading
#define rs4851Register1 0
#define rs4851Register2 1

// Define the number of bits to read
#define bytesQty 1

// define file name: MUST be 8.3 SHORT FILE NAME
char* filename="0212.TXT";

// define variable
uint8_t sd_answer;

// APN settings
///////////////////////////////////////
char apn[] = "mdata.net.au";
char login[] = "";
char password[] = "";
///////////////////////////////////////

// SERVER settings
///////////////////////////////////////
char host[] = "device.eagle.io";  //"webtcp.tongxinmao.com";  
uint16_t remote_port = 5566;
///////////////////////////////////////

// define Socket ID (from 'CONNECTION_1' to 'CONNECTION_6')
///////////////////////////////////////
uint8_t connId = Wasp4G::CONNECTION_1;
///////////////////////////////////////

// define data to send through TCP socket
///////////////////////////////////////
char http_format[] =
  "CM Manufacturing"\
  "Host: test.libelium.com\r\n"\
  "Content-Length: 0\r\n\r\n";
///////////////////////////////////////

// define variables
uint8_t  error;
uint32_t previous;
uint8_t  socketIndex;
char data[1000];
uint8_t connection_status;
char operator_name[20];

void setup()
{
  // Init USB port & RTC
  USB.ON();
  USB.println(F("Start program"));
/*
unsigned long epoch;
epoch = RTC.getEpochTime();
 USB.println(F(epoch));
  */
  RTC.setTime("19:12:02:01:20:28:00");
  // set the Waspmote ID
  frame.setID(moteID);  

SD.ON();
  // Create file
  sd_answer = SD.create(filename);

  if( sd_answer == 1 )
  {
    USB.println(F("file created"));
  }
  else 
  {
    USB.println(F("file NOT created")); 
  } 
  SD.OFF();
  
// Powers on the module and assigns the SPI in socket0
  if ( W485.ON() == 0) {
     USB.println(F("RS-485 module started successfully"));
  } else {
     USB.println(F("RS-485 did not initialize correctly"));
  }
  delay(100);


  // Configure the baud rate of the module
 // W485.baudRateConfig(9600);
  // Configure the parity bit as disabled 
  W485.parityBit(DISABLE);
  // Use one stop bit configuration 
  W485.stopBitConfig(1);  
  /*
  // Initialize Modbus communication baud rate
  rs485Address1.begin(9600);
  rs485Address2.begin(9600);
  rs485Address3.begin(9600);
  */
  W485.OFF();
  //////////////////////////////////////////////////
  // 1. sets operator parameters
  //////////////////////////////////////////////////
  _4G.set_APN(apn);//, login, password);


  //////////////////////////////////////////////////
  // 2. Show APN settings via USB port
  //////////////////////////////////////////////////
  _4G.show_APN();

  //////////////////////////////////////////////////
  // 1. Switch ON
  //////////////////////////////////////////////////
  error = _4G.ON();

  if (error == 0)
  {
    USB.println(F("1. 4G module ready..."));

    ////////////////////////////////////////////////
    // Enter PIN code
    ////////////////////////////////////////////////

    /*
      USB.println(F("Enter PIN code..."));
      if (_4G.enterPIN("****") == 1)
      {
      USB.println(F("PIN code accepted"));
      }
      else
      {
      USB.println(F("PIN code incorrect"));
      }
    */
////////////////////////////////////////////////
    // 1.1. Check connection to network and continue
    ////////////////////////////////////////////////
    connection_status = _4G.checkDataConnection(60);
    
    if (connection_status == 0)
    {
      _4G.setTimeFrom4G();
      USB.println(RTC.getTime());
      USB.println(RTC.getTimestamp());
    }
  }
  else
  {
    // Problem with the communication with the 4G module
    USB.println(F("1. 4G module not started"));
  }

  ////////////////////////////////////////////////
  // 3. Powers off the 4G module
  ////////////////////////////////////////////////
  USB.println(F("3. Switch OFF 4G module"));
  _4G.OFF();

}

void loop()
{
  


  //////////////////////////////////////////////////
  // 1. Switch ON
  //////////////////////////////////////////////////
  error = _4G.ON();

  if (error == 0)
  {
    USB.println(F("1. 4G module ready..."));

    ////////////////////////////////////////////////
    // Enter PIN code
    ////////////////////////////////////////////////

    /*
      USB.println(F("Enter PIN code..."));
      if (_4G.enterPIN("****") == 1)
      {
      USB.println(F("PIN code accepted"));
      }
      else
      {
      USB.println(F("PIN code incorrect"));
      }
    */
////////////////////////////////////////////////
    // 1.1. Check connection to network and continue
    ////////////////////////////////////////////////
    connection_status = _4G.checkDataConnection(60);
    
    if (connection_status == 0)
    {
      _4G.setTimeFrom4G();
      USB.println(RTC.getTime());
      USB.println(RTC.getTimestamp());
    }
    ////////////////////////////////////////////////
    // 2. TCP socket
    ////////////////////////////////////////////////

    error = _4G.openSocketClient(connId, Wasp4G::TCP, host, remote_port);

    if (error == 0)
    {
      USB.println(F("2.1. Opening a socket... done!"));

      USB.print(F("IP address:"));
      USB.println(_4G._ip);
 
      //////////////////////////////////////////////
      // 2.2. Create a frame and data to send via HTTP request
      //////////////////////////////////////////////

      RTC.ON();
      RTC.getTime();
// Powers on the module and assigns the SPI in socket0
  if ( W485.ON() == 0) {
     USB.println(F("RS-485 module started successfully"));
  } else {
     USB.println(F("RS-485 did not initialize correctly"));
  }
  delay(100);
  // Initialize Modbus communication baud rate
  rs485Address1.begin(9600);
  frame.createFrame(ASCII);
  USB.println(F("YOU CAN SEE THIS"));
  frame.addSensor(SENSOR_DATE, RTC.year, RTC.month, RTC.date);
  frame.addSensor(SENSOR_TIME, RTC.hour,RTC.minute,RTC.second);
  // *****************************************************************************************
//              Reading from the temperature sensor 
// *****************************************************************************************

  // This variable will store the result of the communication
  // result = 0 : no errors
  // result = 1 : error occurred 
  int result = rs485Address1.readHoldingRegisters(rs4851Register1 , bytesQty);

  if (result != 0) 
  {
    // If no response from the slave, print an error message
    USB.println(F("Communication error. Couldn't read from temperature sensor"));
    delay(100);
  } 
  else 
  { 
    // If all ok 
    USB.println(F("Temperature read from slave ID 1: "));

    // Print the read data from the slave 
    USB.println(rs485Address1.getResponseBuffer(0));
    delay(100);
  }

  USB.println(F("\n"));
  delay(1000);
//////////////////////////////////////
 // frame.addSensor(SENSOR_AGR_SOIL1, rs485Address1.getResponseBuffer(0));
  float soilTemp =rs485Address1.getResponseBuffer(0);
  soilTemp=soilTemp /10;
 frame.addSensor(SENSOR_AGR_SOIL1, soilTemp);
  // add rs485 input 2

// *****************************************************************************************
//              Reading from the soil humidity sensor          
// *****************************************************************************************

  // result = 0 : no errors
  // result = 1 : error occurred 
  
   result = rs485Address1.readHoldingRegisters(rs4851Register2 , bytesQty);

  if (result != 0)
  {
    // If no response from the slave, print an error message. 
    USB.println(F("Communication error. Couldn't read from the soil humidity sensor"));
    delay(100);
  } 
  else { 
    // If all ok. 
    USB.println(F("Soil Humidity data read from slave ID 2: "));

    // Print the read data from the slave 
    USB.println(rs485Address1.getResponseBuffer(0));
    delay(100);
 }

  USB.println(F("\n"));
  delay(1000);
  /////////////////////////////
  
//frame.addSensor(SENSOR_AGR_SOIL2, rs485Address1.getResponseBuffer(0));
float soilMoist = rs485Address1.getResponseBuffer(0);
soilMoist= soilMoist/10;
  frame.addSensor(SENSOR_AGR_SOIL2, soilMoist);
// Add rs485 input 1 

 frame.showFrame();

W485.OFF();
  SD.OFF();
  SD.ON();



  // show file
 // SD.showFile(filename);
  delay(1000);


  // 2 - It appends “hello” at the end of the file
  sd_answer = SD.appendln(filename, frame.buffer, frame.length);

  if( sd_answer == 1 )
  {
    USB.println(F("ok"));
  }
  else 
  {
    USB.println(F("\n2 - append error"));
  }

  // show file
 // SD.showFile(filename);
  delay(1000);
  SD.OFF();


  // Wait 2 seconds
  delay(2000);
      
/*
  USB.println(F("Creating an ASCII frame"));

  // Create new frame (ASCII)
  frame.createFrame(ASCII); 
// set frame fields (Time from RTC)
     frame.addSensor(SENSOR_TIME,(uint8_t) RTC.hour, RTC.minute, RTC.second);
      // show frame contents
  // set frame fields (String - char*)
// frame.addSensor(SENSOR_STR,(uint8_t) "this_is_a_string");
  // set frame fields (Battery sensor - uint8_t)
  frame.addSensor(SENSOR_BAT,(uint8_t) PWR.getBatteryLevel());

  // Prints frame
  frame.showFrame();
  *///only cause added earlier on
  
  /*
  // define aux buffer
      char frame_string[frame.length*2 + 1];
      memset(frame_string, 0x00, sizeof(frame_string));

      // convert frame from bytes to ASCII representation
      Utils.hex2str((uint8_t*)frame.buffer, (char*)frame_string, frame.length);
*//*
      snprintf( data, sizeof(data),frame.buffer);// http_format, frame.buffer); //frame_string);
      USB.print(F("data to send:"));
      USB.println(data);
*/
      //////////////////////////////////////////////
      // 2.3. Send it through the connection
      //////////////////////////////////////////////

      // send TCP packet
  //    error = _4G.send(connId, data);
      error = _4G.send(connId, frame.buffer, frame.length);
      if (error == 0)
      {
        USB.println(F("2.3. Sending a frame... done!"));
      }
      else
      {
        USB.print(F("2.3. Error sending a frame. Code: "));
        USB.println(error, DEC);
      }
    }
 //////////////////////////////////////////////
    // 2.5. Close socket
    //////////////////////////////////////////////
    error = _4G.closeSocketClient(connId);

    if (error == 0)
    {
      USB.println(F("2.5. Socket closed OK"));
    }
    else
    {
      USB.print(F("2.5. Error closing socket. Error code: "));
      USB.println(error, DEC);
    }
  }
  else
  {
    // Problem with the communication with the 4G module
    USB.println(F("1. 4G module not started"));
  }

  ////////////////////////////////////////////////
  // 3. Powers off the 4G module
  ////////////////////////////////////////////////
  USB.println(F("3. Switch OFF 4G module"));
  _4G.OFF();


  ////////////////////////////////////////////////
  // 4. Sleep
  ////////////////////////////////////////////////
  USB.println(F("4. Enter deep sleep..."));
  PWR.deepSleep("00:00:05:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);

  USB.ON();
  USB.println(F("5. Wake up!!\n\n"));
  
  // Wait for five seconds
  delay(5000);
  
}

Code: Select all

J#
Start program
file NOT created
RS-485 module started successfully
*****************************
APN: mdata.net.au
LOGIN: 
PASSWORD: 
*****************************
[LE910] ==> ERROR CODE: operation not supported
1. 4G module ready...
[LE910] CREG: 0,2
[LE910] CREG: 0,1
[LE910] CGREG: 0,1
[LE910] GPRS context activation:1
[LE910] IP address:10.68.58.98
[LE910] Network time:year: 19 | month: 12 | day: 3
hour: 18 | minute: 13 | second: 26 | timezone: 40
RTC time before: Sun, 19/12/02, 20:28:15
RTC time after: Tue, 19/12/03, 18:13:26
Tue, 19/12/03, 18:13:26
Tue, 19/12/03, 18:13:26
3. Switch OFF 4G module
[LE910] ==> ERROR CODE: operation not supported
1. 4G module ready...
[LE910] CREG: 0,2
[LE910] CREG: 0,1
[LE910] CGREG: 0,1
[LE910] GPRS context activation:1
[LE910] IP address:10.68.88.120
[LE910] Network time:year: 19 | month: 12 | day: 3
hour: 18 | minute: 13 | second: 49 | timezone: 40
RTC time before: Tue, 19/12/03, 18:13:48
RTC time after: Tue, 19/12/03, 18:13:49
Tue, 19/12/03, 18:13:49
Tue, 19/12/03, 18:13:49
[LE910] Connection active, nothing more to check
[LE910] _buffer:
#SS: 1,0

OK
[LE910] socketStatus.id:1
[LE910] socketStatus.state:0
[LE910] Configuring connection
[LE910] Opening the socket
[LE910] _buffer:
#SS: 1,6,10.68.88.120,0,0.0.0.0,0

OK
[LE910] socketStatus.id:1
[LE910] socketStatus.state:6
[LE910] socketStatus.localIp:10.68.88.120
[LE910] socketStatus.localPort:0
[LE910] socketStatus.remoteIp:0.0.0.0
[LE910] socketStatus.remotePort:0
[LE910] _buffer:
#SS: 1,2,10.68.88.120,1901,54.252.235.152,5566

OK
[LE910] socketStatus.id:1
[LE910] socketStatus.state:2
[LE910] socketStatus.localIp:10.68.88.120
[LE910] socketStatus.localPort:1901
[LE910] socketStatus.remoteIp:54.252.235.152
[LE910] socketStatus.remotePort:5566
2.1. Opening a socket... done!
IP address:10.68.88.120
RS-485 module started successfully
YOU CAN SEE THIS
Temperature read from slave ID 1: 
317


Soil Humidity data read from slave ID 2: 
12


===============================
Current ASCII Frame:
Length: 86
Frame Type:  134
frame (HEX): 3C3D3E860423343635443743333243383931334542432336313436313537393131233023444154453A31392D31322D332354494D453A31382D31332D353123534F494C313A33312E373023534F494C323A312E323023
frame (STR): <=>†#465D7C32C8913EBC#6146157911#0#DATE:19-12-3#TIME:18-13-51#SOIL1:31.70#SOIL2:1.20#
===============================
ok
[LE910] _buffer:
#SS: 1,2,10.68.88.120,1901,54.252.235.152,5566

OK
[LE910] socketStatus.id:1
[LE910] socketStatus.state:2
[LE910] socketStatus.localIp:10.68.88.120
[LE910] socketStatus.localPort:1901
[LE910] socketStatus.remoteIp:54.252.235.152
[LE910] socketStatus.remotePort:5566
[LE910] _buffer:
#SS: 1,2,10.68.88.120,1901,54.252.235.152,5566

OK
[LE910] socketStatus.id:1
[LE910] socketStatus.state:2
[LE910] socketStatus.localIp:10.68.88.120
[LE910] socketStatus.localPort:1901
[LE910] socketStatus.remoteIp:54.252.235.152
[LE910] socketStatus.remotePort:5566
[LE910] Data sent
2.3. Sending a frame... done!
[LE910] _buffer:
#SS: 1,2,10.68.88.120,1901,54.252.235.152,5566

OK
[LE910] socketStatus.id:1
[LE910] socketStatus.state:2
[LE910] socketStatus.localIp:10.68.88.120
[LE910] socketStatus.localPort:1901
[LE910] socketStatus.remoteIp:54.252.235.152
[LE910] socketStatus.remotePort:5566
[LE910] _buffer:
#SS: 1,0

OK
[LE910] socketStatus.id:1
[LE910] socketStatus.state:0
[LE910] Socket closed
2.5. Socket closed OK
3. Switch OFF 4G module
4. Enter deep sleep...
the normal strings I was receiving was as follows through a TCP program on my computer :

<=>†#546067057C105404#node_01#206#DATE:19-12-2#TIME:0-1-55#SOIL1:29.30#SOIL2:1.00#

Any ideas on what could cause this? Also waiting for EagleIO to send me what they were receiving, if they can.

Thanks

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

Re: EagleIO date stamp incorrect

Post by libelium-dev » Tue Dec 03, 2019 2:37 pm

Hi,

The showFrame function shows that the frame is created with the correct timestamp
<=>†#465D7C32C8913EBC#6146157911#0#DATE:19-12-3#TIME:18-13-51#SOIL1:31.70#SOIL2:1.20#
Anyway, we recommend to send it in hexadecimal format due to weird characters, like "†" in the above frame, can cause a weird analysis.

We don't know how Eagle is expecting to receive data. Please ask them if the format is correct.

Regards

ccreevey
Posts: 4
Joined: Tue Oct 01, 2019 11:28 am
Company: CM Manufacturing

Re: EagleIO date stamp incorrect

Post by ccreevey » Wed Dec 04, 2019 5:06 am

So the hex after the <=> is 86 04, is that correct for that type of frame?

ccreevey
Posts: 4
Joined: Tue Oct 01, 2019 11:28 am
Company: CM Manufacturing

Re: EagleIO date stamp incorrect

Post by ccreevey » Wed Dec 04, 2019 5:08 am

ccreevey wrote:
Wed Dec 04, 2019 5:06 am
So the hex after the <=> is 86 04, is that correct for that type of frame?
They believe that the date is in the wrong format, as mine is in single digit where they are set up for double digit dates. Any ideas how to fix that?

ccreevey
Posts: 4
Joined: Tue Oct 01, 2019 11:28 am
Company: CM Manufacturing

Re: EagleIO date stamp incorrect

Post by ccreevey » Wed Dec 04, 2019 10:33 am

Sorted used the following string call to get the date and time correct on EagleIO

frame.addSensor(SENSOR_STR,RTC.getTimestamp());

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

Re: EagleIO date stamp incorrect

Post by libelium-dev » Wed Dec 04, 2019 10:59 am

Hi,

Yes, those two bytes are correct. They mean that it is an ASCII information frame and it contains 4 fields.

Please try to set a date and time with double digit and let us know if the data is received with the correct format. If so you will need to modify the addFrame function to avoid that problem. Try to set the following timestamp before adding the timestamp to the frame and check if the frame is received with that timestamp

Code: Select all

RTC.setTime("19:12:10:06:12:33:10");
Regards

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

Re: EagleIO date stamp incorrect

Post by libelium-dev » Wed Dec 04, 2019 11:00 am

Hi,

We haven't seen your last post. Glad to hear that you solved the problem! :D

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest