ibm-watson-iot / iot-python

Python Package and samples for connecting to Maximo IoT and IBM Watson IoT Platform
http://ibm-watson-iot.github.io/iot-python/
Eclipse Public License 1.0
187 stars 160 forks source link

file transfer support possible? #130

Closed namespace7 closed 5 years ago

namespace7 commented 5 years ago

does the library support different format ,other then json ? to update the existing file or send a file from one system to another?

durera commented 5 years ago

I hacve just put out a pre-release for the new wiotp-sdk library ahead of the finalization for 1.0 (note: there may still be a few breaking changes coming before the official 1.0 release)

The new RawCodec will do what you want, it is automatically registered to handle events/commands where format=raw:

On the device:

cwd = os.getcwd()
fileContent = None
with open("%s/README.md" % cwd, 'rb') as fileIn:
  fileContent = fileIn.read()

deviceCli.publishEvent("readmeContent", "raw", fileContent)

When the app recieves the event you will be able to get a bytearray containing the data from the file using event.data in the event callback method.

Utf8Codec does pretty much the same thing, but works for UTF-8 encoded strings rather than arbitrary bytes, if you're transferring UTF-8 encoded files it may be more appropriate as it would throw errors in the event any content in the file is not valid UTF-8.

Related code:

namespace7 commented 5 years ago

Great!