aws / aws-iot-device-sdk-arduino-yun

SDK for connecting to AWS IoT from an Arduino Yún.
Apache License 2.0
163 stars 77 forks source link

Saving readings to SD card #35

Closed OtisHarrison24 closed 7 years ago

OtisHarrison24 commented 7 years ago

Hi, was wondering if there was any way to save my readings I am getting to a file on the SD card while using aws iot sdk?

THanks

liuszeng commented 7 years ago

Hi @OtisHarrison24 ,

Thank you very much for your interest in AWS IoT Arduino Yun SDK.

The Yun SDK utilizes the Serial1 connection between ATmega32u4 and AR9331 to translate user sketch commands to Python commands and send them over Serial1 to be executed on embedded Linux.

This mechanism is also used by native Arduino Bridge library, which provides a way to write to a file on Linux. However, since the SDK and Bridge library are using the same Serial1 channel, they cannot be used together otherwise different protocols will be interfering with each other. For more details, please check out this issue.

One work-around you can do is, add your own serial commands that basically executes the write to file action on Linux. You can use the existing serial commands as a reference: https://github.com/aws/aws-iot-device-sdk-arduino-yun/tree/master/AWS-IoT-Python-Runtime/lib/command

You will also need to come with your own protocol code to map your new sketch APIs to the command you create in Python runtime. You can use the existing sketch commands as a reference as well: https://github.com/aws/aws-iot-device-sdk-arduino-yun/blob/master/AWS-IoT-Arduino-Yun-Library/aws_iot_mqtt.cpp#L256

Another work-around you can do is, instead of writing the data you read to a local file on Linux, set up an IoT Rule that filters out the data published to one topic and writes to a file in S3 bucket. For more details, you can check out the following documentation: http://docs.aws.amazon.com/iot/latest/developerguide/s3-rule.html

Hope the above helps.

Thanks, Liusu

OtisHarrison24 commented 7 years ago

already pushing to S3 but what if there is any internet and the still want to save the data to sd just in case

liuszeng commented 7 years ago

Hi @OtisHarrison24 ,

In this case, you will need to add your own serial commands that executes write command on Linux/Python like I mentioned in the previous posts, since you cannot use the Bridge library APIs for file access.

This could potentially be a feature request to add customized command support into the SDK. Sorry that I cannot give you a more positive answer for now.

Thanks, Liusu

OtisHarrison24 commented 7 years ago

Was looking at the serial command. It look like python I could just add a streamwriter to lets say publish serial command and it should write to a file each time it publishes to a topic?