docker-compose-env-var-test #1
|
@ -38,5 +38,9 @@ RUN chmod +x /set-env-vars.sh
|
|||
COPY ./scripts/health-check.sh /health-check.sh
|
||||
RUN chmod +x /health-check.sh
|
||||
|
||||
# TEST
|
||||
COPY ./scripts/debug/host-setup-docker.sh /host-setup-docker.sh
|
||||
RUN chmod +x /host-setup-docker.sh
|
||||
|
||||
# Add healthcheck
|
||||
HEALTHCHECK CMD /health-check.sh || exit 1
|
||||
|
|
|
@ -9,7 +9,18 @@ services:
|
|||
- XBEE_INDEX=1
|
||||
- XBEE_BAUDRATE=230400
|
||||
- XBEE_PORT=/dev/ttyUSB0
|
||||
- XBNET_BASE_SUBNET=2.2.2
|
||||
- XBNET_BASE_SUBNET=172.18.0
|
||||
- XBNET_INTERFACE_TYPE=router
|
||||
- XBNET_PROTO=tap
|
||||
command: bash /entrypoint.sh
|
||||
- XBNET_PROTO=tun
|
||||
command: bash /entrypoint.sh
|
||||
networks:
|
||||
eth0:
|
||||
ipv4_address: 172.18.0.100
|
||||
|
||||
networks:
|
||||
# Assigning a static IP to eth0 interface, so that it stays the same everytime the container is started
|
||||
eth0:
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.18.0.0/24
|
||||
gateway: 172.18.0.1
|
|
@ -0,0 +1,44 @@
|
|||
#!/bin/sh -e
|
||||
# IP forwarding and NAT rules
|
||||
|
||||
# Default host IP
|
||||
HOST_IP=""
|
||||
|
||||
# Parse command line argument for --host-ip
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
--host-ip=*)
|
||||
HOST_IP="${arg#*=}"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown argument: $arg"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# If HOST_IP is not set, fetch the IP address of the eth0 interface
|
||||
if [ -z "$HOST_IP" ]; then
|
||||
HOST_IP=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
|
||||
if [ -z "$HOST_IP" ]; then
|
||||
echo "Error: Could not retrieve IP from eth0"
|
||||
exit 1
|
||||
fi
|
||||
echo "No --host-ip provided. Using eth0 IP: $HOST_IP"
|
||||
else
|
||||
echo "Using provided --host-ip: $HOST_IP"
|
||||
fi
|
||||
|
||||
# Enable IP forwarding
|
||||
echo 1 > /proc/sys/net/ipv4/ip_forward
|
||||
|
||||
# Set iptables rules for NAT and forwarding
|
||||
iptables -t nat -A POSTROUTING -s 2.2.2.0/24 -o eth0 -j MASQUERADE
|
||||
iptables -A FORWARD -i xbnet_router_1 -o eth0 -j ACCEPT
|
||||
iptables -A FORWARD -i eth0 -o xbnet_router_1 -m state --state RELATED,ESTABLISHED -j ACCEPT
|
||||
|
||||
# Ensure the xbnet_router_1 interface has a default route through eth0
|
||||
ip route add default via $(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') dev xbnet_router_1
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,18 @@
|
|||
import serial
|
||||
import subprocess
|
||||
|
||||
# Set up serial connection (adjust serial port to match your configuration)
|
||||
ser = serial.Serial('/dev/ttyUSB0', 230400)
|
||||
|
||||
# Function to send command to XBee
|
||||
def send_command(command):
|
||||
ser.write((command + '\r\n').encode())
|
||||
|
||||
# Function to ping from the Raspberry Pi
|
||||
def ping_address(address):
|
||||
response = subprocess.run(['ping', '-c', '5', address], capture_output=True)
|
||||
return response.stdout.decode()
|
||||
|
||||
# Example usage
|
||||
send_command('Hello XBee') # Sending data to XBee
|
||||
print(ping_address('8.8.8.8')) # Pinging Google DNS from Pi
|
|
@ -36,7 +36,7 @@ loop() {
|
|||
fi
|
||||
|
||||
# Log messages sent and received over xbnet
|
||||
# log_xbnet_messages
|
||||
log_xbnet_messages
|
||||
|
||||
sleep 0.5
|
||||
done
|
||||
|
@ -72,11 +72,14 @@ create_tap_interface() {
|
|||
done
|
||||
|
||||
# Create and bring up xbnet interface
|
||||
ip route add default via 172.18.0.1 dev $XBNET_INTERFACE_NAME
|
||||
ip addr add $XBNET_IP/24 dev $XBNET_INTERFACE_NAME
|
||||
ip link set $XBNET_INTERFACE_NAME up
|
||||
ip link show $XBNET_INTERFACE_NAME
|
||||
ip addr show $XBNET_INTERFACE_NAME
|
||||
|
||||
echo "---------------------------------------------------------"
|
||||
echo "***************** Tap interface created *****************"
|
||||
echo "************ ${XBNET_PROTO} interface created ************"
|
||||
echo "---------------------------------------------------------"
|
||||
echo "XBEE_INDEX : ${XBEE_INDEX}"
|
||||
echo "XBEE_BAUDRATE : ${XBEE_BAUDRATE}"
|
||||
|
@ -84,6 +87,7 @@ create_tap_interface() {
|
|||
echo "XBNET_BASE_SUBNET : ${XBNET_BASE_SUBNET}"
|
||||
echo "XBNET_IP : ${XBNET_IP}"
|
||||
echo "XBNET_INTERFACE_NAME : ${XBNET_INTERFACE_NAME}"
|
||||
echo "XBNET_PROTO : ${XBNET_PROTO}"
|
||||
echo "XBNET_DEFAULT_GATEWAY : ${XBNET_DEFAULT_GATEWAY}"
|
||||
echo "XBNET_DEFAULT_IPVLAN_IP : ${XBNET_DEFAULT_IPVLAN_IP}"
|
||||
echo "XBNET_DEFAULT_MACVLAN_IP : ${XBNET_DEFAULT_MACVLAN_IP}"
|
||||
|
@ -154,9 +158,9 @@ log_packet_info() {
|
|||
length=$(cat /sys/class/net/$XBNET_INTERFACE_NAME/statistics/tx_bytes)
|
||||
echo "Length: ${length} bytes"
|
||||
|
||||
# Placeholder for payload (not feasible to extract without raw packet inspection)
|
||||
echo "Payload: [Payload extraction requires raw packet inspection tools]"
|
||||
echo "******************************************************************"
|
||||
# # Placeholder for payload (not feasible to extract without raw packet inspection)
|
||||
# echo "Payload: [Payload extraction requires raw packet inspection tools]"
|
||||
# echo "******************************************************************"
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue