LoRa / Meshtastic 対応羊カウンター — デプロイガイド

GitHub でソースを見る
プリセット

LoRa Gateway (Full System)

Count sheep at the gate and see real-time totals on your phone and in a Home Assistant dashboard — even on an off-grid farm with no WiFi in the field.

DevicePurpose
reCamera 2002Runs YOLO sheep detector and gate-crossing counter
XIAO ESP32-S3 + Wio-SX1262LoRa transmitter node (Meshtastic firmware)
reComputer R1100 / Raspberry PiGateway — bridges LoRa messages to MQTT and Home Assistant

What you'll get:

  • Automatic IN / OUT / INSIDE sheep counts every time an animal crosses the gate
  • LoRa heartbeat every 15 minutes to keep all displays in sync
  • Real-time Home Assistant dashboard with daily totals and trend history
  • Works off-grid — only the gateway computer needs a LAN connection to HA

Requirements: reCamera connected via USB or Ethernet · XIAO ESP32-S3 with Wio-SX1262 LoRa board · reComputer or Raspberry Pi running Home Assistant on the local network


1

Deploy Sheep Counter to reCamera

Deploy the sheep counter to your reCamera; it starts automatically on boot.

配線
  1. Connect reCamera to your computer via USB-C or Ethernet
  2. Connect the XIAO ESP32-S3 LoRa node to reCamera's UART port (/dev/ttyS3):
    • XIAO TX → reCamera RX
    • XIAO RX → reCamera TX
    • Shared GND
  3. Enter your reCamera IP address (USB default: 192.168.42.1) and SSH password
トラブルシューティング
IssueSolution
SSH connection failedCheck cable; try password recamera.2 if recamera doesn't work
Counter exits immediatelyCheck /var/log/sheep_counter.log, then run /etc/init.d/S85sscma-keepalive restart
No log output after 2 minEnsure SSCMA inference daemon is running: /etc/init.d/S85sscma-keepalive start
No UART events reaching XIAOConfirm XIAO GND is shared with reCamera; check wiring on /dev/ttyS3

デプロイ後

Deployment stops the reCamera's default Node-RED service. After deployment, SSH into the camera and tail the log to confirm it's running:

ssh recamera@192.168.42.1
tail -f /var/log/sheep_counter.log

You should see detection events like EVT,IN,1,0,1,123 appearing when sheep cross the gate line.

2

Configure the XIAO LoRa Transmitter

Flash Meshtastic firmware to the XIAO ESP32-S3 and configure it to act as a Serial + Detection Sensor node.

配線
  1. Connect the XIAO ESP32-S3 to your computer via USB-C
  2. Open the Meshtastic Web Flasher in Chrome/Edge
  3. Select XIAO ESP32-S3 as the target device and flash the latest stable Meshtastic firmware
  4. After flashing, open the Meshtastic Web Client to configure:
    • Serial Module → Enable → Baud Rate: 115200 → Receive mode: passthrough
    • Detection Sensor Module → Enable → Monitor GPIO: 490 → Detection high → Alert message prefix: SHEEP
    • Set a unique Node name (e.g. SheepGate1) so you can identify it on the mesh
  5. Pair the XIAO with a Meshtastic-compatible LoRa receiver (phone app or local node)
トラブルシューティング
IssueSolution
Flasher can't detect XIAOHold BOOT while plugging in USB; release after the port appears
No messages on the meshCheck RF frequency matches all mesh nodes; confirm channel preset is the same
Serial data arrives garbledConfirm baud rate is 115200 on both the XIAO Serial Module and the reCamera UART
GPIO alerts not firingVerify the sheep_counter binary is sending a ~0.5 s pulse on GPIO 490 on each crossing

デプロイ後

Once configured, trigger a test crossing by briefly pulling GPIO 490 HIGH. You should see:

  • A "SHEEP" alert on your Meshtastic phone app within 30 seconds
  • The raw EVT,IN,... line appearing in your Meshtastic channel as a text message
3

Deploy Gateway Bridge to reComputer

Deploy the bridge services to your local gateway computer. They publish the sheep counts received over LoRa to Home Assistant via MQTT.

Before you start, ensure Home Assistant is running on your LAN and its MQTT integration is connected to the same broker with discovery enabled. You will enter the gateway SSH connection, MQTT broker IP, and Meshtastic receiver serial port in the deploy form.

配線
  1. Connect the LoRa receiver node (a second Meshtastic device, e.g. reComputer serial or a plugged-in USB Meshtastic radio) to the gateway computer
トラブルシューティング
IssueSolution
meshtastic-bridge not startingConfirm the Meshtastic USB radio is plugged into the gateway; check journalctl -u meshtastic-bridge
ha-bridge fails to connectConfirm the MQTT broker IP is reachable on port 1883 and accepts the gateway connection
No MQTT messagesVerify the MQTT broker IP and that the broker accepts unauthenticated connections on port 1883
Services stop on rebootRun systemctl enable meshtastic-bridge ha-bridge to re-enable

デプロイ後

After deployment, verify the systemd services are healthy:

ssh recomputer@<gateway-ip>
systemctl status meshtastic-bridge ha-bridge

Both should show active (running).

Import the ha_dashboard.yaml file into Home Assistant:

  1. Copy assets/gateway/ha_dashboard.yaml from this solution package to your HA config directory (or use /opt/sheep-gateway/ha_dashboard.yaml if the gateway scripts were already deployed)
  2. In HA: Settings → Dashboards → Import → select the file
4

Open Sheep Counter Dashboard

The full system is now running. Click below to open the Home Assistant sheep counter dashboard and confirm live counts are coming in.

トラブルシューティング
IssueSolution
Dashboard page shows no dataConfirm ha-bridge is running, MQTT discovery is enabled in HA, and the sensor.sheep_* entities exist
Counts not updatingTrigger a manual crossing; check MQTT traffic with mosquitto_sub -t sheep/# -v
HA entities show unavailableRe-import the ha_dashboard.yaml and restart the ha-bridge service
デプロイ後

Your sheep counter is live! On the dashboard you will see:

  • IN / OUT / INSIDE — real-time counters since the last dashboard reset
  • Last event time — timestamp of the most recent gate crossing
  • Daily history — 24-hour trend graph

Quick Verification

  1. Wave your hand in front of the camera (or walk past the gate line) to simulate a crossing
  2. Watch the EVT,IN,... line appear in /var/log/sheep_counter.log on the reCamera
  3. Within ~30 s, the IN counter should increment on the HA dashboard

Tips

  • Mount reCamera at an angle to the gate so sheep cross the virtual line cleanly
  • Adjust the gate-line position in the counter config if your crossing rate is low
  • The LoRa heartbeat (HB messages every 15 min) keeps displays in sync after radio gaps

Next Steps