LoRa düğümümden gelen negatif sıcaklıklar Hermetry'de 65486 olarak görünüyor
Yapay zekâ tarafından English dilinden çevrildi ·
Backend geliştiricisiyim, ilk LoRaWAN düğümüm ve kendimi aptal hissediyorum.Arduino Pro Mini + RFM95, LMIC, OTAA ile Hermetry’ye, EU868. Bir DS18B20’den gelen sıcaklığı iki bayt olarak gönderiyor, değer 100 ile çarpılmış:
int t = (int)(tempC * 100);
payload[0] = t >> 8;
payload[1] = t & 0xFF;
Kendi codec’imi yazdım (düzen örneğini kopyaladım, fmt: "u16be", scale: 0.01). Sonbahar boyunca sorunsuz çalıştı. Dün gece kulübede sıcaklık sıfırın altına düştü ve grafik 654.86’ya fırladı. Frame günlüğünde bu uplink için FF CE görünüyor.İki bayt nasıl negatif bir sayıya dönüşebilir? Baytların yalnızca 0 ile 255 arasında olduğunu düşünmüştüm.
Backend dev, first LoRaWAN node, and I feel silly.
Arduino Pro Mini + RFM95, LMIC, OTAA into Hermetry, EU868. It sends temperature from a DS18B20 as two bytes, value times 100:
int t = (int)(tempC * 100);
payload[0] = t >> 8;
payload[1] = t & 0xFF;
I wrote my own codec (copied the layout example, fmt: "u16be", scale: 0.01). Worked all autumn. Last night it went below zero in the shed and the chart jumped to 654.86. The frames log shows FF CE for that uplink.
How do two bytes turn into a negative number at all? I thought bytes were just 0 to 255.
Yapay zekâ tarafından English dilinden çevrildi ·
Açıkçası aynı soru. İşaretin nasıl saklandığını hiç anlamadım.
Same question honestly, I never understood how the sign is stored.
Yapay zekâ tarafından English dilinden çevrildi ·
Ha, geçen Ocak ayında sera sensörümle tam olarak bunu yaşamıştım, bu sefer cevap verebilirim!Arduino int değerini iki tümleyen biçiminde saklar. -0,5 °C çarpı 100 eder -50, ve -50 değeri 16 bitte 0xFFCE olur. En üst bit işaret bitidir. İşaretsiz okunursa 65486 eder, 0,01 ile çarpınca 654,86 çıkar. İşaretli okunursa -50 eder, 0,01 ile çarpınca -0,5 çıkar. Baytlar aynı, codec’in bunların işaretli olduğunu bilmesi yeterli.Bu durumda codec’inizde formatı u16be‘den i16be‘ye değiştirin, ölçeği koruyun. Negatif bir değer için bir test vektörü ekleyin ki bu hata geri gelmesin:
{ "at": 0, "field": "temperature", "fmt": "i16be", "scale": 0.01, "unit": "°C" }
"tests": [
{ "name": "positive", "fport": 1, "hex": "0960", "expect": { "temperature": 24.0 } },
{ "name": "below zero", "fport": 1, "hex": "FFCE", "expect": { "temperature": -0.5 } }
]
Arduino tarafında, 32 bitlik bir karta geçerseniz 2 bayt kalsın diye int yerine int16_t kullanın. Sonra Check ve Publish’e basın. Anahtar adı ve birim aynı kaldığı için aynı codec’in yeni bir revizyonu olarak yayınlanabilir. Referans: Write your own codec
Ha, I had exactly this with my greenhouse sensor last January, so I can answer for once!
The Arduino stores int as two’s complement. -0.5 °C times 100 is -50, and -50 in 16 bits is 0xFFCE. The top bit is the sign. Read as unsigned that’s 65486, times 0.01 gives your 654.86. Read as signed it’s -50, times 0.01 gives -0.5. Same bytes, the codec just has to know they’re signed.
So in your codec change the format from u16be to i16be, keep the scale. Add a test vector for a negative value so it never sneaks back:
{ "at": 0, "field": "temperature", "fmt": "i16be", "scale": 0.01, "unit": "°C" }
"tests": [
{ "name": "positive", "fport": 1, "hex": "0960", "expect": { "temperature": 24.0 } },
{ "name": "below zero", "fport": 1, "hex": "FFCE", "expect": { "temperature": -0.5 } }
]
On the Arduino side use int16_t instead of int, so it stays 2 bytes if you move to a 32-bit board. Then Check and Publish. The key name and unit stay the same, so it can go out as a new revision of the same codec. Reference: Write your own codec
Yapay zekâ tarafından English dilinden çevrildi ·
Düzeltmeden önce kaydedilen okumalar yanlış değeri korur; o gece önemliyse, dışa aktarın ve elle düzeltin.
The readings stored before the fix keep the wrong value, so if that night matters, export it and correct it by hand.
Yapay zekâ tarafından English dilinden çevrildi ·
Veri i16be ile yeniden yayınlandı, iki test vektörü de geçiyor ve bu gecekiki uplink’ler yanındaki termometre gibi -1.25 ve -1.5 gösteriyor. Taslağı da int16_t olarak değiştirdim. Dünkü iki yanlış noktayı hatırlatma olarak grafikte bırakacağım 😅
Republished with i16be, both test vectors pass, and tonight’s uplinks show -1.25 and -1.5 like the thermometer next to it. Changed the sketch to int16_t too. I’ll leave last night’s two wrong points in the chart as a reminder 😅
- 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.

