Skip to content

Commit ffe5648

Browse files
author
durera
committed
Use qos 2 for command publish/subscribe
1 parent 3a290d9 commit ffe5648

File tree

5 files changed

+15
-445
lines changed

5 files changed

+15
-445
lines changed

README.md

Lines changed: 3 additions & 229 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ IBM Internet of Things Foundation for Python
33

44
Python module for interacting with the IBM Internet of Things Foundation.
55

6-
* [Python 3.4](https://www.python.org/download/releases/3.4.1)
6+
* [Python 3.4](https://www.python.org/download/releases/3.4.2)
77

88
Dependencies
99
------------
@@ -28,231 +28,5 @@ Uninstalling the module is simple.
2828

2929
Documentation
3030
-------------
31-
32-
1. Device Client
33-
2. Application Client
34-
1. [Constructor](#constructor)
35-
2. [Subscribing to Device events](#subscribing-to-device-events)
36-
3. [Handling events from Devices](#handling-events-from-devices)
37-
4. [Subscribing to Device status](#subscribing-to-device-status)
38-
5. [Handling status updates from Devices](#handling-status-updates-from-devices)
39-
6. [Publishing Events "from" Devices](#publishing-events-from-devices)
40-
7. [Publishing Commands to Devices](#publishing-commands-to-devices)
41-
8. [Retrieve Device Details](#retrieve-devices-details)
42-
9. [Register a New Device](#register-a-new-device)
43-
10. [Delete a Device](#delete-a-device)
44-
11. [Access Historical Event Data](#access-historical-event-data)
45-
46-
47-
###Device Client
48-
49-
Work in progress ...
50-
51-
52-
###Application Client
53-
54-
####Constructor
55-
The Client constructor accepts an options dict containing:
56-
* org - Your organization ID
57-
* id - The unique ID of your application within your organization
58-
* authMethod - Method of authentication (the only value of authMethod currently supported is "apikey")
59-
* authKey - API key (required if authMethod is "apikey")
60-
* authToken - API key token (required if authMethod is "apikey")
61-
62-
```python
63-
import ibmiotf.application
64-
try:
65-
options = {"org": organization, "id": appId, "auth-method": authMethod, "auth-key": authKey, "auth-token": authToken}
66-
client = ibmiotf.application.Client(options)
67-
except ibmiotf.ConnectionException as e:
68-
...
69-
```
70-
71-
#####Using a Configuration File
72-
```python
73-
import ibmiotf.application
74-
try:
75-
options = ibmiotf.application.ParseConfigFile(configFilePath)
76-
client = ibmiotf.application.Client(options)
77-
except ibmiotf.ConnectionException as e:
78-
...
79-
```
80-
81-
The application configuration file must be in the following format:
82-
```
83-
[application]
84-
org=$orgId
85-
id=$myApplication
86-
auth-method=apikey
87-
auth-key=$key
88-
auth-token=$token
89-
```
90-
91-
####Subscribing to Device events
92-
By default, this will subscribe to all events from all connected devices. Use the type, id and event parameters to control the scope of the subscription. A single client can support multiple subscriptions.
93-
94-
#####Subscribe to all events from all devices
95-
```python
96-
client.connect()
97-
client.subscribeToDeviceEvents()
98-
```
99-
100-
#####Subscribe to all events from all devices of a specific type
101-
```python
102-
client.connect()
103-
client.subscribeToDeviceEvents(deviceType=myDeviceType)
104-
```
105-
106-
#####Subscribe to a specific event from all devices
107-
```python
108-
client.connect()
109-
client.subscribeToDeviceEvents(event=myEvent)
110-
```
111-
112-
#####Subscribe to a specific event from two different devices
113-
```python
114-
client.connect()
115-
client.subscribeToDeviceEvents(deviceType=myDeviceType, deviceId=myDeviceId, event=myEvent)
116-
client.subscribeToDeviceEvents(deviceType=myOtherDeviceType, deviceId=myOtherDeviceId, event=myEvent)
117-
```
118-
119-
####Handling events from Devices
120-
To process the events received by your subscroptions you need to register an event callback method. The messages are returned as an instance of the Event class:
121-
* event.device - string (uniquely identifies the device across all types of devices in the organization $deviceType:$deviceId)
122-
* event.deviceType - string
123-
* event.deviceId - string
124-
* event.event - string
125-
* event.format - string
126-
* event.data - dict
127-
* event.timestamp - datetime
128-
129-
```python
130-
def myEventCallback(event):
131-
print "%s event '%s' received from device [%s]: %s" % (event.format, event.event, event.device, json.dumps(event.data))
132-
133-
...
134-
client.connect()
135-
client.eventCallback = myEventCallback
136-
client.subscribeToDeviceEvents()
137-
```
138-
139-
140-
####Subscribing to Device status
141-
By default, this will subscribe to status updates for all connected devices. Use the type and id parameters to control the scope of the subscription. A single client can support multiple subscriptions.
142-
143-
#####Subscribe to status updates for all devices
144-
```python
145-
client.connect()
146-
client.subscribeToDeviceStatus()
147-
```
148-
149-
#####Subscribe to status updates for all devices of a specific type
150-
```python
151-
client.connect()
152-
client.subscribeToDeviceStatus(deviceType=myDeviceType)
153-
```
154-
155-
#####Subscribe to status updates for two different devices
156-
```python
157-
client.connect()
158-
client.subscribeToDeviceStatus(deviceType=myDeviceType, deviceId=myDeviceId)
159-
client.subscribeToDeviceStatus(deviceType=myOtherDeviceType, deviceId=myOtherDeviceId)
160-
```
161-
162-
####Handling status updates from Devices
163-
To process the status updates received by your subscriptions you need to register an event callback method. The messages are returned as an instance of the Status class:
164-
165-
The following properties are set for both "Connect" and "Disconnect" status events:
166-
* status.clientAddr - string
167-
* status.protocol - string
168-
* status.clientId - string
169-
* status.user - string
170-
* status.time - datetime
171-
* status.action - string
172-
* status.connectTime - datetime
173-
* status.port - int
174-
175-
The following properties are only set when the action is "Disconnect":
176-
* status.writeMsg - int
177-
* status.readMsg - int
178-
* status.reason - string
179-
* status.readBytes - int
180-
* status.writeBytes - int
181-
182-
```python
183-
def myStatusCallback(status):
184-
if status.action == "Disconnect":
185-
print("%s - device %s - %s (%s)" % (status.time.isoformat(), status.device, status.action, status.reason))
186-
else:
187-
print("%s - %s - %s" % (status.time.isoformat(), status.device, status.action))
188-
189-
...
190-
client.connect()
191-
client.statusCallback = myStatusCallback
192-
client.subscribeToDeviceStstus()
193-
```
194-
195-
####Publishing Events "from" Devices
196-
Applications can publish events as if they originated from a Device
197-
```python
198-
client.connect()
199-
myData={'name' : 'foo', 'cpu' : 60, 'mem' : 50}
200-
client.publishEvent(myDeviceType, myDeviceId, "status", myData)
201-
```
202-
203-
####Publishing Commands to Devices
204-
Applications can publish commands to connected Devices
205-
```python
206-
client.connect()
207-
commandData={'rebootDelay' : 50}
208-
client.publishCommand(myDeviceType, myDeviceId, "reboot", myData)
209-
```
210-
211-
####Retrieve Devices Details
212-
213-
#####Retrieve Details of all Registered Devices
214-
```python
215-
deviceList = client.api.getDevices()
216-
print(deviceList)
217-
```
218-
219-
#####Retrieve Details of a Specific Device
220-
```python
221-
device = client.api.getDevice(deviceType, deviceId)
222-
print(device)
223-
```
224-
225-
####Register a New Device
226-
```python
227-
device = client.api.registerDevice(deviceType, deviceId, metadata)
228-
print(device)
229-
print("Generated Authentication Token = %s" % (device['password']))
230-
```
231-
232-
####Delete a Device
233-
```python
234-
try:
235-
client.api.deleteDevice(deviceType, deviceId)
236-
except Exception as e:
237-
print(str(e))
238-
```
239-
240-
####Access Historical Event Data
241-
242-
#####Get historical event data for a specific device
243-
```python
244-
result = client.api.getHistoricalEvents(deviceType, deviceId)
245-
print(result)
246-
```
247-
248-
#####Get historical event data for all devices of a specific type
249-
```python
250-
result = client.api.getHistoricalEvents(deviceType)
251-
print(result)
252-
```
253-
254-
#####Get historical event data for all devices of all types
255-
```python
256-
result = client.api.getHistoricalEvents()
257-
print(result)
258-
```
31+
* [Device Client](http://iotf.readthedocs.org/en/latest/libraries/python_cli_for_devices.html)
32+
* [Application Client](http://iotf.readthedocs.org/en/latest/libraries/python_cli_for_apps.html)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy