Skip to content

Commit

Permalink
Add ip_address option to setup() (#628)
Browse files Browse the repository at this point in the history
* Add ip_address option to setup()

* Update README.md
  • Loading branch information
felipediel authored Oct 18, 2021
1 parent 24ef730 commit b596984
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ broadlink.setup('myssid', 'mynetworkpass', 3)

Security mode options are (0 = none, 1 = WEP, 2 = WPA1, 3 = WPA2, 4 = WPA1/2)

#### Advanced options

You may need to specify a broadcast address if setup is not working.
```python3
broadlink.setup('myssid', 'mynetworkpass', 3, ip_address='192.168.0.255')
```

### Discovery

Use this function to discover devices:
Expand Down
9 changes: 7 additions & 2 deletions broadlink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ def xdiscover(

# Setup a new Broadlink device via AP Mode. Review the README to see how to enter AP Mode.
# Only tested with Broadlink RM3 Mini (Blackbean)
def setup(ssid: str, password: str, security_mode: int) -> None:
def setup(
ssid: str,
password: str,
security_mode: int,
ip_address: str = DEFAULT_BCAST_ADDR,
) -> None:
"""Set up a new Broadlink device via AP mode."""
# Security mode options are (0 - none, 1 = WEP, 2 = WPA1, 3 = WPA2, 4 = WPA1/2)
payload = bytearray(0x88)
Expand Down Expand Up @@ -269,5 +274,5 @@ def setup(ssid: str, password: str, security_mode: int) -> None:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Internet # UDP
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(payload, (DEFAULT_BCAST_ADDR, DEFAULT_PORT))
sock.sendto(payload, (ip_address, DEFAULT_PORT))
sock.close()

0 comments on commit b596984

Please sign in to comment.