koalazak / rest980

REST interface to control your iRobot Roomba 980 via local server on your lan.
MIT License
293 stars 62 forks source link

Problem with Firmware 2 and REST with environment variables #17

Closed normanth closed 7 years ago

normanth commented 7 years ago

Hi,

first: thanks for this api - a very good solution - i really like it!

I use the docker installation with environment variables: ENABLE_LOCAL yes; KEEP_ALIVE no; ENABLE_CLOUD no; FIRMWARE_VERSION 2; PASSWORT ...; ROBOT_IP ...; BLID ...

With KEEP_ALIVE yes everything works. With KEEP_ALIVE no there comes an error:

TypeError: Cannot read property 'getMission' of undefined at /usr/src/app/routes/api.js:149:20

This error appears because the condition in line 146 isn't true. keepAlive is 'no', but firmwareVersion seems to be a string. If I change the condition to

if (keepAlive === 'no' && firmwareVersion === '2') {

everything works.

There are other lines with a firmwareVersion compare. And I don't know if the variable is an integer using config file.

Thanks, Norman

normanth commented 7 years ago

I think there are two options.

First option: We change the version number to String:

12: var firmwareVersion = process.env.FIRMWARE_VERSION || config.firmwareVersion || '1'; 18: if (firmwareVersion === '2') enableCloud = 'no'; ...

Second option: We change the compare operator:

18: if (firmwareVersion == 2) enableCloud = 'no'; ...

Not tested yet! What do you think?

koalazak commented 7 years ago

I think is better to force the firmwareVersion to a integer in: var firmwareVersion = parseInt((process.env.FIRMWARE_VERSION || config.firmwareVersion || 1), 10);

fixed and pushed in v2.0.3 https://github.com/koalazak/rest980/commit/abb533f6680363740ffedcd22d4cb489c4397704

thanks!

normanth commented 7 years ago

Good solution... thanx...