Skip to content

Commit

Permalink
MQTT last will and Improved RFM69
Browse files Browse the repository at this point in the history
Thaks Thierry
  • Loading branch information
couin3 committed Sep 12, 2020
1 parent c9fd765 commit 30c9ae6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions RFLink/1_Radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ void set_Radio_mode(Radio_State new_State)
case Radio_OFF:
PIN_RF_RX_DATA = NOT_A_PIN;
PIN_RF_TX_DATA = NOT_A_PIN;
radio.reset();
radio.initialize();
radio.setFrequency(433920000);
Serial.print("Freq = "); Serial.println(radio.getFrequency());
//Serial.print("Temp = "); Serial.println(radio.readTemperature());
radio.setHighPower(true); // for RFM69HW
// radio.sleep();
break;
Expand Down
7 changes: 5 additions & 2 deletions RFLink/6_Credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
String WIFI_SSID = "your_AP_ssid";
String WIFI_PSWD = "your_AP_passwd";

// static IP
// DHCP or Static IP
#define USE_DHCP
#ifndef USE_DHCP
String WIFI_IP = "192.168.0.199";
String WIFI_DNS = "8.8.8.8";
String WIFI_GATEWAY = "192.168.0.1";
String WIFI_SUBNET = "255.255.255.0";
#endif

// MQTT Server
String MQTT_SERVER = "raspberrypi.local";
Expand All @@ -33,4 +36,4 @@ String MQTT_TOPIC_OUT = "/RFLink/msg";
String MQTT_TOPIC_IN = "/RFLink/cmd";

#endif
#endif
#endif
11 changes: 10 additions & 1 deletion RFLink/6_WiFi_MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ void setup_WIFI()
#endif // ESP8266
WiFi.mode(WIFI_STA);

// Comment out for Dynamic IP
// For Static IP
#ifndef USE_DHCP
WiFi.config(ipaddr_addr(WIFI_IP.c_str()), ipaddr_addr(WIFI_GATEWAY.c_str()), ipaddr_addr(WIFI_SUBNET.c_str()));
#endif // USE_DHCP

// We start by connecting to a WiFi network
Serial.print(F("WiFi SSID :\t\t"));
Expand Down Expand Up @@ -108,13 +110,20 @@ void reconnect()
Serial.println(MQTT_SERVER.c_str());
Serial.print(F("MQTT Connection :\t"));

#ifdef MQTT_LWT
if (MQTTClient.connect(MQTT_ID.c_str(), MQTT_USER.c_str(), MQTT_PSWD.c_str(), (MQTT_TOPIC_OUT+"/LWT").c_str(), 2, true, "Offline"))
#else
if (MQTTClient.connect(MQTT_ID.c_str(), MQTT_USER.c_str(), MQTT_PSWD.c_str()))
#endif
{
Serial.println(F("Established"));
Serial.print(F("MQTT ID :\t\t"));
Serial.println(MQTT_ID.c_str());
Serial.print(F("MQTT Username :\t\t"));
Serial.println(MQTT_USER.c_str());
#ifdef MQTT_LWT
MQTTClient.publish((MQTT_TOPIC_OUT+"/LWT").c_str(), "Online", true);
#endif
}
else
{
Expand Down
1 change: 1 addition & 0 deletions RFLink/RFLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define MQTT_ENABLED // Send RFLink messages over MQTT
#define MQTT_LOOP_MS 1000 // MQTTClient.loop(); call period (in mSec)
#define MQTT_RETAINED_0 false // Retained option
#define MQTT_LWT // Let know if Module is Online or Offline via MQTT Last Will message
#endif

// Debug default
Expand Down

0 comments on commit 30c9ae6

Please sign in to comment.