utzl / MMM-Solarman

MIT License
2 stars 1 forks source link

Installation fails - MM2 doesn't start after configuration #4

Closed Stefan19630122 closed 10 months ago

Stefan19630122 commented 10 months ago

Hello, after installing and configuring MMM-Solarman, MM2 doesn't start. Running pm2 logs doesn't show any errors as well as config:check doesn't show any failures. I'm using MM2 version 20.8.0, npm version 10.1.0. The customer service of Solarman sent the API ID as well as the API Secret, which both I used to generate the accessToken as it was described on the main page of this module. I'd be happy for any hint of what could I try to do to get the module running. Thanks for your help, Stefan

utzl commented 10 months ago

Hi Stefan, I am sorry, but I have no idea what the problem could be. What you could do is to check if the connection to the solarman server works (without the MM). Try to run this code in node. I used it to build the module.

const fs = require("fs");
var request = require("request");
var result = null;

accessToken = "YOUR_ACCESS_TOKEN";                      // <-- INPUT HERE

var headers = {
    'Authorization': '',
    'Content-Type': 'application/json'
    };
headers['Authorization'] = 'bearer ' + accessToken;

let deviceSn = "YOUR_DEVICE_SN";                        // <-- INPUT HERE
var dataString = `{ "deviceSn": "${deviceSn}" }`;
//console.log('dataString:', dataString);

var options = {
    url: 'https://globalapi.solarmanpv.com/device/v1.0/currentData?appId=2022072735031760&language=en&=',
    method: 'POST',
    headers: headers,
    body: dataString
    };

async function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log('error:', error); // Print the error if one occurred
        console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received

        result = JSON.parse(body);
        console.log('result:', result);
        if (result.success) {
            console.log("successful data load!");

        }

        // print some results
        console.log("success?: ", result.success);
        console.log("msg: ", result.msg);
        console.log('deviceState:', result.deviceState);
        // LOOK for specific value with a search of the list
        for (let i = 0; i < result.dataList.length; i++){
            if (result.dataList[i].key == 'APo_t1'){
                var fetchedDataValue = result.dataList[i].value;
                console.log('AcPower:', fetchedDataValue);
            }
        }

    } else {
      console.log("MMM-Solarman: Could not load data.");
    }   
}

request(options, callback); 

But do not forget to insert your own accessToken and deviceSn :-)

best regards Kai

utzl commented 10 months ago

If the connection to Solarman is not the problem, it could be the configuration of the module. Honestly I have no idea how to do it or how to set up my module correctly. I just built it, copied it in the module directory and included the module in config.js. And this worked. So maybe unistallation and copy without npm install might work.

Stefan19630122 commented 10 months ago

Hi Kai, thanks a lot. Now, the module runs fine :-) At least, the error has been the missing module "request" which was not installed on my raspberry pi. Your code works perfect. best regards, Stefan