Actions

WattNode Logger for LonWorks Programming Details

Contents

Overview

This article provides details about retrieving log data from the WattNode® Logger for LonWorks®. In most cases, we recommend using the LNS Plug-in for WattNode Logger to download log data. For special applications, you may wish to write your own download software using LNS® and the LonWorks protocol. This article provides details to help develop your own software.

We recommend reading the following for overview information:

We also recommend installing and trying the LNS Plug-in, so that you can compare your results against the data downloaded by the plug-in.

The WattNode Logger meter logs a complete set of measurements at the interval configured with nciLogMinutes. Using the LonTalk File Transfer Protocol (LFTP), it is then possible to download all records or some subset of records. You can also configure whether to download full (long) records or short records. The short records are much faster to download, but only include the record number, status, date/time, demand, and energy sum values.

LonTalk File Transfer Protocol (LFTP)

LFTP is a system developed to support transferring large blocks of data more efficiently than with SNVTs. For details on the LonTalk file transfer protocol, see the following:

Even with LFTP, transferring many records is slow. In our testing, we typically see the following speeds:

However, this is more than ten times faster than retrieving the same data using SNVTs.

LFTP uses three NVs (network variables) to configure and manage file transfers, while explicit messages are used for the actual data transfer.

Most LonWorks tools and APIs (like LNS) provide built-in LFTP support, so you won't generally need to manually manipulate these network variables or handle the explicit messages.

LFTP Files

The LonTalk file transfer protocol supports numbered files (0 to 65535) and uses a 32 bit file position value. The first three file handles (numbers) are reserved, while the next three are used to transfer WattNode meter log records.

LonWorks Reserved File Handles

WattNode Logger File Handles

3 - Log Information (Read Only)

// The following structure defines the log information file. This is used by Neuron C to keep
// track of the current and oldest record number, Flash addresses, etc. This is preserved
// across power failures.
// 
// Note: the FTP file for this is defined as 64 bytes long, but we don't have 64 bytes of 
// content. Rather than waste RAM, we'll make this smaller and just zero pad the file or end
// the file early.
typedef struct {
  int32 CurrentRecNum;      // The most recent logged record number.
  TLogAddr CurrentRecAddr;  // The flash address of the most recently logged record
  SNVT_time_stamp CurrentRecDateTime;  // The timestamp of the most recent log record
 
  int32 OldestRecNum;       // The oldest log record number in the serial flash
  TLogAddr OldestRecAddr;   // The flash address of the oldest logged record
  SNVT_time_stamp OldestRecDateTime;   // The timestamp of the oldest log record
 
  uint16 crc;               // Every time we update this structure, compute the CRC
  uint8 logInitialized;     // Must be set to LOG_INIT_VALUE when the log is initialized
} TLogInfo;

The above structure references the following structures:

// The TLogAddr structure is used to address locations in the serial flash 
// efficiently, since the flash uses a page/offset addressing scheme.
typedef struct {
  uint16 page;    // The page number ranges from 0..4095
  uint16 offset;  // The offset ranges from 0..527
} TLogAddr;
 
// This is the definition for the SNVT_time_stamp type, with the types
// modified to int16 and uint8.
typedef struct {
  int16 year;
  uint8 month;
  uint8 day;
  uint8 hour;
  uint8 minute;
  uint8 second;
} SNVT_time_stamp;

4 - Log Retrieval Setup (Read / Write)

The following structure is used to configure a log transfer. This structure has provisions for transfer modes that are not yet supported, so only certain fields are used. Set all reserved fields to zero when configuring a transfer.

// The following struct defines the log retrieval setup file
typedef struct {
  // Note: not all fields are used. We could overlap fields, but unions are tough in VB6
  // so it's easier and clearer to provide non-overlapping fields and waste some space.
                                  // Byte#: Description
  uint8 retrievalType;            //     0: 0 = full (start with oldest record, stop on newest), 
                                  //        1 = prior-n (start with newest record, read 'count' records), 
                                  //        2 = to-date (start with newest record, stop on stopDateTime or
                                  //          after seven older records (in case of out-of-order records), 
                                  //        5 = to-recNum (start with newest record, stop on stopRecNum or
                                  //          after seven older records (in case of out-of-order records), 
  int32 count;                    //  1- 4: count of records to transfer
 
  int32 reserved1;                //  5- 8: reserved
  TLogAddr reserved2;             //  9-12: reserved
  SNVT_time_stamp reserved3;      // 13-19: reserved
 
  int32 stopRecNum;               // 20-23: ending record number
  TLogAddr reserved4;             // 24-27: reserved
  SNVT_time_stamp stopDateTime;   // 28-34: ending date/time
 
  uint8 reserved5;                //    35: reserved
  int32 reserved6;                // 36-39: reserved
  uint8 compressMode;             //    40: 2 = full (all logged fields), 
                                  //        3 = basic (date, time, EnergySum, demand, status)
 
  // The following fields are used internally in the WattNode meter to track the progress 
  // of active transfer. They are initialized when the log data file is opened. They could
  // be read out after a transfer if desired, but not during a log transfer.
  uint8 supportedSetup;  // 1 = supported transfer setup? If not, return EOF immediately.
  uint8 direction;       // 0 = current first (backwards), 1 = oldest first (forward)
  uint16 countLeft;      // Count of records left to transfer
  uint8 transferDone;    // Set to TRUE to terminate transfer
  TLogAddr recAddr;      // The address of the record to transfer
  uint8 recPos;          // The position within the record being transferred
  int32 recNum;             // current log record number
  SNVT_time_stamp dateTime; // current log date/time
} TLogSetup;

5 - Log Data (Read Only)

The following structures show the long log record structure. The short record is just the first 24 bytes of the long log record.

typedef struct {             // Byte#: Description
  uint8 logType;             //     0: This value is always 1
  int32 recordNum;           //   1-4: Unique log record number (>4000 years to overflow)
  TLogStatus logStatus;      //     5: Status event logging
  SNVT_time_stamp dateTime;  //  6-12: Date/time for log record (from WattNode nviTimeSet)
  uint16 logSeconds;         // 13-14: Number of measured seconds in this log interval
  float32 demand;            // 15-18: Most recent nvoDemand value
  int32 energySum;           // 19-22: Energy with 0.1 kWh resolution
  int8 crcA;                 //    23: Eight bit CRC on the first 23 bytes
  // 24 bytes: End of the short log records, the following are added for long records
  int32 energyPosSum;        // 24-27: Positive energy (0.1 kWh resolution)
  int32 energy[3];           // 28-39: Energies for phase A, B, and C (0.1 kWh resolution)
  int32 reacEngySum;         // 40-43: Reactive energy sum (0.1 kVARh resolution)
  float32 volts[3];          // 44-55: Voltages for phase A, B, and C
  float32 freq;              // 56-59: Line frequency (Hz)
  float32 power[3];          // 60-71: Real powers for phase A, B, and C
  float32 reacPower[3];      // 72-83: Reactive powers for phase A, B, and C
  uint16 crcB;               // 84-85: 16 bit CRC on entire log record
  // 86 bytes total
} TNomLogRecord;
 
// This structure / variable is a bitfield used to track events. It is logged and cleared with
// each log record, and bits are set when events happen.
typedef union {
  uint8 status;                 // Byte containing all status bits
  struct {                // Neuron C stores these most significant bit first
    uint8 powerFail:1;          // This is the first log record after power up
    uint8 clockChange:1;        // The clock was changed by >= 15 seconds
    uint8 calibrationChange:1;  // The calibration was changed
    uint8 configChange:1;       // The configuration was changed: nciCtAmps, nciDemPerMins, 
                                //  nciDemSubints, nciLogMinutes, nciCreepLimit.
    uint8 nodeOnline:1;         // First log record since coming online
    uint8 internalError:1;      // An internal error occurred
    uint8 nodeReset:1;          // The WattNode was reset (not due to power-up).
    uint8 res2:1;               // Reserved
  } bits;
} TLogStatus;

Code Samples

We have included some sample Visual Basic 6 code from our LNS Plug-in showing the log transfer setup and download on the following page:

See Also

 

Call Us Toll Free
888-928-8663
888-WATTNODE
Voice: 303-444-7422
FAX: 303-444-2903
sales@ccontrolsys.com

Continental Control Systems
3131 Indian Rd. Suite A
Boulder, CO 80301
USA