2018年7月20日 星期五

備份 Raspberry Pi 時SD卡容量不相符的解決方式

備份回復 rpi image 的時候有時會遇到 sd card 雖號稱一樣 g 數,但實際大小卻不一樣,導致回復時出問題,此時可以用底下 scripts 解決,先把檔案變小就好解決… (linux 環境下)

Shrink your Raspberry Pi SD Card Image size

https://github.com/Drewsif/PiShrink

Very Nice !!


硬體從 rpi2 改到 rpi3
舊 SDCard 無法順利在 rpi3 開機的問題

apt-get install rpi-update
rpi-update

2018年7月1日 星期日

mqtt@RaspberryPi

broker / server / client library install...
# 安裝 broker 及 所需函式庫

sudo apt-get install mosquitto mosquitto-clients
sudo apt-get install python3-pip
sudo pip3 install paho-mqtt

fix python search path...
# poah 安裝路徑若 python 找不到要作修正

cd /usr/lib/python2.7/dist-packages
sudo ln -s /usr/local/lib/python3.5/dist-packages/paho


subscribe...
# Subscribe 訂閱訊息/接收訊息

import paho.mqtt.client as mqtt 
def on_connect(client, userdata, flags, rc):
  print("Connected with result code "+str(rc))
  client.subscribe("where/is/my/topic") 

def on_message(client, userdata, msg):
  print(msg.topic+" "+str(msg.payload)) 

client = mqtt.Client()
client.on_connect = on_connect    #call back function
client.on_message = on_message    #call back function
client.connect("localhost", 1883, 60)
client.loop_forever()

pubilsh...
# Publisher 發佈訊息

import paho.mqtt.publish as publish
# publish a message then disconnect.

host = "localhost"
topic = "where/is/my/topic"
payload = "hello"

# If broker asks user/password.
auth = {'username': "", 'password': ""}

# If broker asks client ID.
client_id = ""

publish.single(topic, payload, qos=1, hostname=host)
#publish.single(topic, payload, qos=1, host=host, auth=auth, client_id=client_id)




更高效處理 micro second 的方式

更高效處理 micro second 的方式…  以 STM32 為例… __IO unsigned long sys_tick = 0; void SysTick_Handler(void) {     HAL_IncTick();     sys_tick += (SysTi...