P1 smartmeter (API)

It’s likely fixable by changing the code of the script, but I haven’t taken a closer look at it to see where it might be leaking.

What i’m doing now (all other things commented out).

var P1Reader = require(’…/main’)

const fs = require(‘fs’)
const fetch = require(‘node-fetch’)

const homeyId = 'HOMEYID
const homeyEndpoint = ‘/update’
const homeyHost = ‘https://’ + homeyId + ‘.connect.athom.com/api/app/com.p1’ + homeyEndpoint
const config = {}

const p1Reader = new P1Reader(config)

p1Reader.on(‘connected’, portConfig => {
console.log(
'Connection with the Smart Meter has been established on port: ’ +
portConfig.port
+ ’ (BaudRate: ’ + portConfig.baudRate + ', Parity: ’ +
portConfig.parity + ', Databits: ’
+ portConfig.dataBits + 'Stopbits: ’ + portConfig.stopBits + ‘)’)
})

p1Reader.on(‘reading’, data => {
const requestJson = JSON.stringify(data)

fetch(homeyHost, {
    method: 'post',
    body: requestJson,
    headers: {'Content-Type': 'application/json'},
})

})

process.on(‘uncaughtException’, error => {
console.error(error)
})

Assuming that P1Reader is leak-free, try removing the call to fetch and see if that solves the memory leak.

Going to try later this day, thanks so far.

Allright, i’m now down to the bare bones as far as I can see.
var P1Reader = require(’…/main’)

const fs = require(‘fs’)
const fetch = require(‘node-fetch’)

const config = {}

const p1Reader = new P1Reader(config)

p1Reader.on(‘connected’, portConfig => {
console.log(
'Connection with the Smart Meter has been established on port: ’ +
portConfig.port
+ ’ (BaudRate: ’ + portConfig.baudRate + ', Parity: ’ +
portConfig.parity + ', Databits: ’
+ portConfig.dataBits + 'Stopbits: ’ + portConfig.stopBits + ‘)’)
})

Issue seems to be in P1Reader. Not easily fixable by me.

Could it also be the node.js memory management being to bad for a raspberry pi zero?
It only has 512 megs of memory…

Shouldn’t be a problem, a bare bones Node.js process takes up about 15 to 20MB at most. When you ran the bare bones test, how long until it started to run out of memory?

Appr half an hour after starting the script the pizero’s memory is filled.

Yeah, sounds like a memory leak :frowning:

Just tried installing domoticz, and installed the domoticz app in homey.
It’s an extra step but is working flawlessly.

Maybe i’ll try this later on, but for now I’m done.

Thanks for the replies!

I updated my app com.p1 for reading out your smartmeter. The app has an new implementation of the script that pushes the data to homey.

The push script is almost real-time and uses less CPU and mem (@RP3 mem: 4 MB CPU: 10% ). Due to incompatibility there is an new driver. The current one is deprecated and will be removed after some time.

The app in test: https://homey.app/a/com.p1/test/
The pusher script: https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader

You can try the new implementation, it use way less resources: https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader

You can try: https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader

I’ve fixed a bug in the pusher script. That will now work on the old driver now too.

Hi Koktail,

I’ve set up the DSMR Reader on a VM, works OK. I installed your app on my Homey, works also OK.
But when i add the smart meter, i see all the info, except current energy consumption. What can be wrong?

Thanks in advance.

I’ve just released v3.1.3 to tests

I’ve released v3.1.4 to tests. Is there any feedback?

Hi Koktail,
Thanks for your reply. I want to test the new version, but i cannot see the new version in the apps section of Homey. How can i test the new version?

Thanks!

You can find v3.1.4 here: https://homey.app/nl-nl/app/com.p1/P1-Slimme-meter/test/

Hi Koktail,
Thanks for your reply.
I installed the v3.1.4. test version, but there’s no difference in showing the actual power consumption. There is only a dash sign at the current consumption.

I rebooted the app on homey and i restarted the p1 script on the VM.

Can i test some more? i.e. Output on the VM or something else?

Did the value exist in the post you send?