1
0
mirror of https://github.com/Adam-Ant/MQTT-nRF24-Bridge synced 2024-06-14 06:27:23 +00:00

Initial Commit

This commit is contained in:
Adam Dodman 2018-01-26 02:35:02 +00:00
commit 031833ca9f
8 changed files with 165 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.pioenvs
.piolibdeps

9
.gitmodules vendored Normal file
View File

@ -0,0 +1,9 @@
[submodule "lib/RF24"]
path = lib/RF24
url = git@github.com:nRF24/RF24.git
[submodule "lib/RF24Network"]
path = lib/RF24Network
url = git@github.com:nRF24/RF24Network.git
[submodule "lib/RF24Mesh"]
path = lib/RF24Mesh
url = git@github.com:nRF24/RF24Mesh.git

21
Makefile Normal file
View File

@ -0,0 +1,21 @@
# Uncomment lines below if you have problems with $PATH
#SHELL := /bin/bash
#PATH := /usr/local/bin:$(PATH)
all:
platformio -f -c vim run
upload:
platformio -f -c vim run --target upload
clean:
platformio -f -c vim run --target clean
program:
platformio -f -c vim run --target program
uploadfs:
platformio -f -c vim run --target uploadfs
update:
platformio -f -c vim update

1
lib/RF24 Submodule

@ -0,0 +1 @@
Subproject commit 4accec5883bb3e65b3370b2e64627a787a790dc3

1
lib/RF24Mesh Submodule

@ -0,0 +1 @@
Subproject commit a832458dbd066c7b8073a46f124ddec0fc9a9491

1
lib/RF24Network Submodule

@ -0,0 +1 @@
Subproject commit 2292755ecb3f7912cf69bae7618c48f34ea612fe

16
platformio.ini Normal file
View File

@ -0,0 +1,16 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
upload_port = /dev/ttyACM*
upload_speed = 460800

114
src/main.ino Normal file
View File

@ -0,0 +1,114 @@
/** RF24Mesh_Example_Master.ino by TMRh20
*
*
* This example sketch shows how to manually configure a node via RF24Mesh as a master node, which
* will receive all data from sensor nodes.
*
* The nodes can change physical or logical position in the network, and reconnect through different
* routing nodes as required. The master node manages the address assignments for the individual nodes
* in a manner similar to DHCP.
*
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "RF24Network.h"
#include "RF24.h"
#include "RF24Mesh.h"
#include <SPI.h>
//Include eeprom.h for AVR (Uno, Nano) etc. except ATTiny
#include <EEPROM.h>
const char* ssid = "XXXX";
const char* password = "XXXX";
/***** Configure the chosen CE,CS pins *****/
RF24 radio(4,5);
RF24Network network(radio);
RF24Mesh mesh(radio,network);
ESP8266WebServer http(80);
uint32_t displayTimer = 0;
String webpage = "";
void setup() {
Serial.begin(115200);
// Set the nodeID to 0 for the master node
mesh.setNodeID(0);
Serial.println(mesh.getNodeID());
Serial.println("Starting...... ");
// Connect to the mesh
mesh.begin();
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
Serial.println(WiFi.status());
}
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Setup the web server
http.on("/", [](){
webpage = "<h1>Connected Clients:</h1><br>";
for(int i=0; i<mesh.addrListTop; i++){
webpage += "<b>NodeId: </b>";
webpage += mesh.addrList[i].nodeID;
webpage += " <b>MeshAddress: </b>";
webpage += mesh.addrList[i].address;
}
http.send(200, "text/html", webpage);
});
http.begin();
}
void loop() {
// Handle the HTTP Server
http.handleClient();
// Call mesh.update to keep the network updated
mesh.update();
// In addition, keep the 'DHCP service' running on the master node so addresses will
// be assigned to the sensor nodes
mesh.DHCP();
// Check for incoming data from the sensors
if(network.available()){
RF24NetworkHeader header;
network.peek(header);
uint32_t dat=0;
switch(header.type){
// Display the incoming millis() values from the sensor nodes
case 'M': network.read(header,&dat,sizeof(dat)); Serial.println(dat); break;
default: network.read(header,0,0); Serial.println(header.type);break;
}
}
if(millis() - displayTimer > 5000){
displayTimer = millis();
Serial.println(" ");
Serial.println(F("********Assigned Addresses********"));
for(int i=0; i<mesh.addrListTop; i++){
Serial.print("NodeID: ");
Serial.print(mesh.addrList[i].nodeID);
Serial.print(" RF24Network Address: 0");
Serial.println(mesh.addrList[i].address,OCT);
}
Serial.println(F("**********************************"));
}
}