-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from FoamyGuy/scanning_and_mac_map
Scanning and mac map
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 Tim Cocks for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
""" | ||
Scan the network for Wiz lights. Print out the MAC addresses of any lights found. | ||
Set each light to a different random RGB color. | ||
""" | ||
|
||
import random | ||
|
||
import wifi | ||
|
||
from adafruit_wiz import WizConnectedLight, scan | ||
|
||
udp_port = 38899 # Default port is 38899 | ||
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (0, 255, 255), (255, 0, 255)] | ||
mac_to_light_map = {} | ||
|
||
found_lights = scan(wifi.radio, timeout=1) | ||
for light_info in found_lights: | ||
mac_to_light_map[light_info["result"]["mac"]] = WizConnectedLight( | ||
light_info["ip"], udp_port, wifi.radio | ||
) | ||
print(f"Found Light with MAC: {light_info['result']['mac']}") | ||
|
||
for mac, light in mac_to_light_map.items(): | ||
chosen_color = random.choice(colors) | ||
print(f"Setting light with MAC: {mac} to {chosen_color}") | ||
light.rgb_color = chosen_color |