MySensors Library & Examples  2.3.2-36-g2e00bf6
RFM69_RFM95_ATC_SignalReport.ino
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of the
6  * network topology allowing messages to be routed to nodes.
7  *
8  * Created by Henrik Ekblad <[email protected]>
9  * Copyright (C) 2013-2020 Sensnology AB
10  * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11  *
12  * Documentation: http://www.mysensors.org
13  * Support Forum: http://forum.mysensors.org
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2 as published by the Free Software Foundation.
18  *
19  *******************************
20  *
21  * REVISION HISTORY
22  * Version 1.1 - tekka
23  *
24  * DESCRIPTION
25  * ATC mode settings and signal report functions, on RFM69 and RFM95 nodes
26  *
27  */
28 
29 // Enable debug prints
30 #define MY_DEBUG
31 
32 // Enable signal report functionalities
33 #define MY_SIGNAL_REPORT_ENABLED
34 
35 // Enable and select radio type attached
36 
37 // RFM69
38 //#define MY_RADIO_RFM69
39 //#define MY_RFM69_NEW_DRIVER // ATC on RFM69 works only with the new driver (not compatible with old=default driver)
40 //#define MY_RFM69_ATC_TARGET_RSSI_DBM (-70) // target RSSI -70dBm
41 //#define MY_RFM69_MAX_POWER_LEVEL_DBM (10) // max. TX power 10dBm = 10mW
42 
43 // RFM95
44 #define MY_RADIO_RFM95
45 #define MY_RFM95_ATC_TARGET_RSSI_DBM (-70) // target RSSI -70dBm
46 #define MY_RFM95_MAX_POWER_LEVEL_DBM (10) // max. TX power 10dBm = 10mW
47 
48 #include <MySensors.h>
49 
50 // ID of the sensor child
51 #define CHILD_ID_UPLINK_QUALITY (0)
52 #define CHILD_ID_TX_LEVEL (1)
53 #define CHILD_ID_TX_PERCENT (2)
54 #define CHILD_ID_TX_RSSI (3)
55 #define CHILD_ID_RX_RSSI (4)
56 #define CHILD_ID_TX_SNR (5)
57 #define CHILD_ID_RX_SNR (6)
58 
59 
60 // Initialize general message
61 MyMessage msgTxRSSI(CHILD_ID_TX_RSSI, V_CUSTOM);
62 MyMessage msgRxRSSI(CHILD_ID_RX_RSSI, V_CUSTOM);
63 MyMessage msgTxSNR(CHILD_ID_TX_SNR, V_CUSTOM);
64 MyMessage msgRxSNR(CHILD_ID_RX_SNR, V_CUSTOM);
65 MyMessage msgTxLevel(CHILD_ID_TX_LEVEL, V_CUSTOM);
66 MyMessage msgTxPercent(CHILD_ID_TX_PERCENT, V_CUSTOM);
67 MyMessage msgUplinkQuality(CHILD_ID_UPLINK_QUALITY, V_CUSTOM);
68 
69 void setup()
70 {
71 }
72 
73 
75 {
76  // Send the sketch version information to the gateway and controller
77  sendSketchInfo("ATC", "1.1");
78 
79  // Register all sensors to gw (they will be created as child devices)
80  present(CHILD_ID_UPLINK_QUALITY, S_CUSTOM, "UPLINK QUALITY RSSI");
81  present(CHILD_ID_TX_LEVEL, S_CUSTOM, "TX LEVEL DBM");
82  present(CHILD_ID_TX_PERCENT, S_CUSTOM, "TX LEVEL PERCENT");
83  present(CHILD_ID_TX_RSSI, S_CUSTOM, "TX RSSI");
84  present(CHILD_ID_RX_RSSI, S_CUSTOM, "RX RSSI");
85  present(CHILD_ID_TX_SNR, S_CUSTOM, "TX SNR");
86  present(CHILD_ID_RX_SNR, S_CUSTOM, "RX SNR");
87 }
88 
89 void loop()
90 {
91  // send messages to GW
92  send(msgUplinkQuality.set(transportGetSignalReport(SR_UPLINK_QUALITY)));
93  send(msgTxLevel.set(transportGetSignalReport(SR_TX_POWER_LEVEL)));
94  send(msgTxPercent.set(transportGetSignalReport(SR_TX_POWER_PERCENT)));
95  // retrieve RSSI / SNR reports from incoming ACK
96  send(msgTxRSSI.set(transportGetSignalReport(SR_TX_RSSI)));
97  send(msgRxRSSI.set(transportGetSignalReport(SR_RX_RSSI)));
98  send(msgTxSNR.set(transportGetSignalReport(SR_TX_SNR)));
99  send(msgRxSNR.set(transportGetSignalReport(SR_RX_SNR)));
100  // wait a bit
101  wait(5000);
102 }
sendSketchInfo
bool sendSketchInfo(const char *name, const char *version, const bool requestEcho=false)
loop
void loop()
Main loop.
Definition: RFM69_RFM95_ATC_SignalReport.ino:89
transportGetSignalReport
int16_t transportGetSignalReport(const signalReport_t signalReport) __attribute__((unused))
Get transport signal report.
presentation
void presentation()
Node presentation.
Definition: RFM69_RFM95_ATC_SignalReport.ino:74
MyMessage::set
MyMessage & set(const void *payload, const size_t length)
Set entire payload.
send
bool send(MyMessage &msg, const bool requestEcho=false)
present
bool present(const uint8_t sensorId, const mysensors_sensor_t sensorType, const char *description="", const bool requestEcho=false)
setup
void setup()
Called after node initialises but before main loop.
Definition: RFM69_RFM95_ATC_SignalReport.ino:69
wait
void wait(const uint32_t waitingMS)
MySensors.h
API declaration for MySensors.
MyMessage
MyMessage is used to create, manipulate, send and read MySensors messages.
Definition: MyMessage.h:289