Pi ağ geçidime seri konsol escape kodlarını renk yerine gösteriyor ve htop bozuk görünüyor
Yapay zekâ tarafından English dilinden çevrildi ·
Yine ben (tavuk kümesindeki amonyak meselesinin sahibi). Kümes Pi’si artık küçük bir ağ geçidi olarak çalışıyor: NH3 sensörünü ve iki sıcaklık probunu okuyup Hermetry’ye yayınlıyor. Kulübedeki Wi-Fi çok zayıf, bu yüzden bağlantı koptuğunda CP2102 USB-TTL kablosunu Pi’nin GPIO UART’ına takıyorum ve dizüstü bilgisayarımda 115200 hızında PuTTY kullanıyorum.Girişi çalışıyor, ancak ağ geçidi betiğim renkli log satırları yazdırıyor ve seri bağlantıda şuna benzer çıktılar görüyorum:
^[[32mINFO^[[0m published nh3_ppm=9.1
^[[33mWARN^[[0m wifi reconnect (3)
Ayrıca PuTTY pencerem tam ekran olsa bile htop bozuk çiziyor ve 80 sütunda satır atlıyor. SSH üzerinden ikisi de mükemmel görünüyor. Seri bağlantı gerçekten bu kadar mı sınırlı?
Me again (chicken coop ammonia person). The coop Pi now runs as a small gateway: reads the NH3 sensor and two temperature probes and publishes to Hermetry. The Wi-Fi out in the shed is terrible, so when it drops I plug a CP2102 USB-TTL cable into the Pi’s GPIO UART and use PuTTY on my laptop at 115200.
Logging in works, but my gateway script prints coloured log lines and over serial I get stuff like:
^[[32mINFO^[[0m published nh3_ppm=9.1
^[[33mWARN^[[0m wifi reconnect (3)
And htop draws garbage and wraps at 80 columns even with a maximised PuTTY window. Over SSH both look perfect. Is serial just limited like that?
Yapay zekâ tarafından English dilinden çevrildi ·
PuTTY yerine picocom’u denediniz mi? PuTTY’nin seri bağlantıda her zaman tuhaf davrandığını düşünmüşümdür.
Try picocom instead of PuTTY? I always found PuTTY weird on serial.
Yapay zekâ tarafından English dilinden çevrildi ·
Linux makinemdeki picocom ile de aynı şey oluyor, denedim.
Same thing in picocom from my Linux box, I tried.
Yapay zekâ tarafından English dilinden çevrildi ·
Sorun terminal programında değil, Pi tarafında. SSH’nin bedavaya sağladığı iki şey seri girişte eksik.Terminal türü: SSH, TERM değerinizi iletir (PuTTY’den xterm-256color). Seri getty ise TERM’i vt220 olarak ayarlar; bunda renk yoktur, bu yüzden TERM’e bakan programlar geri döner ya da ham kodlar basar. echo $TERM ile kontrol edin.Pencere boyutu: Seri hat, Pi’ye pencerenizin boyutunu bildirmenin bir yolunu sunmaz; bu yüzden 80×24 varsayar ve hiç değişmez.Konsola bağlandığım her makinede bunu ~/.bashrc dosyasına koydum:
case "$(tty)" in
/dev/ttyS0|/dev/ttyAMA0|/dev/serial0)
export TERM=xterm-256color
stty rows 50 cols 160 # match your PuTTY window
;;
esac
xterm paketini kurarsanız boyutu sabit kodlamak yerine resize yazabilirsiniz; terminale sorar ve ayarlar.Betiğinizin renkleri, günlük kütüphanesi TERM’i kontrol ediyorsa çalışacaktır.
It’s the Pi side, not the terminal program. Two things are missing on a serial login that SSH gives you for free.
The terminal type: SSH passes your TERM along (xterm-256color from PuTTY). The serial getty sets TERM to vt220, which has no colour, so programs that check TERM fall back or print raw codes. Check with echo $TERM.
The window size: there’s no way for the serial line to tell the Pi how big your window is, so it assumes 80×24 and never changes.
I put this in ~/.bashrc on every box I console into:
case "$(tty)" in
/dev/ttyS0|/dev/ttyAMA0|/dev/serial0)
export TERM=xterm-256color
stty rows 50 cols 160 # match your PuTTY window
;;
esac
If you install the xterm package you can type resize instead of hardcoding the size, it asks the terminal and sets it.
Your script’s colours will then work, assuming the logging library checks TERM.
Yapay zekâ tarafından English dilinden çevrildi ·
Not: Aynı betik bir servis olarak çalıştığında günlükleri journald’a da yazıyor ve journal içindeki renk kodları can sıkıcı. Çoğu günlükleme kütüphanesi, stdout bir tty değilken rengi kapatmanıza izin verir.
Side note: the same script also logs to journald when it runs as a service, and colour codes in the journal are annoying. Most logging libs let you turn colour off when stdout isn’t a tty.
Yapay zekâ tarafından English dilinden çevrildi ·
+1 bashrc parçasına, bizim geçitlerde de aynı. htop’ta kutu çizim karakterleri bozuluyorsa oraya export LANG=C.UTF-8 satırını da eklerdim.
+1 to the bashrc snippet, same on our gateways. I’d add export LANG=C.UTF-8 there too if you see box-drawing characters break in htop.
Yapay zekâ tarafından English dilinden çevrildi ·
TERM tam olarak vt220 idi. bashrc bloğunu ekledikten sonra artık seri bağlantı üzerinden renkler ve tam genişlikte htop çalışıyor. Ayrıca Eric’in önerisini de ekledim; servis renksiz çalışıyor, böylece journal temiz kalıyor. Herkese teşekkürler!
TERM was vt220, exactly. With the bashrc block it’s colours and a full-width htop over serial now. I also added Eric’s tip, the service runs with colour off so the journal is clean. Thanks all!
- Bu konuyu yanıtlamak için giriş yapmış olmalısınız.
Sohbete katılın
Soru sormak ve yanıtlamak, yararlı gönderileri beğenmek ve sorununuzu çözen yanıtı işaretlemek için oturum açın. Her katkı puan ve seviye kazandırır.

