@enyo-energy/sunspec-sdk 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -79,7 +79,7 @@ export interface SunspecInverterData extends SunspecBlock {
79
79
  apparentPower?: number;
80
80
  reactivePower?: number;
81
81
  powerFactor?: number;
82
- acEnergy?: bigint;
82
+ acEnergy?: number;
83
83
  dcCurrent?: number;
84
84
  dcVoltage?: number;
85
85
  dcPower?: number;
@@ -109,7 +109,7 @@ export interface SunspecMPPTData extends SunspecBlock {
109
109
  dcVoltageSF?: number;
110
110
  dcPower?: number;
111
111
  dcPowerSF?: number;
112
- dcEnergy?: bigint;
112
+ dcEnergy?: number;
113
113
  dcEnergySF?: number;
114
114
  timestamp?: number;
115
115
  temperature?: number;
@@ -141,9 +141,9 @@ export interface SunspecMeterData extends SunspecBlock {
141
141
  phaseAPower?: number;
142
142
  phaseBPower?: number;
143
143
  phaseCPower?: number;
144
- totalEnergy?: bigint;
145
- exportedEnergy?: bigint;
146
- importedEnergy?: bigint;
144
+ totalEnergy?: number;
145
+ exportedEnergy?: number;
146
+ importedEnergy?: number;
147
147
  voltage?: number;
148
148
  current?: number;
149
149
  frequency?: number;
@@ -371,16 +371,15 @@ class SunspecModbusClient {
371
371
  const acEnergyAddr = baseAddr + 24;
372
372
  const acEnergy = await this.readRegisterValue(acEnergyAddr, 2, 'acc32');
373
373
  console.log(`AC Energy: address=${acEnergyAddr}, raw=0x${acEnergy.toString(16).toUpperCase()} (${acEnergy}), SF=${scaleFactors.WH_SF}`);
374
- data.acEnergy = BigInt(acEnergy) * BigInt(Math.pow(10, scaleFactors.WH_SF));
374
+ data.acEnergy = !this.isUnimplementedValue(acEnergy, 'uint32')
375
+ ? acEnergy * Math.pow(10, scaleFactors.WH_SF) // Regular number with scale factor
376
+ : undefined;
375
377
  // Log final calculated values
376
378
  console.log('Inverter Final Values:', {
377
379
  acPower: data.acPower,
378
- dcPower: data.dcPower,
379
380
  voltageAN: data.voltageAN,
380
381
  voltageBN: data.voltageBN,
381
382
  voltageCN: data.voltageCN,
382
- dcVoltage: data.dcVoltage,
383
- dcCurrent: data.dcCurrent,
384
383
  acCurrent: data.acCurrent
385
384
  });
386
385
  return data;
@@ -548,7 +547,7 @@ class SunspecModbusClient {
548
547
  // DC Energy - Offset 15-16 (32-bit accumulator)
549
548
  // Only calculate if value is not unimplemented
550
549
  dcEnergy: !this.isUnimplementedValue(dcEnergyRaw, 'uint32')
551
- ? BigInt(dcEnergyRaw) * BigInt(Math.pow(10, scaleFactors.DCWH_SF))
550
+ ? dcEnergyRaw * Math.pow(10, scaleFactors.DCWH_SF) // Regular number with scale factor
552
551
  : undefined,
553
552
  dcEnergySF: scaleFactors.DCWH_SF,
554
553
  // Timestamp - Offset 18-19 (32-bit)
@@ -612,17 +611,17 @@ class SunspecModbusClient {
612
611
  const baseAddr = model.address + 2;
613
612
  console.log(`Reading Meter Data from Model ${model.id} at base address: ${baseAddr}`);
614
613
  try {
615
- // Model 201 (single phase) and 203 (3-phase) have different offsets
616
- // Model 201: Power at offset 12, Frequency at offset 18
617
- // Model 203: Power at offset 14, Frequency at offset 24
618
- const isPowerMeter201 = model.id === 201;
619
- const powerOffset = isPowerMeter201 ? 12 : 14; // Total Real Power offset
620
- const powerSFOffset = isPowerMeter201 ? 15 : 17; // Power scale factor offset
621
- const freqOffset = isPowerMeter201 ? 18 : 24; // Frequency offset
622
- const freqSFOffset = isPowerMeter201 ? 21 : 27; // Frequency scale factor offset
623
- const exportOffset = isPowerMeter201 ? 32 : 38; // Total Wh Exported offset
624
- const importOffset = isPowerMeter201 ? 40 : 46; // Total Wh Imported offset
625
- const energySFOffset = 4; // Energy scale factor is typically at offset 4
614
+ // Model 201 (single phase meter) - Correct register offsets from Sunspec
615
+ // All offsets are from data start (after ID and Length)
616
+ console.log(`Meter is Model 201 (Single Phase Meter)`);
617
+ // Model 201 register offsets according to Sunspec specification:
618
+ const powerOffset = 18; // W - Total Real Power (int16) at offset 18
619
+ const powerSFOffset = 21; // W_SF - Power scale factor at offset 21
620
+ const freqOffset = 32; // Hz - Frequency (uint16) at offset 32
621
+ const freqSFOffset = 35; // Hz_SF - Frequency scale factor at offset 35
622
+ const exportOffset = 38; // TotWhExp - Total Wh Exported (acc32) at offset 38-39
623
+ const importOffset = 46; // TotWhImp - Total Wh Imported (acc32) at offset 46-47
624
+ const energySFOffset = 4; // TotWh_SF - Total Energy scale factor at offset 4
626
625
  // Read scale factors
627
626
  const powerSF = await this.readRegisterValue(baseAddr + powerSFOffset, 1, 'int16');
628
627
  const freqSF = await this.readRegisterValue(baseAddr + freqSFOffset, 1, 'int16');
@@ -641,16 +640,27 @@ class SunspecModbusClient {
641
640
  const importAddr = baseAddr + importOffset;
642
641
  const importRaw = await this.readRegisterValue(importAddr, 2, 'acc32');
643
642
  console.log(`Meter Import Energy: address=${importAddr}, raw=0x${importRaw.toString(16).toUpperCase()} (${importRaw}), SF=${energySF}`);
643
+ // Calculate final values with scale factors
644
+ const totalPower = this.applyScaleFactor(powerRaw, powerSF, 'int16');
645
+ const frequency = this.applyScaleFactor(freqRaw, freqSF);
646
+ const exportedEnergy = !this.isUnimplementedValue(exportRaw, 'uint32')
647
+ ? exportRaw * Math.pow(10, energySF) // Regular number, not BigInt
648
+ : undefined;
649
+ const importedEnergy = !this.isUnimplementedValue(importRaw, 'uint32')
650
+ ? importRaw * Math.pow(10, energySF) // Regular number, not BigInt
651
+ : undefined;
652
+ console.log('Meter Final Values:', {
653
+ totalPower,
654
+ frequency,
655
+ exportedEnergy,
656
+ importedEnergy
657
+ });
644
658
  return {
645
659
  blockNumber: model.id,
646
- totalPower: this.applyScaleFactor(powerRaw, powerSF, 'int16'),
647
- frequency: this.applyScaleFactor(freqRaw, freqSF),
648
- exportedEnergy: !this.isUnimplementedValue(exportRaw, 'uint32')
649
- ? BigInt(exportRaw) * BigInt(Math.pow(10, energySF))
650
- : undefined,
651
- importedEnergy: !this.isUnimplementedValue(importRaw, 'uint32')
652
- ? BigInt(importRaw) * BigInt(Math.pow(10, energySF))
653
- : undefined
660
+ totalPower,
661
+ frequency,
662
+ exportedEnergy,
663
+ importedEnergy
654
664
  };
655
665
  }
656
666
  catch (error) {
@@ -9,7 +9,7 @@ exports.getSdkVersion = getSdkVersion;
9
9
  /**
10
10
  * Current version of the enyo Energy App SDK.
11
11
  */
12
- exports.SDK_VERSION = '0.0.7';
12
+ exports.SDK_VERSION = '0.0.8';
13
13
  /**
14
14
  * Gets the current SDK version.
15
15
  * @returns The semantic version string of the SDK
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Current version of the enyo Energy App SDK.
7
7
  */
8
- export declare const SDK_VERSION = "0.0.7";
8
+ export declare const SDK_VERSION = "0.0.8";
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
@@ -79,7 +79,7 @@ export interface SunspecInverterData extends SunspecBlock {
79
79
  apparentPower?: number;
80
80
  reactivePower?: number;
81
81
  powerFactor?: number;
82
- acEnergy?: bigint;
82
+ acEnergy?: number;
83
83
  dcCurrent?: number;
84
84
  dcVoltage?: number;
85
85
  dcPower?: number;
@@ -109,7 +109,7 @@ export interface SunspecMPPTData extends SunspecBlock {
109
109
  dcVoltageSF?: number;
110
110
  dcPower?: number;
111
111
  dcPowerSF?: number;
112
- dcEnergy?: bigint;
112
+ dcEnergy?: number;
113
113
  dcEnergySF?: number;
114
114
  timestamp?: number;
115
115
  temperature?: number;
@@ -141,9 +141,9 @@ export interface SunspecMeterData extends SunspecBlock {
141
141
  phaseAPower?: number;
142
142
  phaseBPower?: number;
143
143
  phaseCPower?: number;
144
- totalEnergy?: bigint;
145
- exportedEnergy?: bigint;
146
- importedEnergy?: bigint;
144
+ totalEnergy?: number;
145
+ exportedEnergy?: number;
146
+ importedEnergy?: number;
147
147
  voltage?: number;
148
148
  current?: number;
149
149
  frequency?: number;
@@ -368,16 +368,15 @@ export class SunspecModbusClient {
368
368
  const acEnergyAddr = baseAddr + 24;
369
369
  const acEnergy = await this.readRegisterValue(acEnergyAddr, 2, 'acc32');
370
370
  console.log(`AC Energy: address=${acEnergyAddr}, raw=0x${acEnergy.toString(16).toUpperCase()} (${acEnergy}), SF=${scaleFactors.WH_SF}`);
371
- data.acEnergy = BigInt(acEnergy) * BigInt(Math.pow(10, scaleFactors.WH_SF));
371
+ data.acEnergy = !this.isUnimplementedValue(acEnergy, 'uint32')
372
+ ? acEnergy * Math.pow(10, scaleFactors.WH_SF) // Regular number with scale factor
373
+ : undefined;
372
374
  // Log final calculated values
373
375
  console.log('Inverter Final Values:', {
374
376
  acPower: data.acPower,
375
- dcPower: data.dcPower,
376
377
  voltageAN: data.voltageAN,
377
378
  voltageBN: data.voltageBN,
378
379
  voltageCN: data.voltageCN,
379
- dcVoltage: data.dcVoltage,
380
- dcCurrent: data.dcCurrent,
381
380
  acCurrent: data.acCurrent
382
381
  });
383
382
  return data;
@@ -545,7 +544,7 @@ export class SunspecModbusClient {
545
544
  // DC Energy - Offset 15-16 (32-bit accumulator)
546
545
  // Only calculate if value is not unimplemented
547
546
  dcEnergy: !this.isUnimplementedValue(dcEnergyRaw, 'uint32')
548
- ? BigInt(dcEnergyRaw) * BigInt(Math.pow(10, scaleFactors.DCWH_SF))
547
+ ? dcEnergyRaw * Math.pow(10, scaleFactors.DCWH_SF) // Regular number with scale factor
549
548
  : undefined,
550
549
  dcEnergySF: scaleFactors.DCWH_SF,
551
550
  // Timestamp - Offset 18-19 (32-bit)
@@ -609,17 +608,17 @@ export class SunspecModbusClient {
609
608
  const baseAddr = model.address + 2;
610
609
  console.log(`Reading Meter Data from Model ${model.id} at base address: ${baseAddr}`);
611
610
  try {
612
- // Model 201 (single phase) and 203 (3-phase) have different offsets
613
- // Model 201: Power at offset 12, Frequency at offset 18
614
- // Model 203: Power at offset 14, Frequency at offset 24
615
- const isPowerMeter201 = model.id === 201;
616
- const powerOffset = isPowerMeter201 ? 12 : 14; // Total Real Power offset
617
- const powerSFOffset = isPowerMeter201 ? 15 : 17; // Power scale factor offset
618
- const freqOffset = isPowerMeter201 ? 18 : 24; // Frequency offset
619
- const freqSFOffset = isPowerMeter201 ? 21 : 27; // Frequency scale factor offset
620
- const exportOffset = isPowerMeter201 ? 32 : 38; // Total Wh Exported offset
621
- const importOffset = isPowerMeter201 ? 40 : 46; // Total Wh Imported offset
622
- const energySFOffset = 4; // Energy scale factor is typically at offset 4
611
+ // Model 201 (single phase meter) - Correct register offsets from Sunspec
612
+ // All offsets are from data start (after ID and Length)
613
+ console.log(`Meter is Model 201 (Single Phase Meter)`);
614
+ // Model 201 register offsets according to Sunspec specification:
615
+ const powerOffset = 18; // W - Total Real Power (int16) at offset 18
616
+ const powerSFOffset = 21; // W_SF - Power scale factor at offset 21
617
+ const freqOffset = 32; // Hz - Frequency (uint16) at offset 32
618
+ const freqSFOffset = 35; // Hz_SF - Frequency scale factor at offset 35
619
+ const exportOffset = 38; // TotWhExp - Total Wh Exported (acc32) at offset 38-39
620
+ const importOffset = 46; // TotWhImp - Total Wh Imported (acc32) at offset 46-47
621
+ const energySFOffset = 4; // TotWh_SF - Total Energy scale factor at offset 4
623
622
  // Read scale factors
624
623
  const powerSF = await this.readRegisterValue(baseAddr + powerSFOffset, 1, 'int16');
625
624
  const freqSF = await this.readRegisterValue(baseAddr + freqSFOffset, 1, 'int16');
@@ -638,16 +637,27 @@ export class SunspecModbusClient {
638
637
  const importAddr = baseAddr + importOffset;
639
638
  const importRaw = await this.readRegisterValue(importAddr, 2, 'acc32');
640
639
  console.log(`Meter Import Energy: address=${importAddr}, raw=0x${importRaw.toString(16).toUpperCase()} (${importRaw}), SF=${energySF}`);
640
+ // Calculate final values with scale factors
641
+ const totalPower = this.applyScaleFactor(powerRaw, powerSF, 'int16');
642
+ const frequency = this.applyScaleFactor(freqRaw, freqSF);
643
+ const exportedEnergy = !this.isUnimplementedValue(exportRaw, 'uint32')
644
+ ? exportRaw * Math.pow(10, energySF) // Regular number, not BigInt
645
+ : undefined;
646
+ const importedEnergy = !this.isUnimplementedValue(importRaw, 'uint32')
647
+ ? importRaw * Math.pow(10, energySF) // Regular number, not BigInt
648
+ : undefined;
649
+ console.log('Meter Final Values:', {
650
+ totalPower,
651
+ frequency,
652
+ exportedEnergy,
653
+ importedEnergy
654
+ });
641
655
  return {
642
656
  blockNumber: model.id,
643
- totalPower: this.applyScaleFactor(powerRaw, powerSF, 'int16'),
644
- frequency: this.applyScaleFactor(freqRaw, freqSF),
645
- exportedEnergy: !this.isUnimplementedValue(exportRaw, 'uint32')
646
- ? BigInt(exportRaw) * BigInt(Math.pow(10, energySF))
647
- : undefined,
648
- importedEnergy: !this.isUnimplementedValue(importRaw, 'uint32')
649
- ? BigInt(importRaw) * BigInt(Math.pow(10, energySF))
650
- : undefined
657
+ totalPower,
658
+ frequency,
659
+ exportedEnergy,
660
+ importedEnergy
651
661
  };
652
662
  }
653
663
  catch (error) {
package/dist/version.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Current version of the enyo Energy App SDK.
7
7
  */
8
- export declare const SDK_VERSION = "0.0.7";
8
+ export declare const SDK_VERSION = "0.0.8";
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
package/dist/version.js CHANGED
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Current version of the enyo Energy App SDK.
7
7
  */
8
- export const SDK_VERSION = '0.0.7';
8
+ export const SDK_VERSION = '0.0.8';
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enyo-energy/sunspec-sdk",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "enyo Energy Sunspec SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",