Skip to content

Commit

Permalink
Feature/debug (#6)
Browse files Browse the repository at this point in the history
* Added debug logging option and fixed configuration handling

* Full example formatting

* Fixed wrong attribute call for configuration

* Added info on enabling debug printing in readme and examples
  • Loading branch information
djesic authored Dec 6, 2018
1 parent 8261422 commit e09ebc6
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 116 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ wolk.publish()
wolk.disconnect()
```

### Debugging

Display send and received messages with `iot.debug_mode` :

```python
# Enable debug printing by setting flag to True
iot.debug_mode = False
```

----

## Advanced features
Expand Down
2 changes: 1 addition & 1 deletion WolkCore/WolkCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _on_inbound_message(self, message):
configuration.command
== ConfigurationCommandType.CONFIGURATION_COMMAND_TYPE_SET
):
self.configuration_handler.handle_configuration(configuration.value)
self.configuration_handler.handle_configuration(configuration.values)
self.publish_configuration()

elif (
Expand Down
4 changes: 4 additions & 0 deletions examples/Controlled_publish_period/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import streams
from wolkabout.iot import iot
from wireless import wifi

# uncomment one of the following lines depending on used board(e.g. Particle Photon, esp8266 or esp32 based board)
# from broadcom.bcm43362 import bcm43362 as wifi_driver
# from espressif.esp32net import esp32wifi as wifi_driver
Expand All @@ -34,6 +35,9 @@
publish_period_milliseconds = 5000
streams.serial()

# Enable debug printing by setting flag to True
iot.debug_mode = False


# Connect to WiFi network
try:
Expand Down
40 changes: 25 additions & 15 deletions examples/Full_feature_set/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
publish_period_milliseconds = 5000
streams.serial()

# Enable debug printing by setting flag to True
iot.debug_mode = False


class ActuatorSimulator:
def __init__(self, value):
Expand Down Expand Up @@ -115,16 +118,17 @@ def handle_configuration(self, configuration):
print("Something went wrong while creating the device: ", e)

try:
wolk = iot.Wolk(device,
host="api-demo.wolkabout.com",
port=1883,
actuation_handler=ActuationHandlerImpl(),
actuator_status_provider=ActuatorStatusProviderImpl(),
outbound_message_queue=iot.ZerynthOutboundMessageQueue(200),
configuration_handler=ConfigurationHandlerImpl(),
configuration_provider=ConfigurationProviderImpl(),
keep_alive_enabled=True
)
wolk = iot.Wolk(
device,
host="api-demo.wolkabout.com",
port=1883,
actuation_handler=ActuationHandlerImpl(),
actuator_status_provider=ActuatorStatusProviderImpl(),
outbound_message_queue=iot.ZerynthOutboundMessageQueue(200),
configuration_handler=ConfigurationHandlerImpl(),
configuration_provider=ConfigurationProviderImpl(),
keep_alive_enabled=True,
)
except Exception as e:
print("Something went wrong while creating the Wolk instance: ", e)

Expand Down Expand Up @@ -154,11 +158,17 @@ def handle_configuration(self, configuration):
else:
wolk.add_alarm("HH", False)

print("Publishing readings" +
" T: " + str(temperature) +
" P: " + str(pressure) +
" H: " + str(humidity) +
" ACL: " + str(acceleration))
print(
"Publishing readings"
+ " T: "
+ str(temperature)
+ " P: "
+ str(pressure)
+ " H: "
+ str(humidity)
+ " ACL: "
+ str(acceleration)
)

# Adds a sensor reading to the queue
wolk.add_sensor_reading("T", temperature)
Expand Down
Loading

0 comments on commit e09ebc6

Please sign in to comment.