Identifying Devices and Substring Questions


I’m trying to write one code base to control different devices (other than the pin values, the functionality of sending data to my server should be the same).

At the moment my plan is to get the substring of a device ID from 0 to 3 to identify the device. Current code:

dev_id <- hardware.getdeviceid();
code <- dev_id.substring(0, 3);
if( code == "300" ) { //must be the 003 series

This is telling me that there’s no index for substring. dev_id.find(“500”) works fine though. I saw that the javascript string functions are part of the S namespace, but S.substring(dev_id, 0, 3); didn’t work either. Do I need to use a directive to add the string namespace?

Also as a higher level question, is there a more direct way of identifying a model type of a device?




The call can tell you, or you could instead test for the presence of features or pins directly, rather than using the model name:

if ("pinX" in hardware)...

I’m not sure why returns “imp004m” for the “imp004”, but it does so consistently, so that should be easy to deal with.