Skip to content

Instantly share code, notes, and snippets.

@SimonMerrett
Last active August 28, 2020 14:54
Show Gist options
  • Save SimonMerrett/b09132b51bb1e9642e240995cf500ba2 to your computer and use it in GitHub Desktop.
Save SimonMerrett/b09132b51bb1e9642e240995cf500ba2 to your computer and use it in GitHub Desktop.
rf24 mqtt node test
Failed
arduinoClient5
Attempting MQTT connection...13349: NET Sending id 8 from 04444 to 00 type 148
13350: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b2 60 06 40 00 00 01 00 2c 00 00 45
13357: MAC Sending to 00 via 0444 on pipe 4
13361: NET Pipe 4 on node 0444 has address cc3e3e3e3e
14487: MAC Network ACK fail from 00 via 0444 on pipe 4
14490: NET Sending id 8 from 04444 to 00 type 148
14490: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b2 60 06 40 00 00 01 00 2c 00 00 45
14498: MAC Sending to 00 via 0444 on pipe 4
14502: NET Pipe 4 on node 0444 has address cc3e3e3e3e
14628: MAC Send fail to 00 via 0444 on pipe 4
14631: NET Sending id 8 from 04444 to 00 type 148
14631: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b2 60 06 40 00 00 01 00 2c 00 00 45
14639: MAC Sending to 00 via 0444 on pipe 4
14643: NET Pipe 4 on node 0444 has address cc3e3e3e3e
14769: MAC Send fail to 00 via 0444 on pipe 4
23582: NET Sending id 9 from 04444 to 00 type 148
23583: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b1 60 06 40 00 00 02 00 2c 00 00 45
23589: MAC Sending to 00 via 0444 on pipe 4
23593: NET Pipe 4 on node 0444 has address cc3e3e3e3e
23796: MAC Network ACK fail from 00 via 0444 on pipe 4
23799: NET Sending id 9 from 04444 to 00 type 148
23799: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b1 60 06 40 00 00 02 00 2c 00 00 45
23808: MAC Sending to 00 via 0444 on pipe 4
23812: NET Pipe 4 on node 0444 has address cc3e3e3e3e
23937: MAC Send fail to 00 via 0444 on pipe 4
23940: NET Sending id 9 from 04444 to 00 type 148
23940: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b1 60 06 40 00 00 02 00 2c 00 00 45
23947: MAC Sending to 00 via 0444 on pipe 4
23951: NET Pipe 4 on node 0444 has address cc3e3e3e3e
24077: MAC Send fail to 00 via 0444 on pipe 4
24081: NET Sending id 10 from 04444 to 00 type 148
24082: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b0 60 06 40 00 00 03 00 2c 00 00 45
24088: MAC Sending to 00 via 0444 on pipe 4
24092: NET Pipe 4 on node 0444 has address cc3e3e3e3e
24293: MAC Network ACK fail from 00 via 0444 on pipe 4
24296: NET Sending id 10 from 04444 to 00 type 148
24296: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b0 60 06 40 00 00 03 00 2c 00 00 45
24304: MAC Sending to 00 via 0444 on pipe 4
24308: NET Pipe 4 on node 0444 has address cc3e3e3e3e
24337: MAC Send fail to 00 via 0444 on pipe 4
24340: NET Sending id 10 from 04444 to 00 type 148
24341: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b0 60 06 40 00 00 03 00 2c 00 00 45
24348: MAC Sending to 00 via 0444 on pipe 4
24352: NET Pipe 4 on node 0444 has address cc3e3e3e3e
24381: MAC Send fail to 00 via 0444 on pipe 4
24386: NET Sending id 11 from 04444 to 00 type 148
24387: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b3 60 06 40 00 00 04 00 28 00 00 45
24393: MAC Sending to 00 via 0444 on pipe 4
24397: NET Pipe 4 on node 0444 has address cc3e3e3e3e
24505: MAC Network ACK fail from 00 via 0444 on pipe 4
24508: NET Sending id 11 from 04444 to 00 type 148
24508: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b3 60 06 40 00 00 04 00 28 00 00 45
24516: MAC Sending to 00 via 0444 on pipe 4
24520: NET Pipe 4 on node 0444 has address cc3e3e3e3e
24549: MAC Send fail to 00 via 0444 on pipe 4
24552: NET Sending id 11 from 04444 to 00 type 148
24553: NET message 5b 07 01 04 01 03 0a 0a 05 03 0a 0a b3 60 06 40 00 00 04 00 28 00 00 45
24560: MAC Sending to 00 via 0444 on pipe 4
24564: NET Pipe 4 on node 0444 has address cc3e3e3e3e
24593: MAC Send fail to 00 via 0444 on pipe 4
failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...29698: NET Sending id 12 from 04444 to 00 type 148
29699: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a ae 60 06 40 00 00 05 00 2c 00 00 45
29705: MAC Sending to 00 via 0444 on pipe 4
29709: NET Pipe 4 on node 0444 has address cc3e3e3e3e
29816: MAC Network ACK fail from 00 via 0444 on pipe 4
29819: NET Sending id 12 from 04444 to 00 type 148
29819: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a ae 60 06 40 00 00 05 00 2c 00 00 45
29828: MAC Sending to 00 via 0444 on pipe 4
29832: NET Pipe 4 on node 0444 has address cc3e3e3e3e
29862: MAC Send fail to 00 via 0444 on pipe 4
29865: NET Sending id 12 from 04444 to 00 type 148
29867: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a ae 60 06 40 00 00 05 00 2c 00 00 45
29874: MAC Sending to 00 via 0444 on pipe 4
29878: NET Pipe 4 on node 0444 has address cc3e3e3e3e
29908: MAC Send fail to 00 via 0444 on pipe 4
30256: NET Sending id 13 from 04444 to 00 type 148
30257: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a ad 60 06 40 00 00 06 00 2c 00 00 45
30263: MAC Sending to 00 via 0444 on pipe 4
30267: NET Pipe 4 on node 0444 has address cc3e3e3e3e
30372: MAC Network ACK fail from 00 via 0444 on pipe 4
30375: NET Sending id 13 from 04444 to 00 type 148
30375: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a ad 60 06 40 00 00 06 00 2c 00 00 45
30384: MAC Sending to 00 via 0444 on pipe 4
30388: NET Pipe 4 on node 0444 has address cc3e3e3e3e
30418: MAC Send fail to 00 via 0444 on pipe 4
30422: NET Sending id 13 from 04444 to 00 type 148
30423: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a ad 60 06 40 00 00 06 00 2c 00 00 45
30430: MAC Sending to 00 via 0444 on pipe 4
30434: NET Pipe 4 on node 0444 has address cc3e3e3e3e
30465: MAC Send fail to 00 via 0444 on pipe 4
31310: NET Sending id 14 from 04444 to 00 type 148
31311: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a ac 60 06 40 00 00 07 00 2c 00 00 45
31318: MAC Sending to 00 via 0444 on pipe 4
31322: NET Pipe 4 on node 0444 has address cc3e3e3e3e
31428: MAC Network ACK fail from 00 via 0444 on pipe 4
31431: NET Sending id 14 from 04444 to 00 type 148
31431: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a ac 60 06 40 00 00 07 00 2c 00 00 45
31439: MAC Sending to 00 via 0444 on pipe 4
31443: NET Pipe 4 on node 0444 has address cc3e3e3e3e
31474: MAC Send fail to 00 via 0444 on pipe 4
31477: NET Sending id 14 from 04444 to 00 type 148
31478: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a ac 60 06 40 00 00 07 00 2c 00 00 45
31485: MAC Sending to 00 via 0444 on pipe 4
31490: NET Pipe 4 on node 0444 has address cc3e3e3e3e
31520: MAC Send fail to 00 via 0444 on pipe 4
33356: NET Sending id 15 from 04444 to 00 type 148
33357: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a af 60 06 40 00 00 08 00 28 00 00 45
33363: MAC Sending to 00 via 0444 on pipe 4
33368: NET Pipe 4 on node 0444 has address cc3e3e3e3e
33474: MAC Network ACK fail from 00 via 0444 on pipe 4
33477: NET Sending id 15 from 04444 to 00 type 148
33477: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a af 60 06 40 00 00 08 00 28 00 00 45
33485: MAC Sending to 00 via 0444 on pipe 4
33489: NET Pipe 4 on node 0444 has address cc3e3e3e3e
33520: MAC Send fail to 00 via 0444 on pipe 4
33523: NET Sending id 15 from 04444 to 00 type 148
33524: NET message 5b 07 02 04 01 03 0a 0a 05 03 0a 0a af 60 06 40 00 00 08 00 28 00 00 45
33531: MAC Sending to 00 via 0444 on pipe 4
33536: NET Pipe 4 on node 0444 has address cc3e3e3e3e
33566: MAC Send fail to 00 via 0444 on pipe 4
failed, rc=-2 try again in 5 seconds
setup_address node=04444 mask=07777 parent=0444 pipe=04
38572: NET Pipe 5 on node 04444 has address 3e3e3e3ee3
38575: NET Pipe 4 on node 04444 has address 3e3e3e3e3e
38580: NET Pipe 3 on node 04444 has address 3e3e3e3ece
38585: NET Pipe 2 on node 04444 has address 3e3e3e3e33
38589: NET Pipe 1 on node 04444 has address 3e3e3e3e3c
38594: NET Pipe 0 on node 04444 has address cccccc3ecc
38599: NET Sending id 16 from 04444 to 0100 type 194
38603: MAC Sending to 00 via 00 on pipe 0
38607: NET Pipe 0 on node 00 has address ccccccccc3
38719: NET Sending id 17 from 04444 to 0100 type 194
38719: MAC Sending to 01 via 01 on pipe 0
38722: NET Pipe 0 on node 01 has address cccccc3ccc
38840: NET Sending id 18 from 04444 to 0100 type 1
/* Last updated 25/8/20
* designed to demo/test the pi A+ is working
*************************************************************************
RF24Ethernet Arduino library by TMRh20 - 2014-2015
Automated (mesh) wireless networking and TCP/IP communication stack for RF24 radio modules
RF24 -> RF24Network -> UIP(TCP/IP) -> RF24Ethernet
-> RF24Mesh
Documentation: http://tmrh20.github.io/RF24Ethernet/
*************************************************************************
**** EXAMPLE REQUIRES: PubSub MQTT library: https://github.com/knolleary/pubsubclient ***
Install using the Arduino library manager
*************************************************************************
Basic MQTT example
***** CONVERTED FOR SAMD21 **********
including serialUSB
This sketch demonstrates the basic capabilities of the library.
It connects to an MQTT server then:
- publishes "hello world" to the topic "outTopic"
- subscribes to the topic "inTopic", printing out any messages
it receives. NB - it assumes the received payloads are strings not binary
- Continually publishes its nodeID to the outTopic
It will reconnect to the server if the connection is lost using a blocking
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
achieve the same result without blocking the main loop.
*/
#include <SPI.h>
#include <RF24.h>
#include <RF24Network.h>
#include <RF24Mesh.h>
#include <RF24Ethernet.h>
#include <PubSubClient.h>
uint8_t numberOfBulbs = 1;
uint8_t currentBulb = 0;
bool bulbState[] = {false, false, false, false, false, false, false, false, false, false};
uint8_t channel = 50;
//RF24 radio(9,10);
RF24 radio(6, 10);
RF24Network network(radio);
RF24Mesh mesh(radio, network);
RF24EthernetClass RF24Ethernet(radio, network, mesh);
IPAddress ip(10, 10, 3, 5);
IPAddress gateway(10, 10, 3, 1); //Specify the gateway in case different from the server
IPAddress server(10, 10, 3, 1); //The ip of the MQTT server
char *clientID = {"arduinoClient5 "};
constexpr char sub[] PROGMEM = "zigbee2mqtt/bridge/log";
constexpr char bulbNumbers[][11] PROGMEM = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10"};
constexpr char bulb[] PROGMEM = "zigbee2mqtt/hue_white_";
constexpr char set[] PROGMEM = "/set";
constexpr char state[] PROGMEM = "{\"state\":\"O";
constexpr char setOn[] PROGMEM = "{\"state\":\"ON\"}"; // leave a little extra space for overwrite issues
constexpr char setOff[] PROGMEM = "{\"state\":\"OFF\"}";
constexpr char setBright[] PROGMEM = "{\"brightness\":\"255\"}";
char msg[45] = {};
char comd[25] = {};
void callback(char* topic, byte* payload, unsigned int length) {
SerialUSB.print(F("Message arrived ["));
SerialUSB.print(topic);
SerialUSB.print(F("] "));
for (int i = 0; i < length; i++) {
SerialUSB.print((char)payload[i]);
}
SerialUSB.println();
}
EthernetClient ethClient;
PubSubClient client(ethClient);
void reconnect() {
// Loop until we're reconnected
if (!client.connected()) {
SerialUSB.print(F("Attempting MQTT connection..."));
// Attempt to connect
if (client.connect(clientID)) {
SerialUSB.println(F("connected"));
// Once connected, publish an announcement...
//client.publish("zigbee2mqtt/bridge/log", "Remote control has woken up");
// ... and resubscribe
memset(msg, 0, sizeof(msg));
memcpy(msg, sub, strlen_P(sub));
client.subscribe(msg);
} else {
SerialUSB.print(F("failed, rc="));
SerialUSB.print(client.state());
SerialUSB.println(F(" try again in 5 seconds"));
// Wait 5 seconds before retrying
delay(1000);
}
}
}
void setup()
{
SerialUSB.begin(115200);
// while (!SerialUSB); // wait for a serial connection to be established
SerialUSB.println(F("rebooted"));
client.setServer(server, 1883);
client.setCallback(callback);
Ethernet.begin(ip);
SerialUSB.println(F(" Ethernet.begin(ip) done"));
radio.setPALevel(RF24_PA_MIN);
Ethernet.set_gateway(gateway);
if (mesh.begin(channel)) {
SerialUSB.println(F(" OK"));
} else {
SerialUSB.println(F(" Failed"));
}
//Convert the last octet of the IP address to an identifier used
char str[4];
int test = ip[3];
itoa(ip[3], str, 10);
// memcpy(&clientID[13], &str, strlen(str));
SerialUSB.println(clientID);
}
uint32_t mesh_timer = 0;
uint32_t pub_timer = 0;
void loop()
{
Ethernet.update();
if (millis() - mesh_timer > 30000) { //Every 30 seconds, test mesh connectivity
mesh_timer = millis();
if ( !mesh.checkConnection() ) {
if (!mesh.renewAddress()) {
mesh.begin(/*MESH_DEFAULT_CHANNEL*/channel, RF24_1MBPS, 5000);
}
}
}
if (!client.connected()) {
//delay(10000); // DEBUG experimental delay to see if it helps
reconnect();
}
client.loop();
// Every 20 seconds, turn a different bulb on or off - rotate through them
if (client.connected() && millis() - pub_timer > 20000) {
pub_timer = millis();
SerialUSB.print(F("currentBulb = "));
SerialUSB.println(currentBulb);
//pubCommands(currentBulb + 1);
currentBulb += 1;
if (currentBulb >= numberOfBulbs)
{
currentBulb = 0;
SerialUSB.println(F("reset counter"));
}
setMsg(currentBulb);
if (bulbState[currentBulb])
{
setComd(setOff);
client.publish(msg, comd); // "{\"state\":\"OFF\"}");
bulbState[currentBulb] = false;
// delay(100);
// setComd(setBright);
// client.publish(msg, comd);
}
else
{
setComd(setOn);
client.publish(msg, comd); //"{\"state\":\"ON\"}");
delay(100);
setComd(setBright);
client.publish(msg, comd); //"{\"state\":\"ON\"}");
bulbState[currentBulb] = true;
}
}
}
// puts the mqtt publishing string together
void setMsg(uint8_t bulbPosn)
{
memset(msg, 0, sizeof(msg));
memcpy_P(msg, bulb, strlen_P(bulb));
memcpy_P(msg + strlen_P(bulb), bulbNumbers[bulbPosn], strlen_P(bulbNumbers[bulbPosn]));
memcpy_P(msg + strlen_P(bulb) + strlen_P(bulbNumbers[bulbPosn]), set, strlen_P(set));
SerialUSB.print(msg);
SerialUSB.println("|");
}
void setComd(const char onOff[])
{
memset(comd, 0, sizeof(comd));
memcpy_P(comd, onOff, strlen_P(onOff));
SerialUSB.print(comd);
SerialUSB.println("|");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment