Skip to content

Commit

Permalink
Remove coap-client binaries (diyhue#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
7FM authored Feb 7, 2023
1 parent fc16d0a commit 1d852e4
Show file tree
Hide file tree
Showing 16 changed files with 11 additions and 151 deletions.
10 changes: 1 addition & 9 deletions .build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ WORKDIR /opt/hue-emulator
# Architecture automatically set by docker eg. linux/amd64, linux/arm/v7, linux/arm64
ARG TARGETPLATFORM

COPY BridgeEmulator .build/select.sh ./

RUN chmod +x ./select.sh && \
mkdir out && \
./select.sh

# ============================ Actual image from here ====================
#FROM debian:stable-slim as prod
FROM debian@sha256:457715c656bf1b14ae3790853c1a4bde13a7e740c510b9c029d38012be78d8c6 as prod
Expand All @@ -23,7 +17,7 @@ COPY requirements.txt ./
## Install requirements
RUN apt update && apt install --no-install-recommends -y \
curl unzip python3-minimal python3-pip python3-dev python3-setuptools gcc \
openssl nmap psmisc iproute2 bluez bluetooth \
openssl nmap psmisc iproute2 bluez bluetooth libcoap2-bin \
&& pip3 install -r requirements.txt --no-cache-dir \
&& apt purge -y python3-pip python3-setuptools python3-dev gcc \
&& apt autoremove -y \
Expand All @@ -50,8 +44,6 @@ RUN curl -sL https://github.com/diyhue/diyHueUI/releases/latest/download/DiyHueU

## Copy correct (compiled) C file from previous image
COPY ./BridgeEmulator/genCert.sh ./BridgeEmulator/openssl.conf /opt/hue-emulator/
RUN echo workaround for https://github.com/moby/moby/issues/37965
COPY --from=binselector /opt/hue-emulator/out /opt/hue-emulator/

## Change Docker script permissions
RUN chmod +x /opt/hue-emulator/genCert.sh
Expand Down
27 changes: 0 additions & 27 deletions .build/archive/aarch64.Dockerfile

This file was deleted.

36 changes: 0 additions & 36 deletions .build/archive/amd64.Dockerfile

This file was deleted.

32 changes: 0 additions & 32 deletions .build/archive/arm.Dockerfile

This file was deleted.

17 changes: 0 additions & 17 deletions .build/select.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY requirements.txt /tmp/pip-tmp/
## Install requirements
RUN apt update && apt install --no-install-recommends -y \
python3-minimal python3-pip python3-setuptools \
openssl nmap psmisc iproute2 \
openssl nmap psmisc iproute2 libcoap2-bin \
&& pip3 --disable-pip-version-check install --no-cache-dir -r /tmp/pip-tmp/requirements.txt \
&& apt purge -y python3-pip python3-setuptools \
&& apt autoremove -y \
Expand Down
2 changes: 1 addition & 1 deletion .idea/docker/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed BridgeEmulator/coap-client-aarch64
Binary file not shown.
Binary file removed BridgeEmulator/coap-client-arm
Binary file not shown.
Binary file removed BridgeEmulator/coap-client-i686
Binary file not shown.
Binary file removed BridgeEmulator/coap-client-linux
Binary file not shown.
Binary file removed BridgeEmulator/coap-client-x86_64
Binary file not shown.
2 changes: 1 addition & 1 deletion BridgeEmulator/flaskUI/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def pairTradfri():
try:
data = request.get_json(force=True)
pprint(data)
cmd = ["./coap-client-linux", "-m", "post", "-u", "Client_identity", "-k", data["tradfriCode"], "-e", "{\"9090\":\"" + data["identity"] + "\"}", "coaps://" + data["tradfriGwIp"] + ":5684/15011/9063"]
cmd = ["coap-client-gnutls", "-m", "post", "-u", "Client_identity", "-k", data["tradfriCode"], "-e", "{\"9090\":\"" + data["identity"] + "\"}", "coaps://" + data["tradfriGwIp"] + ":5684/15011/9063"]
registration = json.loads(check_output(cmd).decode('utf-8').rstrip('\n').split("\n")[-1])
if "9091" in registration:
bridgeConfig["config"]["tradfri"] = {"psk": registration["9091"], "tradfriGwIp": data["tradfriGwIp"], "identity": data["identity"]}
Expand Down
25 changes: 2 additions & 23 deletions BridgeEmulator/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ esac
echo -e "\033[36m Installing dependencies.\033[0m"
if type apt &> /dev/null; then
# Debian-based distro
apt-get install -y unzip python3 python3-pip openssl bluez bluetooth
apt-get install -y unzip python3 python3-pip openssl bluez bluetooth libcoap2-bin
elif type pacman &> /dev/null; then
# Arch linux
pacman -Syq --noconfirm || exit 1
pacman -Sq --noconfirm unzip python3 python-pip gnu-netcat || exit 1
pacman -Sq --noconfirm unzip python3 python-pip gnu-netcat libcoap || exit 1
else
# Or assume that packages are already installed (possibly with user confirmation)?
# Or check them?
Expand Down Expand Up @@ -156,27 +156,6 @@ mv index.html /opt/hue-emulator/flaskUI/templates/
cp -r static /opt/hue-emulator/flaskUI/
rm -r static

# Install correct binaries
case $arch in
x86_64|i686|aarch64)
cp coap-client-$arch /opt/hue-emulator/coap-client-linux
;;
arm64)
cp coap-client-aarch64 /opt/hue-emulator/coap-client-linux
;;
armv*)
cp coap-client-arm /opt/hue-emulator/coap-client-linux
;;
*)
echo -e "\033[0;31m-------------------------------------------------------------------------------"
echo -e "ERROR: Unsupported architecture $arch!"
echo -e "You will need to manually compile the coap-client binary\033[0m"
echo -e "Please visit https://diyhue.readthedocs.io/en/latest/AddFuncts/entertainment.html"
echo -e "Once installed, open this script and manually run the last 10 lines."
exit 1
esac

chmod +x /opt/hue-emulator/coap-client-linux
cp hue-emulator.service /lib/systemd/system/
cd ../../
rm -rf diyHue.zip diyHue-$branchSelection
Expand Down
8 changes: 4 additions & 4 deletions BridgeEmulator/lights/protocols/tradfri.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def set_light(light, data):

if "5712" not in payload:
payload["5712"] = 4 #If no transition add one, might also add check to prevent large transitiontimes
cmd = ["./coap-client-linux", "-B", "2", "-m", "put", "-u", light.protocol_cfg["identity"], "-k", light.protocol_cfg["psk"], "-e", "{ \"3311\": [" + json.dumps(payload) + "] }", url]
cmd = ["coap-client-gnutls", "-B", "2", "-m", "put", "-u", light.protocol_cfg["identity"], "-k", light.protocol_cfg["psk"], "-e", "{ \"3311\": [" + json.dumps(payload) + "] }", url]
check_output(cmd)

def get_light_state(light):
state ={}
cmd = ["./coap-client-linux", "-B", "5", "-m", "get", "-u", light.protocol_cfg["identity"], "-k", light.protocol_cfg["psk"], "coaps://" + light.protocol_cfg["ip"] + ":5684/15001/" + str(light.protocol_cfg["id"])]
cmd = ["coap-client-gnutls", "-B", "5", "-m", "get", "-u", light.protocol_cfg["identity"], "-k", light.protocol_cfg["psk"], "coaps://" + light.protocol_cfg["ip"] + ":5684/15001/" + str(light.protocol_cfg["id"])]
light_data = json.loads(check_output(cmd).decode('utf-8').rstrip('\n').split("\n")[-1])
state["on"] = bool(light_data["3311"][0]["5850"])
state["bri"] = light_data["3311"][0]["5851"]
Expand All @@ -77,11 +77,11 @@ def discover(detectedLights, tradfriConfig):
if "psk" in tradfriConfig:
logging.debug("tradfri: <discover> invoked!")
try:
cmd = ["./coap-client-linux", "-B", "5", "-m", "get", "-u", tradfriConfig["identity"], "-k", tradfriConfig["psk"], "coaps://" + tradfriConfig["tradfriGwIp"] + ":5684/15001"]
cmd = ["coap-client-gnutls", "-B", "5", "-m", "get", "-u", tradfriConfig["identity"], "-k", tradfriConfig["psk"], "coaps://" + tradfriConfig["tradfriGwIp"] + ":5684/15001"]
tradriDevices = json.loads(check_output(cmd).decode('utf-8').rstrip('\n').split("\n")[-1])
logging.debug(tradriDevices)
for device in tradriDevices:
cmd = ["./coap-client-linux", "-B", "5", "-m", "get", "-u", tradfriConfig["identity"], "-k", tradfriConfig["psk"], "coaps://" + tradfriConfig["tradfriGwIp"] + ":5684/15001/" + str(device)]
cmd = ["coap-client-gnutls", "-B", "5", "-m", "get", "-u", tradfriConfig["identity"], "-k", tradfriConfig["psk"], "coaps://" + tradfriConfig["tradfriGwIp"] + ":5684/15001/" + str(device)]
deviceParameters = json.loads(check_output(cmd).decode('utf-8').rstrip('\n').split("\n")[-1])
if "3311" in deviceParameters:
logging.debug("found tradfi light " + deviceParameters["9001"])
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ All documentation and instructions can be found over at [diyhue.readthedocs.io](

## Requirements

- coap-client: i.e. via `apt install libcoap2-bin`
- Python 3
- Python modules: ws4py, requests, astral, paho-mqtt [see requirements.txt](./requirements.txt)

Expand Down

0 comments on commit 1d852e4

Please sign in to comment.