Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Error Reporting #140

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
"cSpell.words": [
"Buildx",
"CODACY",
"daynight",
"DEVICEID",
"enginerpm",
"eyeroll",
"getlocation",
"homeassistant",
"HOTSPOT",
"INTERM",
"kewr",
"lastpollsuccessful",
"lcov",
"MIDPEAK",
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ Supply these values to the ENV vars below. The default data refresh interval is

* **NEW - Manual diagnostic refresh command and manual engine RPM refresh command are working**

* **NEW - OnStar password/pin and MQTT password are masked by default in the console log output. To see these values in the console log output, set "--env LOG_LEVEL=debug"**

## Helpful Usage Notes

- The OnStar API has rate limiting, so they will block excessive requests over a short period of time.
- Reducing the polling timeout to less than 30 minutes/1800000 ms is likely to get you rate limited (Error 429).
- The OnStar API can be very temperamental, so you may see numerous errors every now and then where you cannot get any data from your vehicle. These tend to be very sporadic and usually go away on their own.
- A common example of this is: "Request Failed with status 504 - Gateway Timeout"
- After your engine is turned off, the vehicle will respond to about 4 - 5 requests before going into a type of hibernation mode and will not respond to requests or commands until the engine is started up again. If your engine has been off for a while, you may still not be able to get any data from the vehicle or run commands even if it is your first attempt at trying to pull data from your vehicle after the engine was turned off.
- **Note:** You will see an error of *"Unable to establish packet session to the vehicle"* when this occurs.
* The OnStar API has rate limiting, so they will block excessive requests over a short period of time.
* Reducing the polling timeout to less than 30 minutes/1800000 ms is likely to get you rate limited (Error 429).
* The OnStar API can be very temperamental, so you may see numerous errors every now and then where you cannot get any data from your vehicle. These tend to be very sporadic and usually go away on their own.
* A common example of this is: "Request Failed with status 504 - Gateway Timeout"
* After your engine is turned off, the vehicle will respond to about 4 - 5 requests before going into a type of hibernation mode and will not respond to requests or commands until the engine is started up again. If your engine has been off for a while, you may still not be able to get any data from the vehicle or run commands even if it is your first attempt at trying to pull data from your vehicle after the engine was turned off.
* **Note:** You will see an error of *"Unable to establish packet session to the vehicle"* when this occurs.

### Docker

Expand Down
44 changes: 39 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//const CircularJSON = require('circular-json');



const onstarConfig = {
deviceId: process.env.ONSTAR_DEVICEID || uuidv4(),
vin: process.env.ONSTAR_VIN,
Expand All @@ -23,7 +22,25 @@
requestPollingTimeoutSeconds: parseInt(process.env.ONSTAR_POLL_TIMEOUT) || 90, // 60 sec default
allowCommands: _.get(process.env, 'ONSTAR_ALLOW_COMMANDS', 'true') === 'true'
};
logger.info('OnStar Config', { onstarConfig });

const onstarRequiredProperties = {
vin: 'ONSTAR_VIN',
username: 'ONSTAR_USERNAME',
password: 'ONSTAR_PASSWORD',
onStarPin: 'ONSTAR_PIN'
};

for (let prop in onstarRequiredProperties) {
if (!onstarConfig[prop]) {
throw new Error(`"${onstarRequiredProperties[prop]}" is not defined`);
}
}

if (process.env.LOG_LEVEL === 'debug') {
logger.debug('OnStar Config:', { onstarConfig });
Dismissed Show dismissed Hide dismissed
} else {
logger.info('OnStar Config:', { onstarConfig: { ...onstarConfig, password: '********', onStarPin: '####' } });
Dismissed Show dismissed Hide dismissed
}

const mqttConfig = {
host: process.env.MQTT_HOST || 'localhost',
Expand All @@ -35,14 +52,31 @@
namePrefix: process.env.MQTT_NAME_PREFIX || '',
pollingStatusTopic: process.env.MQTT_ONSTAR_POLLING_STATUS_TOPIC,
};
logger.info('MQTT Config', { mqttConfig });

const mqttRequiredProperties = {
username: 'MQTT_USERNAME',
password: 'MQTT_PASSWORD',
pollingStatusTopic: 'MQTT_ONSTAR_POLLING_STATUS_TOPIC'
};

for (let prop in mqttRequiredProperties) {
if (!mqttConfig[prop]) {
throw new Error(`"${mqttRequiredProperties[prop]}" is not defined`);
}
}

if (process.env.LOG_LEVEL === 'debug') {
logger.debug('MQTT Config:', { mqttConfig });
Dismissed Show dismissed Hide dismissed
} else {
logger.info('MQTT Config:', { mqttConfig: { ...mqttConfig, password: '********' } });
Dismissed Show dismissed Hide dismissed
}

const init = () => new Commands(OnStar.create(onstarConfig));

const getVehicles = async commands => {
logger.info('Requesting vehicles');
const vehiclesRes = await commands.getAccountVehicles();
logger.info('Vehicle request status', { status: _.get(vehiclesRes, 'status') });
logger.info('Vehicle request status:', { status: _.get(vehiclesRes, 'status') });
const vehicles = _.map(
_.get(vehiclesRes, 'response.data.vehicles.vehicle'),
v => new Vehicle(v)
Expand All @@ -67,7 +101,7 @@
password: mqttConfig.password,
will: { topic: availabilityTopic, payload: 'false', retain: true }
};
logger.info('Connecting to MQTT', { url, config: _.omit(config, 'password') });
logger.info('Connecting to MQTT:', { url, config: _.omit(config, 'password') });
Dismissed Show dismissed Hide dismissed
const client = await mqtt.connectAsync(url, config);
logger.info('Connected to MQTT!');
return client;
Expand Down
Loading