lightswitch05 / foscam-client

Node client sdk for current HD foscam cameras that stream H.264 like the FI9821W, FI9831P, etc..
https://lightswitch05.github.io/foscam-client
MIT License
45 stars 15 forks source link

MAC address may be returned as "Infinity" #14

Closed jamieburchell closed 8 years ago

jamieburchell commented 8 years ago

The XML contains the MAC address but the parsed response contains "Infinity"

I suspect the MAC address is being parsed as a number or converted in some way...

https://github.com/luisiam/homebridge-foscam2/issues/3

https://github.com/luisiam/homebridge-foscamcamera/issues/5

Oct 05 01:06:35 osmc-bedroom homebridge[20840]: <CGI_Result>
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: <result>0</result>
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: <productName>FI9821W+V2</productName>
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: <serialNo></serialNo>
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: <devName>Sitting_Room</devName>
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: <mac>00626EXXXXXXXX</mac>
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: <year>2016</year>

...

Oct 05 01:06:35 osmc-bedroom homebridge[20840]: { CGI_Result:
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: { result: 0,
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: productName: 'FI9821W+V2',
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: serialNo: '',
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: devName: 'Sitting_Room',
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: mac: Infinity,
Oct 05 01:06:35 osmc-bedroom homebridge[20840]: year: 2016,
lightswitch05 commented 8 years ago

Great find! If you need this soon, pull requests are very welcome. If not, I'll try to find some time in the next few weeks to look into it.

jamieburchell commented 8 years ago

No problem. To be honest I'm not sure how to fix this one. You kind of can't rely on the XML processor to automagically convert values to guessed types using xml2js.processors.parseNumbers.

lightswitch05 commented 8 years ago

Looks like the solution is to create a custom parser based off of the xml2js.processors.parseNumbers parser

jamieburchell commented 8 years ago

I think the difficulty will be knowing if you should parse the value given as a MAC adddress or convert it in to a int/float. For the same reason it's not able to automagically know if a value beginning 00626E should be a string.

lightswitch05 commented 8 years ago

I can fix this, but not till next week. Which API call is this response from? It looks like the issue only occurs for specific mac addresses (contains an 'E' - but no other letters).

jamieburchell commented 8 years ago

So the XML (which has the correct MAC address in) is from /cgi-bin/CGIProxy.fcgi?cmd=getDevInfo&usr=xxx&pwd=xxx. Once the XML has been parsed the value of "mac" in the JSON is Infinity.

Yeah, it looks like I was just unlucky that my MAC address only has one letter ("E") in it. I know of only one other person that's run in to this.

jamieburchell commented 8 years ago

This is my stab at a revised function, but I do not know if you approve or how to factor that in as a custom function.

  exports.parseNumbers = function(str) {
    if (!isNaN(str) && str.toUpperCase().indexOf('E') < 0) {
      str = str % 1 === 0 ? parseInt(str, 10) : parseFloat(str);
    }
    return str;
  };

If you agree in principal I could have a look at getting that in Foscam.js

jamieburchell commented 8 years ago

https://github.com/lightswitch05/foscam-client/pull/15

lightswitch05 commented 8 years ago

Closed by #15