particle-iot / particle-cloud-sdk-ios

Official Particle Cloud SDK for iOS
Apache License 2.0
19 stars 21 forks source link

Wrong device type in particle-sdk-ios #8

Closed zermanik closed 6 years ago

zermanik commented 6 years ago

Dear Particle Team,

I've installed the particle-sdk-ios and used the following function: ParticleCloud.sharedInstance().getDevices. I'm listing all devices.

As a result I get the following: <ParticleDevice 0x6000015dd2c0, type: Photon, id: 230033000847373432363837, name: porsche-secpro-alarm, connected: true, variables: { }, functions: ( alarm ), version: (null), requires update: false, last app: (null), last heard: 2018-08-29 06:11:02 +0000> <ParticleDevice 0x6000015dc780, type: Photon, id: 2b0053000a51353431383437, name: porsche-secpro-v1, connected: true, variables: { altitude = double; gas = double; humidity = double; pressure = double; temperature = double; }, functions: ( led, status, tmode, batt, gps ), version: (null), requires update: false, last app: (null), last heard: 2018-08-29 06:20:04 +0000>

As you can see, the device type for both devices is listed as Photon, even though my devices are clearly Electrons. You can check that using the ID.

Please let me know if you can reproduce or find the issue.

Thank you in advance!

Best,

Herbert

RaimundasSakalauskas commented 6 years ago

Thanks for reporting. Will investigate to see whether it's a problem in database or SDK. Can you please tell me how did you install the library in your project (carthage, pods, manually) and if it was using dependency manager what version of dependency do you have? Thanks

Edit: This is the problem with logging. Underlying model has property type set to correct type id (10 for electron). It seems that the code for logging a device hasn't been changed for ~3 years and is heavily outdated. Will fix this in the next build for now don't be alarmed as the the type itself is correct.

In device class I see the following code:

-(NSString *)description
{
...
    (self.type == ParticleDeviceTypeCore) ? @"Core" : @"Photon",
...
}

The actual device type enum has following values

typedef NS_ENUM(NSInteger, ParticleDeviceType) {
    ParticleDeviceTypeUnknown=-1,
    ParticleDeviceTypeCore=0,
    ParticleDeviceTypePhoton=6, // or P0
    ParticleDeviceTypeP1=8,
    ParticleDeviceTypeElectron=10,
    ParticleDeviceTypeRaspberryPi=31,
    ParticleDeviceTypeRedBearDuo=88,
    ParticleDeviceTypeBluz=103,
    ParticleDeviceTypeDigistumpOak=82,
};

So the logging part of the code hasn't been changed since the time when particle only had 2 devices. Sorry for that.

zermanik commented 6 years ago

Dear Raimundas,

I installed using pods. Great that you found what's happening. It's not urgent, I'm onlyprototyping for now. Looking forward to the update!

Best, H.

RaimundasSakalauskas commented 6 years ago

Well this bug is very minor and only affecting the console logging of ParticleDevice instance. SDK can safely be used, because this SDK feature will never be used in the app :)