Azure / azure-iot-arduino

Azure IoT library for the Arduino
Other
168 stars 95 forks source link

Fix bugs with Authentication #23

Closed yaweiw closed 8 years ago

yaweiw commented 8 years ago

SAS token generated out of device constr doesn't seem to work. We generate SAS token from iothubowner constr in this fix so that whatever changes in iothub in future won't break the existing code.

The code has been verified with Feather M0 Wifi board. Contact yaweiw@microsoft.com should you have questions.

stefangordon commented 8 years ago

Thank you @yaweiw! I will take a look through these. Note that some of these changes are in the core Azure C libraries that do not live in this repo (they are just synced in via a script in the source), but I will share with those people so they can evaluate. (e.g. https://github.com/Azure/azure-iot-sdks/tree/master/c)

sandeepmistry commented 8 years ago

Hi @yaweiw @stefangordon,

On SAMD src/samd/time.cpp makes the use of the RTC to make time(NULL) work. However iotHubClient.setEpochTime(time) needs to be called in the sketch as shown in the example.

Let me know if this isn't working.

yaweiw commented 8 years ago

Hi @sandeepmistry,

Yes you are right. setEpochTime is actually something I've been trying to find out or create.

Thanks.

yaweiw commented 8 years ago

Hi @stefangordon

Thanks mate. Please let me know if anything is wrong. Cheers.

sandeepmistry commented 8 years ago

Can this PR be closed then?

yaweiw commented 8 years ago

Have you verified the PR has fixed the authentication issue or not? Or are the bits currently working on any of your boards?

sandeepmistry commented 8 years ago

@yaweiw last time I used this library everything was working as with the simplesample_http.ino example on my Arduino MKR1000.

yaweiw commented 8 years ago

@sandeepmistry i am pretty sure that my adafruit boards don't work at all. Can you try this on your MKR1000 board and see if it works? It won't cost you much time i think.

sandeepmistry commented 8 years ago

@yaweiw looks good:

Attempting to connect to SSID: F0645C
Connected to wifi
Fetched NTP epoch time is: 1471010039
Info: IoT Hub SDK for C, version 1.0.1
Info: IoTHubClient accepted the message for delivery
Info: Message Id: 1 Received.
Info: Result Call Back Called! Result is: IOTHUB_CLIENT_CONFIRMATION_OK 
Info: Turning fan on.
yaweiw commented 8 years ago

@sandeepmistry can you please pull my bits and try with your boards as well? https://github.com/yaweiw/azureiothub/tree/develop

sandeepmistry commented 8 years ago

Yes, that works as well. I had to provide 2 connection strings in the updated example.

yaweiw commented 8 years ago

@sandeepmistry yeah. two connections are required and it guarantees working. However, i have just pulled your bits and tried again and seems to be working. I think it's because of setEpochTime was correctly called so SASToken_Create starts to function normally. Let's close this PR off for now.