Close

nRF24 <-> ESP8266 Hub Development

A project log for analog.io - A full stack IoT platform

A full stack project dedicated to easily collecting, analyzing and sharing IoT sensor data.

luke-benoLuke Beno 08/29/2015 at 15:003 Comments

So at this point the MSP430 Sensor nodes are coming along quite well. This week I built and shipped off 10 units to other members of the 43oh.com forum. The first revision of the analog_io_lib was also released and other people are starting to play around with it.

Back in April I released this ESP8266 Mini Dev Kit on Tindie, it is intended to be a ultra compact and convenient way to develop for ESP8266 (pics below).

At that time I was doing development with NodeMCU which is also a great environment! I was looking for a lower cost alternative to Electric Imp and something that was easier to deploy with customers. One thing that I came to realize with NodeMCU was that it wasn't the most reliable thing, it tended to run out of heap space very often when doing simple WiFi transactions. I determined then that if I was going to do a product, that I would need to program directly in C/C++.

After reading about it setting up a ESP8266 dev environment for awhile, I realized that it was going to be a lot of fiddling around. I really don't enjoy setting up toolchains, especially when there are such low friction alternatives like Arduino, Energia, Simplicity Studio, etc, etc. So I started working on something else instead...

Fast forward to August and there is now this beautiful Arduino port for ESP8266! Last night I took a chance to sit down a explore. Very quickly I was able to solder up a nRF24 module to the dev kit:

Merging some of the demo code from the ESP8266WiFi lib and my own, I was able to quickly merge this demo where the ESP8266 talks directly to nRF24 via SPI, takes packets received from the a MSP430 sensor node and pushes them directly to data.sparkfun.com!

Very cool, heres my code:

/*
 *  This sketch sends data via HTTP GET requests to data.sparkfun.com service.
 *
 *  You need to get streamId and privateKey at data.sparkfun.com and paste them
 *  below. Or just customize this script to talk to other HTTP servers.
 *
 */
#include <analog_io.h>
#include <SPI.h>
#include <ESP8266WiFi.h>

const char* ssid     = "...";
const char* password = "...";

const char* host = "data.sparkfun.com";
const char* streamId   = "VGQ7n2Ww2Mhx5NNnVooE";
const char* privateKey = "...................................................";

analog_io radio(2, 15, 18); // CE, CSN, IRQ pins
const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
char inbuf[33];

void setup() {
  Serial.begin(115200);
  delay(10);

  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  radio.begin();  // Defaults 1Mbps, channel 0, max TX power

  radio.setRXaddress((void*)rxaddr);
  
  radio.enableRX();  // Start listening
}

int value = 0;

void loop() {
  while (!radio.available(true))
  {
    delay(10);
  }
  if (radio.read(inbuf)) {
    Serial.print("Received packet: ");
    Serial.println(inbuf);
  }

  Serial.print("connecting to ");
  Serial.println(host);
  
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
  
  // We now create a URI for the request
  String url = "/input/";
  url += streamId;
  url += "?private_key=";
  url += privateKey;
  url += "&value=";
  url += inbuf;
  
  Serial.print("Requesting URL: ");
  Serial.println(url);
  
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
  delay(10);
  
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  
  Serial.println();
  Serial.println("closing connection");
}
Lots more of code to write here but this is extremely promising towards creating a super low cost IoT hub and bridging the sensor nodes to the analog.io web service! I even started a new board for it (work in progress).

More to come on this one :)

Discussions

khaled wrote 08/14/2016 at 12:01 point

very amazing to know that you did make the esp8266 talk to the nrf24l01.

but I have a question I have done all what you posted here and nothing happened on my esp can give me a little bit of advice.

thanks.

  Are you sure? yes | no

lageos wrote 09/25/2015 at 23:59 point

Great looking forward to try that as well :)

  Are you sure? yes | no

chadclick wrote 09/01/2015 at 21:13 point

Looks fun!

  Are you sure? yes | no