Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** RF24Mesh_Example.ino by TMRh20
- *
- * This example sketch shows how to manually configure a node via RF24Mesh, and send data to the
- * master node.
- * The nodes will refresh their network address as soon as a single write fails. This allows the
- * nodes to change position in relation to each other and the master node.
- */
- #include "RF24.h"
- #include "RF24Network.h"
- #include "RF24Mesh.h"
- #include <SPI.h>
- #include <EEPROM.h>
- #include <dht.h>
- //#include <printf.h>
- /**** Configure the nrf24l01 CE and CS pins ****/
- RF24 radio(7, 8);
- RF24Network network(radio);
- RF24Mesh mesh(radio, network);
- /**
- * User Configuration: nodeID - A unique identifier for each radio. Allows addressing
- * to change dynamically with physical changes to the mesh.
- *
- * In this example, configuration takes place below, prior to uploading the sketch to the device
- * A unique value from 1-255 must be configured for each node.
- * This will be stored in EEPROM on AVR devices, so remains persistent between further uploads, loss of power, etc.
- *
- **/
- #define nodeID 5
- dht DHT;
- #define DHT11_PIN 2
- uint32_t displayTimer = 0;
- struct payload_t {
- uint32_t soilMoisture;
- uint32_t temp;
- uint32_t humidity;
- };
- //moisture sensor pin
- int mostureSensor = 0;
- void setup() {
- Serial.begin(115200);
- //printf_begin();
- // Set the nodeID manually
- mesh.setNodeID(nodeID);
- // Connect to the mesh
- Serial.println(F("Connecting to the mesh..."));
- mesh.begin();
- }
- void loop() {
- mesh.update();
- // Send to the master node every second
- if (millis() - displayTimer >= 5000) {
- payload_t payload;
- displayTimer = millis();
- //payload_t sensorValue;
- payload.soilMoisture = analogRead(mostureSensor);
- int chk = DHT.read11(DHT11_PIN);
- payload.temp = DHT.temperature;
- payload.humidity = DHT.humidity;
- //TODO: send node value as well
- Serial.print("\n SM ");
- Serial.println(payload.soilMoisture);
- Serial.print("Temp ");
- Serial.println(payload.temp);
- Serial.print("Humidity ");
- Serial.println(payload.humidity);
- if (!mesh.write(&payload, 'M', sizeof(payload))) {
- // If a write fails, check connectivity to the mesh network
- if ( ! mesh.checkConnection() ) {
- //refresh the network address
- Serial.println("Renewing Address");
- mesh.renewAddress();
- } else {
- Serial.println("Send fail, Test OK");
- }
- } else {
- Serial.print("Send OK: "); Serial.println(sizeof(payload));// Serial.print(" "); Serial.println(sensorValue);
- }
- }
- while (network.available()) {
- RF24NetworkHeader header;
- payload_t payload;
- network.read(header, &payload, sizeof(payload));
- Serial.print("Received packet #");
- Serial.print(payload.soilMoisture);
- Serial.print(" at ");
- Serial.println(payload.humidity);
- }
- }
Add Comment
Please, Sign In to add comment