2026年2月26日 星期四

Raspberry Pi4 與小龍蝦 openclaw 的連接問題 (應用 telegram)

首先在raspberryPi4安裝Openclaw
# 更新系統
sudo apt update && sudo apt upgrade -y
sudo apt install -y git curl build-essential
# 安裝 Node.js 22
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs
# 安裝 openclaw
curl -fsSL https://openclaw.ai/install.sh | bash

安裝完後接著去設定telegram的APP
這些網路上教學很多可參考!!

以下是我安裝完後跟 telegram 在溝通時的問題與解決方法!!
問題1. 在telegram上下 /start 沒有回應
很多 Pi 都是卡 IPv6。
sudo nano /etc/dhcpcd.conf
在最後一行添加noipv6
sudo nano /boot/firmware/cmdline.txt
在最後一行添加ipv6.disable=1
然後在/home/pi/.openclaw的openclaw.json修改
"channels": {
    "telegram": {
      "enabled": true,
      "dmPolicy": "open",
      "botToken": "your telegram token",
      "allowFrom": [
        "*"
      ],
      "groupPolicy": "allowlist",
      "streaming": "partial"
    }
  },
  "gateway": {
    "port": 18789,
    "mode": "local",
    "bind": "lan",
    "controlUi": {
      "enabled": true,
      "allowedOrigins": [
        "http://192.168.1.41:port",
        "http://192.168.1.104:port"
      ]
    },

問題2. ⚠️ API rate limit reached. Please try again later. (rate_limit)
這個問題出在telegram 下指令給 openclaw時, 去找尋答案時還是會用到 model上的token
所以要執行順利一點還是要花點錢!!





應用例:從telegram下達指令, 透過 openclaw 來控制raspberryPi的IO做家電控制
在/home/pi/.openclaw/workspace建立skills目錄跟skills/gpio-control
/home/pi/.openclaw/workspace/skills/gpio-control













led_control.py
import RPi.GPIO as GPIO
import sys

def set_led(pin, state):
    GPIO.setmode(GPIO.BCM) # 使用 BCM 編號
    GPIO.setup(pin, GPIO.OUT)
    if state == "on":
        GPIO.output(pin, GPIO.HIGH)
        print(f"Pin {pin} is now ON")
    else:
        GPIO.output(pin, GPIO.LOW)
        print(f"Pin {pin} is now OFF")
    # 注意:在 AI 持續控制場景下,通常不立即執行 GPIO.cleanup()
    # 以免狀態重置,但在程式退出前應呼叫。

if __name__ == "__main__":
    # 從命令列接收參數:python led_control.py 17 on
    pin_num = int(sys.argv[1])
    target_state = sys.argv[2]
    set_led(pin_num, target_state)
skill.json
{
  "name": "control_raspberry_pi_gpio",
  "description": "控制樹莓派的 GPIO 針腳開關(例如開關燈或馬達)",
  "parameters": {
    "type": "object",
    "properties": {
      "pin": { "type": "number", "description": "GPIO 針腳編號 (BCM)" },
      "state": { "type": "string", "enum": ["on", "off"], "description": "開啟或關閉" }
    },
    "required": ["pin", "state"]
  },
  "handler": "python3 path/to/led_control.py {{pin}} {{state}}"
}















沒有留言:

張貼留言