diff --git a/Dockerfile b/Dockerfile index a84526d..fc2fa49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Use an official Rust image as the base FROM rust:latest -# Install necessary packages +# Install necessary packages including supervisord RUN apt-get update && apt-get install -y \ libudev-dev \ iproute2 \ @@ -19,22 +19,22 @@ RUN git clone https://github.com/jgoerzen/xbnet.git /usr/src/xbnet WORKDIR /usr/src/xbnet RUN cargo build --release -# Copy the built binary to /usr/local/bin (makes it accessible from anywhere in the OS) +# Copy the built binary to /usr/local/bin RUN cp target/release/xbnet /usr/local/bin/xbnet # Copy the entrypoint script -COPY entrypoint.sh /entrypoint.sh +COPY ./scripts/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh # Copy the supervisor config file COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf -# Copy the health check script from local ./scripts/ to container root / +# Copy the health check script COPY ./scripts/health_check.sh /health_check.sh RUN chmod +x /health_check.sh -# Add the health check -HEALTHCHECK CMD /health_check.sh || exit 1 - # Start supervisord as the main command CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] + +# Add healthcheck +HEALTHCHECK CMD /health_check.sh || exit 1 diff --git a/README.md b/README.md index 90063d3..5d88a40 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,95 @@ - Need to add setup_end_device.sh - Need to dockerize service - Possibly may need to bridge docker xbnet network with local wifi interface as well -- Make a submodule of xbnet, or copy over raw files, depending on future decisions \ No newline at end of file +- Make a submodule of xbnet, or copy over raw files, depending on future decisions + + +--- +  +  + + +# SERVICES-XBEE-NET + +This project contains a Dockerized setup to create and manage an XBee network using the `xbnet` utility. The network interface is bridged with a host Wi-Fi interface, enabling internet access for connected devices. + +## File Structure +``` +services-xbee-net/ +├── scripts/ +│ ├── entrypoint.sh # Entrypoint script for Docker container +│ ├── get_connected_wifi_info.sh # Script to fetch connected Wi-Fi device information +│ ├── health_check.sh # Script to perform health checks on the container +│ ├── setup_end_device.sh # Script to set up the XBee end device +│ ├── setup_host_device.sh # Script to set up the XBee host device +│ ├── test.sh # Script to run tests +├── tests/ # Directory for testing-related scripts and files +├── xbnet/ # The xbnet source code directory +├── .env # Environment variables for the Docker setup +├── .gitignore # Git ignore file +├── docker-compose-run-multiple.yml # Docker Compose file to run multiple instances +├── docker-compose.yml # Main Docker Compose file +├── Dockerfile # Dockerfile to build the Docker image +├── README.md # Project documentation +└── supervisord.conf # Supervisor configuration file +``` + +## Prerequisites + +Ensure Docker and Docker Compose are installed on your machine. + +## Getting Started + +### 1. Clone the Repository + +```bash +git clone https://github.com/your-username/services-xbee-net.git +cd services-xbee-net +``` + +### 2. Modify the `.env` File + +The `.env` file contains the configuration parameters for the XBee network. You may need to update these parameters according to your specific setup. +- For a single xbnet setup, modify all the `XBEE0` params only +- For multi xbnet setup, add similar config chunks like `XBEE1` +#### (Note: Multi node xbnet setup is currently under progress) + +```bash +# Configuration for xbnet0 +XBEE0_PORT=/dev/ttyUSB0 # The serial port for the XBee device +XBEE0_BAUDRATE=230400 # Baud rate for the XBee device +XBEE0_NET_SRC_IP=192.168.1.10 # Source IP for the XBee network +XBEE0_NET_DST_IP=192.168.1.11 # Destination IP for the XBee network +XBEE0_NET_IFACE_NAME=xbnet0 # Interface name for the XBee network + +# Configuration for xbnet1 +XBEE1_PORT=/dev/ttyUSB1 +XBEE1_BAUDRATE=230400 +XBEE1_NET_SRC_IP=192.168.1.11 +XBEE1_NET_DST_IP=192.168.1.10 +XBEE1_NET_IFACE_NAME=xbnet1 +``` + +### 3. Build and Start the Docker Container + +To build the Docker image and start the container, run: + +```bash +docker-compose -f docker-compose.yml up --build +``` + +This will build the Docker image and start the container with the XBee network and the required setup. + +### 4. Health Check and Container Management + +The container includes a health check that pings the XBee network interface to ensure it is functioning properly. The container is configured to restart automatically if the health check fails. + +### 5. Troubleshooting + +Ensure the XBee devices are connected to the correct serial ports. +Verify the network interfaces using ip a inside the container. +The container logs can be viewed using: + +```bash +docker logs xbee_node +``` \ No newline at end of file diff --git a/entrypoint.sh b/scripts/entrypoint.sh similarity index 98% rename from entrypoint.sh rename to scripts/entrypoint.sh index d3d2aaf..8dab520 100644 --- a/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash # Source the get_connected_wifi_info.sh script -source ./scripts/get_connected_wifi_info.sh +source ./get_connected_wifi_info.sh # Check if the script is running with root privileges check_root() {