MySensors Library & Examples  2.3.2
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-2019 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.0 - 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 and select radio type attached
33 
34 // RFM69
35 //#define MY_RADIO_RFM69
36 //#define MY_RFM69_NEW_DRIVER // ATC on RFM69 works only with the new driver (not compatible with old=default driver)
37 //#define MY_RFM69_ATC_TARGET_RSSI_DBM (-70) // target RSSI -70dBm
38 //#define MY_RFM69_MAX_POWER_LEVEL_DBM (10) // max. TX power 10dBm = 10mW
39 
40 // RFM95
41 #define MY_RADIO_RFM95
42 #define MY_RFM95_ATC_TARGET_RSSI_DBM (-70) // target RSSI -70dBm
43 #define MY_RFM95_MAX_POWER_LEVEL_DBM (10) // max. TX power 10dBm = 10mW
44 
45 #include <MySensors.h>
46 
47 // ID of the sensor child
48 #define CHILD_ID_UPLINK_QUALITY (0)
49 #define CHILD_ID_TX_LEVEL (1)
50 #define CHILD_ID_TX_PERCENT (2)
51 #define CHILD_ID_TX_RSSI (3)
52 #define CHILD_ID_RX_RSSI (4)
53 #define CHILD_ID_TX_SNR (5)
54 #define CHILD_ID_RX_SNR (6)
55 
56 
57 // Initialize general message
58 MyMessage msgTxRSSI(CHILD_ID_TX_RSSI, V_CUSTOM);
59 MyMessage msgRxRSSI(CHILD_ID_RX_RSSI, V_CUSTOM);
60 MyMessage msgTxSNR(CHILD_ID_TX_SNR, V_CUSTOM);
61 MyMessage msgRxSNR(CHILD_ID_RX_SNR, V_CUSTOM);
62 MyMessage msgTxLevel(CHILD_ID_TX_LEVEL, V_CUSTOM);
63 MyMessage msgTxPercent(CHILD_ID_TX_PERCENT, V_CUSTOM);
64 MyMessage msgUplinkQuality(CHILD_ID_UPLINK_QUALITY, V_CUSTOM);
65 
66 void setup()
67 {
68 }
69 
70 
72 {
73  // Send the sketch version information to the gateway and controller
74  sendSketchInfo("ATC", "1.0");
75 
76  // Register all sensors to gw (they will be created as child devices)
77  present(CHILD_ID_UPLINK_QUALITY, S_CUSTOM, "UPLINK QUALITY RSSI");
78  present(CHILD_ID_TX_LEVEL, S_CUSTOM, "TX LEVEL DBM");
79  present(CHILD_ID_TX_PERCENT, S_CUSTOM, "TX LEVEL PERCENT");
80  present(CHILD_ID_TX_RSSI, S_CUSTOM, "TX RSSI");
81  present(CHILD_ID_RX_RSSI, S_CUSTOM, "RX RSSI");
82  present(CHILD_ID_TX_SNR, S_CUSTOM, "TX SNR");
83  present(CHILD_ID_RX_SNR, S_CUSTOM, "RX SNR");
84 }
85 
86 void loop()
87 {
88  // send messages to GW
89  send(msgUplinkQuality.set(transportGetSignalReport(SR_UPLINK_QUALITY)));
90  send(msgTxLevel.set(transportGetSignalReport(SR_TX_POWER_LEVEL)));
91  send(msgTxPercent.set(transportGetSignalReport(SR_TX_POWER_PERCENT)));
92  // retrieve RSSI / SNR reports from incoming ACK
93  send(msgTxRSSI.set(transportGetSignalReport(SR_TX_RSSI)));
94  send(msgRxRSSI.set(transportGetSignalReport(SR_RX_RSSI)));
95  send(msgTxSNR.set(transportGetSignalReport(SR_TX_SNR)));
96  send(msgRxSNR.set(transportGetSignalReport(SR_RX_SNR)));
97  // wait a bit
98  wait(5000);
99 }
sendSketchInfo
bool sendSketchInfo(const char *name, const char *version, const bool requestEcho=false)
loop
void loop()
Main loop.
Definition: RFM69_RFM95_ATC_SignalReport.ino:86
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:71
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:66
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