{{ :elektronik:lora_temperatursensor:header.jpg?nolink&3000 |}} ====== LoRa-Temperatursensor ====== Einen Temperatursensor ansteuern gehört zu den ersten Dingen, die man normalerweise mit einem Mikrocontroller macht. Allerdings meist mit USB als Stromversorgung. In diesem Projekt wird der Temperatursensor allerdings mit Akku und Solarzelle versorgt und sendet die Messergebnisse mehrere Kilometer weit über LoRa (TTN). Die Daten werden dann in einen ioBroker gesammelt. ++++ Informationen zu TTN und ioBroker | {{wp:de>The Things Network}} {{wp:de>ioBroker}} ++++ Der Temperatursensor soll auf einem Gartengrundstück angebracht werden und die Temperatur, die Luftfeuchte und den Luftdruck etwas abseits des Ortes messen. Für das TTN betreibe ich ein eigenes Gateway mit einem Raspberry Pi, ic880a und Außenantenne. ===== Hardware ===== ==== Komponenten ==== - [[https://www.amazon.de/dp/B07KWSLCWM|OxyLED Solar Lichterkette Außen, 100 LED Lichterkette (Amazon.de)]] - Arduino Pro Mini (entfernte LED + Spannungsregler, siehe [[http://www.home-automation-community.com/arduino-low-power-how-to-run-atmega328p-for-a-year-on-coin-cell-battery/|hier]]) - RFM95W (868 MHz) - BME280-Modul (ohne Spannungsregler) für Temperatur, Luftfeuchtigkeit und Luftdruck - [[https://www.aliexpress.com/item/4000275661046.html|BL8530 BL8531 DC-DC Boost Converter Module]] (0,8 V zu 3,3 V) - diverser Kleinkram (XT60 Stecker, Kabel, Gehäuse, etc.) ==== Schaltung ==== {{:elektronik:lora_temperatursensor:schaltung.svg?50x50&units:%|}} ==== Energie-Optimierung ==== Wie sich im folgendem Diagramm zeigt hatte die Übertragung immer wieder Aussetzer. Je nach Sonneneinstrahlung wurde am Tag mehr oder weniger gesendet. Das ist natürlich nicht der Sinn des Wettersensors. Die Batterie sollte die komplette Nacht sicher überbrücken können. { series: [{ name: "Anzahl der Daten", data: [[1603180800000,8], [1603184400000,19], [1603188000000,12], [1603191600000,14], [1603195200000,18], [1603198800000,18], [1603202400000,18], [1603206000000,18], [1603209600000,16], [1603213200000,17], [1603216800000,16], [1603220400000,18], [1603224000000,18], [1603227600000,18], [1603231200000,18], [1603234800000,19], [1603238400000,18], [1603242000000,18], [1603245600000,18], [1603249200000,11], [1603252800000,19], [1603256400000,18], [1603260000000,18], [1603263600000,18], [1603267200000,18], [1603270800000,19], [1603274400000,18], [1603278000000,18], [1603281600000,18], [1603285200000,17], [1603288800000,18], [1603292400000,18], [1603296000000,19], [1603299600000,18], [1603303200000,18], [1603306800000,18], [1603310400000,18], [1603314000000,17], [1603317600000,19], [1603321200000,18], [1603324800000,18], [1603328400000,18], [1603332000000,18], [1603335600000,13], [1603339200000,19], [1603342800000,18], [1603346400000,18], [1603350000000,18], [1603353600000,18], [1603357200000,18], [1603360800000,19], [1603364400000,18], [1603368000000,18], [1603371600000,18], [1603375200000,18], [1603378800000,18], [1603382400000,18], [1603386000000,19], [1603389600000,18], [1603393200000,18], [1603396800000,18], [1603400400000,18], [1603404000000,17], [1603407600000,19], [1603411200000,17], [1603414800000,18], [1603418400000,18], [1603422000000,9], [1603425600000,16], [1603429200000,18], [1603432800000,18], [1603436400000,18], [1603440000000,18], [1603443600000,18], [1603447200000,18], [1603450800000,18], [1603454400000,18], [1603458000000,18], [1603461600000,18], [1603465200000,17], [1603468800000,17], [1603472400000,19], [1603476000000,18], [1603479600000,18], [1603483200000,18], [1603486800000,18], [1603490400000,18], [1603494000000,19], [1603497600000,18], [1603501200000,14], [1603504800000,0], [1603508400000,0], [1603512000000,0], [1603515600000,0], [1603519200000,0], [1603522800000,0], [1603526400000,0], [1603530000000,0], [1603533600000,0], [1603537200000,0], [1603540800000,0], [1603544400000,0], [1603548000000,16], [1603551600000,17], [1603555200000,18], [1603558800000,18], [1603562400000,19], [1603566000000,18], [1603569600000,13], [1603573200000,0], [1603576800000,0], [1603580400000,0], [1603584000000,0], [1603587600000,0], [1603591200000,0], [1603594800000,0], [1603598400000,0], [1603602000000,0], [1603605600000,0], [1603609200000,6], [1603612800000,18], [1603616400000,18], [1603620000000,19], [1603623600000,18], [1603627200000,17], [1603630800000,17], [1603634400000,18], [1603638000000,18], [1603641600000,18], [1603645200000,19], [1603648800000,18], [1603652400000,18], [1603656000000,18], [1603659600000,18], [1603663200000,19], [1603666800000,17], [1603670400000,18], [1603674000000,18], [1603677600000,3], [1603681200000,0], [1603684800000,0], [1603688400000,0], [1603692000000,0], [1603695600000,0], [1603699200000,0], [1603702800000,0], [1603706400000,0], [1603710000000,0], [1603713600000,0], [1603717200000,0], [1603720800000,0], [1603724400000,0], [1603728000000,0], [1603731600000,0], [1603735200000,0], [1603738800000,0], [1603742400000,0], [1603746000000,0], [1603749600000,0], [1603753200000,0], [1603756800000,0], [1603760400000,0], [1603764000000,0], [1603767600000,0], [1603771200000,0], [1603774800000,0], [1603778400000,0], [1603782000000,0], [1603785600000,8], [1603789200000,19], [1603792800000,18], [1603796400000,18], [1603800000000,18], [1603803600000,18], [1603807200000,19], [1603810800000,18], [1603814400000,18], [1603818000000,18], [1603821600000,17], [1603825200000,18], [1603828800000,0], [1603832400000,0], [1603836000000,0], [1603839600000,0], [1603843200000,0], [1603846800000,0], [1603850400000,0], [1603854000000,0], [1603857600000,0], [1603861200000,0], [1603864800000,0], [1603868400000,0], [1603872000000,11], [1603875600000,19], [1603879200000,18], [1603882800000,18], [1603886400000,18], [1603890000000,18], [1603893600000,18], [1603897200000,19], [1603900800000,18], [1603904400000,18], [1603908000000,18], [1603911600000,18], [1603915200000,19], [1603918800000,18], [1603922400000,18], [1603926000000,18], [1603929600000,1], [1603933200000,0], [1603936800000,0], [1603940400000,0], [1603944000000,0], [1603947600000,0], [1603951200000,0], [1603954800000,0], [1603958400000,5], [1603962000000,18], [1603965600000,17], [1603969200000,18], [1603972800000,18], [1603976400000,19], [1603980000000,18], [1603983600000,17], [1603987200000,18], [1603990800000,18], [1603994400000,19], [1603998000000,13], [1604001600000,0], [1604005200000,0], [1604008800000,0], [1604012400000,0], [1604016000000,0], [1604019600000,0], [1604023200000,0], [1604026800000,0], [1604030400000,0], [1604034000000,0], [1604037600000,0], [1604041200000,0], [1604044800000,0], [1604048400000,16], [1604052000000,18], [1604055600000,18], [1604059200000,18], [1604062800000,19], [1604066400000,18], [1604070000000,18], [1604073600000,18], [1604077200000,4], [1604080800000,0], [1604084400000,0], [1604088000000,0], [1604091600000,0], [1604095200000,0], [1604098800000,0], [1604102400000,0], [1604106000000,0], [1604109600000,0], [1604113200000,0], [1604116800000,0], [1604120400000,0], [1604124000000,0], [1604127600000,0], [1604131200000,14], [1604134800000,18], [1604138400000,18], [1604142000000,18], [1604145600000,18], [1604149200000,19], [1604152800000,18], [1604156400000,18], [1604160000000,18], [1604163600000,18], [1604167200000,19], [1604170800000,18], [1604174400000,1], [1604178000000,0], [1604181600000,0], [1604185200000,0], [1604188800000,0], [1604192400000,0], [1604196000000,0], [1604199600000,0], [1604203200000,0], [1604206800000,0], [1604210400000,0], [1604214000000,0], [1604217600000,0], [1604221200000,0], [1604224800000,3], [1604228400000,18], [1604232000000,18], [1604235600000,18], [1604239200000,17], [1604242800000,16], [1604246400000,0], [1604250000000,0], [1604253600000,0], [1604257200000,0], [1604260800000,0], [1604264400000,0], [1604268000000,0], [1604271600000,0], [1604275200000,0], [1604278800000,0], [1604282400000,0], [1604286000000,0], [1604289600000,0], [1604293200000,0], [1604296800000,0], [1604300400000,0], [1604304000000,14], [1604307600000,18], [1604311200000,18], [1604314800000,18], [1604318400000,18], [1604322000000,17], [1604325600000,18], [1604329200000,18], [1604332800000,17], [1604336400000,18], [1604340000000,18], [1604343600000,19], [1604347200000,18], [1604350800000,18], [1604354400000,18], [1604358000000,18], [1604361600000,17], [1604365200000,4], [1604368800000,0], [1604372400000,0], [1604376000000,0], [1604379600000,0], [1604383200000,0], [1604386800000,0], [1604390400000,5], [1604394000000,18], [1604397600000,18], [1604401200000,18], [1604404800000,18], [1604408400000,18], [1604412000000,3], [1604415600000,0], [1604419200000,0], [1604422800000,0], [1604426400000,0], [1604430000000,0], [1604433600000,0], [1604437200000,0], [1604440800000,0], [1604444400000,0], [1604448000000,0], [1604451600000,0], [1604455200000,0], [1604458800000,0], [1604462400000,0], [1604466000000,0], [1604469600000,0], [1604473200000,0], [1604476800000,0], [1604480400000,1], [1604484000000,19], [1604487600000,18], [1604491200000,18], [1604494800000,17], [1604498400000,18], [1604502000000,18], [1604505600000,18], [1604509200000,3], [1604512800000,0], [1604516400000,0], [1604520000000,0], [1604523600000,0], [1604527200000,0], [1604530800000,0], [1604534400000,0], [1604538000000,0], [1604541600000,0], [1604545200000,0], [1604548800000,0], [1604552400000,0], [1604556000000,0], [1604559600000,0], [1604563200000,0], [1604566800000,15], [1604570400000,18], [1604574000000,19], [1604577600000,18], [1604581200000,17], [1604584800000,18], [1604588400000,18], [1604592000000,19], [1604595600000,18], [1604599200000,4], [1604602800000,0], [1604606400000,0], [1604610000000,0], [1604613600000,0], [1604617200000,0], [1604620800000,0], [1604624400000,0], [1604628000000,0], [1604631600000,0], [1604635200000,0], [1604638800000,0], [1604642400000,0], [1604646000000,0], [1604649600000,0], [1604653200000,16], [1604656800000,18], [1604660400000,19], [1604664000000,18], [1604667600000,18], [1604671200000,18], [1604674800000,19], [1604678400000,18], [1604682000000,18], [1604685600000,17], [1604689200000,0], [1604692800000,0], [1604696400000,0], [1604700000000,0], [1604703600000,0], [1604707200000,0], [1604710800000,0], [1604714400000,0], [1604718000000,0], [1604721600000,0], [1604725200000,0], [1604728800000,0], [1604732400000,0], [1604736000000,7], [1604739600000,18], [1604743200000,17], [1604746800000,17]] }], chart: { type: 'area', height: 350, zoom: { enabled: false } }, dataLabels: { enabled: false }, stroke: { curve: 'straight' }, title: { text: 'Datenhäufigkeit pro Stunde', align: 'left' }, subtitle: { text: 'vom LoRa-Sensor auf dem Grundstück', align: 'left' }, xaxis: { type: 'datetime', labels: { format: 'dd.MM.yyyy' }, }, yaxis: { opposite: true }, legend: { horizontalAlign: 'left' }, tooltip: { x: { show: true, format: 'dd.MM.yyyy HH:mm', } } } Im Prinzip gibt es zwei Stellschrauben, um den Energieverbrauch zu reduzieren: * Häufigkeit der Datenübertragung * Sendedauer (ergibt sich aus dem Spreading Factor (SF)) Den benötigten SF kann man abschätzen, wenn man den SNR (Signal-Rausch-Verhältnis) hat. [([[https://www.researchgate.net/figure/2-LoRa-Spreading-Factors-Symbol-Rate-SNR-limit-TOA-and-Bit-Rate_tbl2_337243596 | LoRa Spreading Factors, Symbol Rate, SNR limit, TOA and Bit Rate.]] "Module-level Health Monitoring of Solar PV Plants using LoRa Wireless Sensor Networks" von **Arnold Johan Rix**)] ^ Spreading Factor ^ Symbol/sec. ^ SNR limit ^ TOA (10-byte packet) ^ Bit rate ^ | 7 | 976 | -7,5 | 56 ms | 5469 bps | | 8 | 488 | -10,0 | 103 ms | 3125 bps | | 9 | 244 | -12,5 | 205 ms | 1758 bps | | 10 | 122 | -15,0 | 371 ms | 977 bps | | 11 | 61 | -17,5 | 741 ms | 537 bps | | 12 | 30 | -20,0 | 1483 ms | 293 bps | Die beiden Parameter habe ich angepasst: ^ Parameter ^ alt ^ neu ^ Energieverbrauch neu ^ | Spreading Factor (SF) | 12 | 9 | 13,8 % | | Sendeintervall | 3 min | 6 min | 50,0 % | Das Gesamt-Energieersparnis liegt also bei ca. 93 %. Der Energieverbrauch verhält sich proportional zur Sendedauer bzw. dem Sendeintervall. Um die Daten für einen geeigneten SF zu bekommen, habe ich die Rohdaten vom TTN mitgeloggt (siehe auskommentierten Code im ioBroker-Script). Diese Daten musste ich dann noch vorverarbeiten. Dazu habe ich den Notepad++ verwendet und folgendes durchgeführt: * Kopfzeile der CSV entfernt * Ersetzen (im "Reguläre Ausdrücke"-Modus) - Suche **({"gtw_id"[^}]*})** ersetze durch **\r\n$1\r\n** * Ersetzen (im "Reguläre Ausdrücke"-Modus) - Suche **^.{1,5}$\r\n** ersetze durch "leer" * Ersetzen (im "Reguläre Ausdrücke"-Modus) - Suche **^.{200,20000}$\r\n** ersetze durch "leer" * Speichern als .json Diese Datei habe ich dann mit Tableau analysiert (Orange ist mein Gateway). Und zur besseren Darstellung im Wiki nachgebaut. ++++ Tableau-Export | {{:elektronik:lora_temperatursensor:rssi_snr_gateways.svg?150x150&units:%|}} ++++ { annotations: { xaxis: [{ // in a datetime series, the x value should be a timestamp, just like it is generated below x: 1603152000000, strokeDashArray: 0, borderColor: "#775DD0", label: { borderColor: "#775DD0", style: { color: "#fff", background: "#775DD0" }, text: "Sensor Standortwechsel" } }, { // in a datetime series, the x value should be a timestamp, just like it is generated below x: 1603497600000, strokeDashArray: 0, borderColor: "#775DD0", label: { borderColor: "#775DD0", style: { color: "#fff", background: "#775DD0" }, text: "Antennentausch" } } ] }, series: [{ name: "...105e", data: [ [1604016000000, -113], [1603929600000, -110.3333], [1603756800000, -112.6667], [1603238400000, -113.1667] ] }, { name: "...13b4", data: [ [1604016000000, -112.6747], [1603929600000, -113.4097] ] }, { name: "...13dc", data: [ [1603152000000, -115.4198], [1602892800000, -115.2353], [1602720000000, -115.0899], [1602633600000, -115.2114], [1602547200000, -115.1194], [1602460800000, -115.1099] ] }, { name: "...1d16", data: [ [1604707200000, -116.9], [1604620800000, -120.2917], [1604534400000, -120.375], [1604448000000, -120.6], [1604361600000, -122.5], [1604275200000, -121.1111], [1604102400000, -121.1176], [1603929600000, -120.1667], [1603843200000, -122.35], [1603756800000, -119], [1603584000000, -120.4714], [1603497600000, -121.6667], [1603411200000, -119.3333], [1603324800000, -119.9394], [1603238400000, -120.0473], [1603152000000, -117.5957], [1603065600000, -118.619], [1602979200000, -119.1875], [1602892800000, -117.8571], [1602720000000, -118.1818], [1602633600000, -116.4658], [1602547200000, -116.7703], [1602460800000, -118.0702], [1602374400000, -105] ] }, { name: "...2234", data: [ [1604707200000, -117.5135], [1604620800000, -114.7731], [1604534400000, -116], [1604448000000, -116.9302], [1604361600000, -116.8657], [1604275200000, -117.0231], [1604188800000, -118.4565], [1604102400000, -117.5439], [1604016000000, -117.1467], [1603929600000, -115.4375], [1603843200000, -117.4179], [1603756800000, -118.4299], [1603670400000, -117.8261], [1603584000000, -117.7429], [1603497600000, -117.4366], [1603411200000, -117.9769], [1603324800000, -117.6914], [1603238400000, -118.0486], [1603152000000, -117.5226], [1603065600000, -118.2258], [1602979200000, -117.6164], [1602892800000, -119.1333], [1602720000000, -112.9545], [1602633600000, -115.3803], [1602547200000, -115.2071], [1602460800000, -117.24] ] }, { name: "...227b", data: [ [1602892800000, -121], [1602633600000, -124], [1602547200000, -121] ] }, { name: "...4150", data: [ [1604016000000, -129.3095] ] }, { name: "...977f", data: [ [1604707200000, -110.0333], [1604620800000, -109.8492], [1604534400000, -112.8841], [1604448000000, -112.0231], [1604361600000, -116.0756], [1604275200000, -109.6502], [1604188800000, -105.5222], [1604102400000, -111.8837], [1604016000000, -112.4626], [1603929600000, -111.206], [1603843200000, -111.3592], [1603756800000, -110.5217], [1603670400000, -113.9744], [1603584000000, -109.4286], [1603497600000, -111.1921], [1603411200000, -115.4262], [1603324800000, -115.1326], [1603238400000, -115.2974], [1603152000000, -93.0038], [1603065600000, -69.3091], [1602979200000, -71.865], [1602892800000, -78.6], [1602720000000, -80.1818], [1602633600000, -78.0094], [1602547200000, -77.3879], [1602460800000, -75], [1602374400000, -74] ] }, { name: "...fb95", data: [ [1604707200000, -116.8689], [1604620800000, -117.8982], [1604534400000, -118.9207], [1604448000000, -120.1887], [1604361600000, -120.5862], [1604275200000, -119.3309], [1604188800000, -119.5652], [1604102400000, -120.2348], [1603756800000, -119.0595], [1603670400000, -121.8], [1603584000000, -119.3935], [1603497600000, -120.3169], [1603411200000, -120.7307], [1603324800000, -120.5073], [1603238400000, -120.2629], [1603152000000, -119.8952], [1602460800000, -122.5] ] }, ], chart: { type: 'line', height: 350, zoom: { enabled: false } }, colors: ['#111111', '#222222', '#333333', '#444444', '#555555', '#666666', '#777777', '#bb0000', '#999999'], dataLabels: { enabled: false }, stroke: { curve: 'straight' }, title: { text: 'RSSI & SNR', align: 'left' }, subtitle: { text: 'der verschiedenen Gateways', align: 'left' }, xaxis: { type: 'datetime', labels: { format: 'dd.MM.yyyy' }, }, yaxis: { title: { text: 'RSSI' } }, legend: { horizontalAlign: 'left' }, tooltip: { x: { show: true, format: 'dd.MM.yyyy HH:mm', } } } { annotations: { yaxis: [{ y: 100, y2: -7.5, borderColor: "#00E396", fillColor: '#b2b2b2', label: { borderColor: "#00E396", style: { color: "#fff", background: "#00E396", }, text: "SF7" } }, { y: -7.5, y2: -10, borderColor: "#00E396", fillColor: '#626262', label: { borderColor: "#00E396", style: { color: "#fff", background: "#00E396" }, text: "SF8" } }, { y: -10, y2: -12.5, borderColor: "#00E396", fillColor: '#b2b2b2', label: { borderColor: "#00E396", style: { color: "#fff", background: "#00E396" }, text: "SF9" } }, { y: -12.5, y2: -15, borderColor: "#00E396", fillColor: '#626262', label: { borderColor: "#00E396", style: { color: "#fff", background: "#00E396" }, text: "SF10" } }, { y: -15, y2: -17.5, borderColor: "#00E396", fillColor: '#b2b2b2', label: { borderColor: "#00E396", style: { color: "#fff", background: "#00E396" }, text: "SF11" } }, { y: -17.5, y2: -20, borderColor: "#00E396", fillColor: '#626262', label: { borderColor: "#00E396", style: { color: "#fff", background: "#00E396" }, text: "SF12" } }], xaxis: [{ // in a datetime series, the x value should be a timestamp, just like it is generated below x: 1603152000000, strokeDashArray: 0, borderColor: "#775DD0", label: { borderColor: "#775DD0", style: { color: "#fff", background: "#775DD0" }, text: "Sensor Standortwechsel" } }, { // in a datetime series, the x value should be a timestamp, just like it is generated below x: 1603497600000, strokeDashArray: 0, borderColor: "#775DD0", label: { borderColor: "#775DD0", style: { color: "#fff", background: "#775DD0" }, text: "Antennentausch" } } ] }, series: [{ name: "...105e", data: [ [1604016000000, 14.25], [1603929600000, -13.5], [1603756800000, 4.5417], [1603238400000, 9.9167] ] }, { name: "...13b4", data: [ [1604016000000, -10.9337], [1603929600000, -1.3872] ] }, { name: "...13dc", data: [ [1603152000000, -2.4294], [1602892800000, -13.375], [1602720000000, -13.5478], [1602633600000, -13.3046], [1602547200000, -13.0872], [1602460800000, -13.1758] ] }, { name: "...1d16", data: [ [1604707200000, -16.83], [1604620800000, -16.5917], [1604534400000, -17.2375], [1604448000000, -17.76], [1604361600000, -18.075], [1604275200000, -17.6167], [1604102400000, -16.2118], [1603929600000, -17.8], [1603843200000, -17.24], [1603756800000, -20], [1603584000000, -15.98], [1603497600000, -16.5333], [1603411200000, -17.4], [1603324800000, -15.8152], [1603238400000, -15.0642], [1603152000000, -11.4518], [1603065600000, -7.9476], [1602979200000, -8.4297], [1602892800000, -4.3143], [1602720000000, -3.1303], [1602633600000, -3.7158], [1602547200000, -3.3338], [1602460800000, -9.314], [1602374400000, -17.2] ] }, { name: "...2234", data: [ [1604707200000, -9.1351], [1604620800000, -9.2202], [1604534400000, -8.2945], [1604448000000, -8.036], [1604361600000, -9.3179], [1604275200000, -9.7439], [1604188800000, -11.6435], [1604102400000, -9.8789], [1604016000000, -9.9467], [1603929600000, -12.1929], [1603843200000, -11.3776], [1603756800000, -11.4131], [1603670400000, -9.0478], [1603584000000, -9.9514], [1603497600000, -9.8239], [1603411200000, -11.0287], [1603324800000, -9.9514], [1603238400000, -9.419], [1603152000000, -8.4852], [1603065600000, -9.4129], [1602979200000, -11.1397], [1602892800000, -8.7333], [1602720000000, -4.8227], [1602633600000, -5.3528], [1602547200000, -5.1586], [1602460800000, -10.0693] ] }, { name: "...227b", data: [ [1602892800000, -19.5], [1602633600000, -20.2], [1602547200000, -19.2] ] }, { name: "...4150", data: [ [1604016000000, -10.7119] ] }, { name: "...977f", data: [ [1604707200000, 3.9283], [1604620800000, 3.7592], [1604534400000, 1.9232], [1604448000000, 3.11], [1604361600000, -0.9109], [1604275200000, 4.5636], [1604188800000, 5.3333], [1604102400000, 2.9437], [1604016000000, 2.2252], [1603929600000, 2.7357], [1603843200000, 3.1764], [1603756800000, 3.6981], [1603670400000, 3.7359], [1603584000000, 4.5466], [1603497600000, 2.5927], [1603411200000, -4.8533], [1603324800000, -3.9388], [1603238400000, -5.1801], [1603152000000, 1.0192], [1603065600000, 8.0727], [1602979200000, 7.7779], [1602892800000, 7.4857], [1602720000000, 7.9216], [1602633600000, 7.617], [1602547200000, 7.7963], [1602460800000, 7.9322], [1602374400000, 7.7] ] }, { name: "...fb95", data: [ [1604707200000, -9.3], [1604620800000, -6.9743], [1604534400000, -7.2927], [1604448000000, -6.1057], [1604361600000, -7.0595], [1604275200000, -3.6989], [1604188800000, -3.6141], [1604102400000, -6.1304], [1603756800000, -7.5131], [1603670400000, -10.64], [1603584000000, -8.3996], [1603497600000, -7.7], [1603411200000, -7.6362], [1603324800000, -5.6347], [1603238400000, -5.4007], [1603152000000, -7.7415], [1602460800000, -18.3] ] }, ], chart: { type: 'line', height: 350, zoom: { enabled: false } }, colors: ['#111111', '#222222', '#333333', '#444444', '#555555', '#666666', '#777777', '#bb0000', '#999999'], dataLabels: { enabled: false }, stroke: { curve: 'straight' }, title: { text: '', align: 'left' }, subtitle: { text: '', align: 'left' }, xaxis: { type: 'datetime', labels: { format: 'dd.MM.yyyy' }, }, yaxis: { title: { text: 'SNR' } }, legend: { horizontalAlign: 'left' }, tooltip: { x: { show: true, format: 'dd.MM.yyyy HH:mm', } } } ^ Tag ^ Rssi (AVG) ^ Rssi (MAX) ^ Rssi (MIN) ^ Rssi (STDABW) ^ Snr (AVG) ^ Snr (MAX) ^ Snr (MIN) ^ Snr (STDABW) ^ | 11.10.2020 | -74,0 | -74,0 | -74,0 | 0,00 | 7,7 | 8,2 | 7,2 | 0,71 | | 12.10.2020 | -75,0 | -68,0 | -79,0 | 1,82 | 7,9 | 9,8 | 5,8 | 0,87 | | 13.10.2020 | -77,4 | -68,0 | -101,0 | 5,75 | 7,8 | 10,5 | 5,8 | 0,57 | | 14.10.2020 | -78,0 | -69,0 | -101,0 | 5,84 | 7,6 | 10,0 | 5,0 | 0,69 | | 15.10.2020 | -80,2 | -74,0 | -101,0 | 6,01 | 7,9 | 9,0 | 7,0 | 0,43 | | 17.10.2020 | -78,6 | -74,0 | -83,0 | 2,75 | 7,5 | 9,0 | 5,8 | 0,84 | | 18.10.2020 | -71,9 | -68,0 | -83,0 | 3,05 | 7,8 | 9,5 | 6,0 | 0,85 | | 19.10.2020 | -69,3 | -68,0 | -71,0 | 0,90 | 8,1 | 9,2 | 7,0 | 0,39 | | 20.10.2020 | -93,0 | -61,0 | -117,0 | 21,51 | 1,0 | 10,0 | -13,2 | 7,58 | | 21.10.2020 | -115,3 | -100,0 | -119,0 | 1,45 | -5,2 | -1,2 | -14,0 | 2,25 | | 22.10.2020 | -115,1 | -101,0 | -119,0 | 1,86 | -3,9 | -0,2 | -12,5 | 2,24 | | 23.10.2020 | -115,4 | -99,0 | -119,0 | 1,63 | -4,9 | 1,0 | -12,2 | 3,32 | | 24.10.2020 | -111,2 | -91,0 | -119,0 | 3,45 | 2,6 | 6,2 | -8,5 | 2,85 | | 25.10.2020 | -109,4 | -103,0 | -121,0 | 3,16 | 4,5 | 7,2 | -7,0 | 1,22 | | 26.10.2020 | -114,0 | -97,0 | -121,0 | 4,50 | 3,7 | 4,5 | 0,5 | 0,59 | | 27.10.2020 | -110,5 | -89,0 | -119,0 | 2,69 | 3,7 | 6,2 | -1,5 | 1,11 | | 28.10.2020 | -111,4 | -96,0 | -123,0 | 3,41 | 3,2 | 6,2 | -1,8 | 1,56 | | 29.10.2020 | -111,2 | -94,0 | -119,0 | 3,76 | 2,7 | 7,0 | -8,8 | 2,86 | | 30.10.2020 | -112,5 | -96,0 | -118,0 | 2,63 | 2,2 | 5,8 | -7,5 | 1,82 | | 31.10.2020 | -111,9 | -91,0 | -115,0 | 2,48 | 2,9 | 5,0 | -3,0 | 1,27 | | 01.11.2020 | -105,5 | -89,0 | -114,0 | 3,69 | 5,3 | 7,0 | 0,5 | 1,24 | | 02.11.2020 | -109,7 | -104,0 | -121,0 | 2,77 | 4,6 | 7,0 | -3,2 | 1,05 | | 03.11.2020 | -116,1 | -112,0 | -120,0 | 1,91 | -0,9 | 4,8 | -11,8 | 3,24 | | 04.11.2020 | -112,0 | -108,0 | -114,0 | 1,25 | 3,1 | 5,0 | -4,5 | 1,05 | | 05.11.2020 | -112,9 | -93,0 | -119,0 | 2,23 | 1,9 | 4,2 | -11,0 | 1,95 | | 06.11.2020 | -109,8 | -90,0 | -114,0 | 2,32 | 3,8 | 5,0 | -6,2 | 1,28 | | 07.11.2020 | -110,0 | -103,0 | -113,0 | 1,75 | 3,9 | 4,8 | 0,8 | 0,60 | Was sich hier zeigt ist, dass sich der Standortwechsel des Sensors vom Haus auf das Gartengrundstück sowohl im RSSI als auch im SNR deutlich bemerkbar gemacht haben. Der Tausch der Indoor-Antenne gegen die Outdoor-Antenne hat aber im SNR wieder einiges gut gemacht. Da der schlechteste SNR im aktuellen Aufbau bei -11,8 liegt habe ich mich für SF9 entschieden, da dort die Grenze bei ca. -12,5 liegt. Was aufgrund des SNR-Ranges recht stabil sein sollte. Des Weiteren habe ich auch noch die Solarzelle in einem anderen Winkel montiert. Damit sollte nun also die Schaltung, ohne Unterbrechung auch über die Winter-Monate kommen... ===== Software ===== ==== Arduino ==== Die Software auf dem Arduino ist auf konsequentes Stromsparen ausgelegt. So wird werden die Module nur bei Bedarf eingeschaltet und der Arduino legt sich lange Zeit schlafen. Verwendete Librarys: * LowPower * Adafruit BME280 * TinyLora ++++ ttn_temp.ino | #define EU863 #include "LowPower.h" #include #include #include #include #define bme_en 4 #define lora_en1 5 #define lora_en2 6 #define lora_en3 7 // Network Session Key (MSB) uint8_t NwkSkey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // Application Session Key (MSB) uint8_t AppSkey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // Device Address (MSB) uint8_t DevAddr[4] = { 0x00, 0x00, 0x00, 0x00 }; unsigned char loraData[4*3+2+1]; // How many times data transfer should occur, in seconds const unsigned int sendInterval = 6 * 60; Adafruit_BME280 bme; TinyLoRa lora = TinyLoRa(2, 10); uint16_t frameCounter = 0; void setup() { //delay(100); //Serial.begin(115200); //while (! Serial); } void loop() { //Serial.println("delaying..."); for(int i = 0; i < ((sendInterval) / 8); i++) { LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); //Funkmodul abschalten pinMode(lora_en1, INPUT); pinMode(lora_en2, INPUT); pinMode(lora_en3, INPUT); digitalWrite(lora_en1, false); digitalWrite(lora_en2, false); digitalWrite(lora_en3, false); } union { float val; unsigned char bytes[4]; } tmp; union { int val; unsigned char bytes[2]; } tmp2; //BME einschalten digitalWrite(bme_en, true); pinMode(bme_en, OUTPUT); delay(3); bme.begin(); bme.setSampling(Adafruit_BME280::MODE_FORCED, Adafruit_BME280::SAMPLING_X2, // temperature Adafruit_BME280::SAMPLING_X2, // pressure Adafruit_BME280::SAMPLING_X2, // humidity Adafruit_BME280::FILTER_X2); bme.takeForcedMeasurement(); loraData[0] = 0; //Gerätetypkennzeichner für TTN decoder tmp.val = bme.readTemperature(); loraData[1] = tmp.bytes[0]; loraData[2] = tmp.bytes[1]; loraData[3] = tmp.bytes[2]; loraData[4] = tmp.bytes[3]; tmp.val = bme.readHumidity(); loraData[5] = tmp.bytes[0]; loraData[6] = tmp.bytes[1]; loraData[7] = tmp.bytes[2]; loraData[8] = tmp.bytes[3]; tmp.val = bme.readPressure(); loraData[9] = tmp.bytes[0]; loraData[10] = tmp.bytes[1]; loraData[11] = tmp.bytes[2]; loraData[12] = tmp.bytes[3]; //BME abschalten pinMode(bme_en, INPUT); digitalWrite(bme_en, false); tmp2.val = analogRead(A7); loraData[13] = tmp2.bytes[0]; loraData[14] = tmp2.bytes[1]; //Funkmodul einschalten digitalWrite(lora_en1, true); digitalWrite(lora_en2, true); digitalWrite(lora_en3, true); pinMode(lora_en1, OUTPUT); pinMode(lora_en2, OUTPUT); pinMode(lora_en3, OUTPUT); delay(3); lora.setChannel(CH2); lora.setDatarate(SF9BW125); lora.begin(); lora.frameCounter = frameCounter; //Serial.println("Sending LoRa Data..."); lora.sendData(loraData, sizeof(loraData), lora.frameCounter); //Serial.print("Frame Counter: ");Serial.println(lora.frameCounter); frameCounter++; } ++++ ==== TTN-Payload-Format ==== Der Dekoder, welcher auf der TTN-Konsole hinterlegt werden kann. Damit können die Bytes dekodiert und wieder in eine Dezimalzahl überführt werden. Der "Format Selector" habe ich definiert, um im selben "Sensornetz" eine Unterscheidung treffen zu können, wie der jeweilige Sensor dekodiert werden soll, falls es noch welche gibt, die andere Werte zurückliefern. ++++ ttn_payload_decoder | function Bytes2Float32(bytes) { var sign = (bytes & 0x80000000) ? -1 : 1; var exponent = ((bytes >> 23) & 0xFF) - 127; var significand = (bytes & ~(-1 << 23)); if (exponent == 128) return sign * ((significand) ? Number.NaN : Number.POSITIVE_INFINITY); if (exponent == -127) { if (significand === 0) return sign * 0.0 ; exponent = -126; significand /= (1 << 22); } else significand = (significand | (1 << 23)) / (1 << 23); return sign * significand * Math.pow(2, exponent); } function Decoder(bytes, port) { if (port === 1) { if(bytes[0] == 0) { //Format Selector return { temperature: Bytes2Float32(bytes[3+1]<<24 | bytes[2+1]<<16 | bytes[1+1]<<8 | bytes[0+1]), humidity: Bytes2Float32(bytes[3+4+1]<<24 | bytes[2+4+1]<<16 | bytes[1+4+1]<<8 | bytes[0+4+1]), pressure: Bytes2Float32(bytes[3+8+1]<<24 | bytes[2+8+1]<<16 | bytes[1+8+1]<<8 | bytes[0+8+1]), battery: bytes[1+12+1]<<8 | bytes[0+12+1] }; } } } ++++ ==== ioBroker-Skript ==== {{:elektronik:lora_temperatursensor:screen_mqtt_1.png?direct&300|}} \\ MQTT-Adapter Einstellung Seite 1 {{:elektronik:lora_temperatursensor:screen_mqtt_2.png?direct&300|}} \\ MQTT-Adapter Einstellung Seite 2 Die Umsetzung in ioBroker-Variablen erfolgt über ein JavaScript-Script. Dieses konvertiert die Werte passend zum ioBroker. Auskommentiert ist noch eine Möglichkeit die rohen JSON-Pakete vom TTN zum entsprechenden Sensor mitzuloggen. ++++ ttn_decode | //Temperatursensor 1 createState("custom.ttn.temp_sensor01.temperature", false, { name: "Temperature", read: true, write: false, desc: "", def: 0, unit: "°C", role: "value.temperature", type: "number" }); createState("custom.ttn.temp_sensor01.humidity", false, { name: "Humidity", read: true, write: false, desc: "", def: 0, unit: "%", role: "value.humidity", type: "number" }); createState("custom.ttn.temp_sensor01.pressure", false, { name: "Pressure", read: true, write: false, desc: "", def: 0, unit: "hPa", role: "value.pressure", type: "number" }); createState("custom.ttn.temp_sensor01.battery", false, { name: "Battery", read: true, write: false, desc: "", def: 0, unit: "V", role: "", type: "number" }); //const fs = require('fs'); on({id: 'mqtt.1.mh-sensornetwork.devices.temp_sensor01.up', change: "ne"}, function (obj) { obj = JSON.parse(getState("mqtt.1.mh-sensornetwork.devices.temp_sensor01.up").val); setState("custom.ttn.temp_sensor01.temperature", parseFloat(obj["payload_fields"]["temperature"].toFixed(2)), true); setState("custom.ttn.temp_sensor01.humidity", parseFloat(obj["payload_fields"]["humidity"].toFixed(2)), true); setState("custom.ttn.temp_sensor01.pressure", parseFloat((obj["payload_fields"]["pressure"]/100.0).toFixed(2)), true); setState("custom.ttn.temp_sensor01.battery", parseFloat(((3.3/1024.0)*parseFloat(obj["payload_fields"]["battery"])*2.0).toFixed(2)), true); /* var file = "/opt/iobroker/ttn_log.csv"; if(!fs.existsSync(file)) { fs.writeFileSync(file, "Time\tData\r\n"); } fs.appendFileSync(file, (new Date()).toISOString() + "\t" + getState("mqtt.1.mh-sensornetwork.devices.temp_sensor01.up").val + "\r\n"); */ }); ++++ ===== Bilder ===== {{:elektronik:lora_temperatursensor:hauptgehaeuse.jpg?direct&300|}} \\ Arduino und Sensor im Gehäuse\\ Mit XT60-Steckverbinder {{:elektronik:lora_temperatursensor:solarzelle_mod.jpg?direct&300|}} \\ Modifizierte Solarzelle;\\ Abgriff der Akkuspannung und\\ entferntes LED-Kabel {{:elektronik:lora_temperatursensor:solar_temperatursensor.jpg?direct&300|}} \\ Solarzelle mit Temperatursensor\\ outdoor montiert {{:elektronik:lora_temperatursensor:solar_temperatursensor_2.jpg?direct&300|}} \\ Solarzelle mit Temperatursensor\\ optimierte Montage {{:elektronik:lora_temperatursensor:ttn_gateway.jpg?direct&300|}} \\ Selbstbau TTN Gateway mit Raspberry Pi Zero\\ und iC880A, noch ohne Außenantenne ===== Screenshots ===== {{:elektronik:lora_temperatursensor:screen_lovelace.png?direct&300|}} \\ Anzeige in Lovelace-Interface {{:elektronik:lora_temperatursensor:screen_grafana.png?direct&300|}} \\ Test-Dashboard mit Grafana\\ mit Influx-DB-Daten\\ -> Vergleich Sensor Garage zu Gartengrundstück ==== 3D-Modell ==== {{:elektronik:lora_temperatursensor:gehaeuse.stl?h=200&w=300&bgcolor=#ffffff|Gehäuse}} {{:elektronik:lora_temperatursensor:deckel.stl?h=200&w=300&bgcolor=#ffffff|Deckel}} {{tag>[arduino micro lora ttn bme280 temperatur luftfeuchte luftdruck ic880a funk iobroker]}} \\ ~~REFNOTES~~ \\ ~~DISQUS~~