WifiManager()
Main class to sablish and manage WiFi connection with Bittle, using the REST API hosted in included WiFi dongle.
Attributes
ip (str): Bittle ip address.
http_address (str): Bittle REST API address.
Methods
get_status_code(): Returns REST API actionpage (e.g., http://192.168.1.18/actionpage) request code (int). If there is no connection to Bittle REST API, -1 is returned.
has_connection(): Returns True if there is connection to REST API actionpage, False otherwise.
send_msg(msg): Sends passed msg parameter (string) to Bittle. Returns request response (int).
Example
The following example shows the complete process of connecting and sending messages to Bittle through WiFi connection.
import time
from pyBittle import wifiManager
# Create WifiManager instance
wifiManager = wifiManager.WifiManager()
# Set Bittle REST API ip address
rest_api_ip = '192.168.1.115'
wifiManager.ip = rest_api_ip
if wifiManager.has_connection(): # http://192.168.1.115/actionpage is accessible
response = wifiManager.send_msg('khi') # Send GREETING command
print(f"khi message sent, received response: {response}, expected: 200")
time.sleep(6) # Wait for GREETING action to finish
response = wifiManager.send_msg("d") # Send SHUTDOWN command
print(f"d message sent, received response: {response}, expected: 200")
else:
print("Can't access to Bittle REST API address!")
Last updated
Was this helpful?