Shantam Raj
Published © GPL3+

Self Sustained WiFi Sensor Node

A sensor node that publishes Temperature, Ambient Light, Humidity, Atmospheric Pressure to the cloud and does not need battery replacement.

AdvancedFull instructions provided2,368
Self Sustained WiFi Sensor Node

Things used in this project

Hardware components

RedBear WiFi Micro Kit
×1
Texas Instruments HDC1080
×1
Texas Instruments OPT3001
×1
Texas Instruments BQ25505
×1
Solar Panel (2W, 5.5V)
×1
Texas Instruments TPS63001
×1
LiPo Battery
×1
NXP MPL3115A2
×1
AAA or AA Battery x 2
×1

Story

Read more

Custom parts and enclosures

Eagle files

Use Eagle to open and edit the files for your own use.

Schematics

schematic

Eagle schematic

Code

Energia Code

C/C++
This is what you upload to your launchpad/microcontroller.
// Best code so far, works with both router and mobile phone hotspot!!. The graphing also works!!.
#include <adafruitmpl.h>
#include <HDC1050-v2.h>
#include <utils.h>
#include <OPT3001.h>
//#include <SPI.h>
#include <WiFi.h>
//#include <WiFiClient.h>
//#include <WiFiServer.h>
#include <Wire.h>
opt3001 instance;
uint32_t resultt =0;
HDC1000 mySensor;
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();
float pascals;
float altm ;
float tempC ;
float hdctemp ;
float hdchumi ;

// your network name also called SSID
char ssid[] = "******";
// your network password
char password[] = "*******";
// your network key Index number (needed only for WEP)
int keyIndex = 0;

WiFiServer server(80);
int i = 0;
void setup() {
  Serial.begin(115200);      // initialize serial communication
  pinMode(RED_LED, OUTPUT);      // set the LED pin mode
  instance.begin();
  mySensor.begin();
  baro.begin();
  // attempt to connect to Wifi network:
  Serial.print("Attempting to connect to Network named: ");
  // print the network name (SSID);
  Serial.println(ssid);
  // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED) {
    // print dots while we wait to connect
    Serial.print(".");
    delay(300);
  }

  Serial.println("\nYou're connected to the network");
  Serial.println("Waiting for an ip address");

  while (WiFi.localIP() == INADDR_NONE) {
    // print dots while we wait for an ip addresss
    Serial.print(".");
    delay(300);
  }

  // you're connected now, so print out the status
  printWifiStatus();

  Serial.println("Starting webserver on port 80");
  server.begin();                           // start the web server on port 80
  Serial.println("Webserver started!");

}
void loop() {
  getSensorData();
//  resultt = instance.readResult();
//  //Serial.println(resultt);
//  float pascals = baro.getPressure();
//  float altm = baro.getAltitude();
//  float tempC = baro.getTemperature();
//  double hdctemp = mySensor.getTemp();
//  double hdchumi = mySensor.getHumi();

  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html; charset=utf-8");
          //Content-Type: text/html; charset=utf-8
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println("Access-Control-Allow-Origin: *"); //comment this line if u are facing issues showing things on webpage.
          client.println();
          //client.println("<!DOCTYPE HTML>");
          //client.println("<html>");
          client.println("<html>");
          client.print("LUX:");
          client.print(resultt);
          client.print(";");
          client.print("Temperature:");
          client.print(hdctemp);
          client.print(";Humidity:");
          client.print(hdchumi);
          client.print(";");
          client.print("  ");
          client.print("Hg:");
          client.print(pascals/3377);
          client.print(";Height:");
          client.print(altm); //client.print("m ");
          client.print(";Temp:");
          client.print(tempC); //client.print("*C");
          client.println("<br>");
          client.println("</html>");
          client.println();
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);

    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
  i++;
}
void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("Network Name: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}
void getSensorData(){
  resultt = instance.readResult();
  Serial.println(resultt);
  pascals = baro.getPressure();
  Serial.println(pascals);
  altm = baro.getAltitude();
  Serial.println(altm);
  tempC = baro.getTemperature();
  Serial.println(tempC);
  hdctemp = mySensor.getTemp();
  Serial.println(hdctemp);
  hdchumi = mySensor.getHumi();
  Serial.println(hdchumi);
  //float pascals = baro.getPressure();
  // Our weather page presents pressure in Inches (Hg)
  // Use http://www.onlineconversion.com/pressure.htm for other units
  // Serial.print(pascals/3377); Serial.println(" Inches (Hg)");
  //
  // float altm = baro.getAltitude();
  // Serial.print(altm); Serial.println(" meters");
  //
  // float tempC = baro.getTemperature();
  // Serial.print(tempC); Serial.println("*C");
}

Web Browser Code

JavaScript
You need to have the smoothie.js and jquery library
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
    <title>Smoothie Chart Example</title>
    <script type="text/javascript" src="smoothie.js"></script>
    <script type="text/javascript" src="jquery.js"></script>

  </head>
  <body>

    <canvas id="mycanvas" width="1300" height="600"></canvas>

    <script type="text/javascript">
    //var smoothie = new SmoothieChart();
    //smoothie.streamTo(document.getElementById("mycanvas"));

var line1 = new TimeSeries();
var line2 = new TimeSeries();
var line3 = new TimeSeries();
var line4 = new TimeSeries();
var line5 = new TimeSeries();
setInterval(function(getRequest) {
  // Do something every 5 seconds

$.get('http://192.168.0.102/').done(function(response) {
  var a = response.split(/[;]+/);
  var b = a[0].split(/[:]+/);
  var c = a[1].split(/[:]+/);
  var d = a[2].split(/[:]+/);
  var e = a[3].split(/[:]+/);
  var f = a[4].split(/[:]+/);

  var
    x = Date.parse(new Date()+1000) ,
    y = Number.parseFloat(b[1]) ,
    z = Number.parseFloat(c[1]) ,
    g = Number.parseFloat(d[1]) ,
    h = Number.parseFloat(e[1]) ,
    i = Number.parseFloat(f[1])
    ;

    //setInterval(function() {
      line1.append(new Date().getTime(), y);
      line2.append(new Date().getTime(), z);
      line3.append(new Date().getTime(), g);
      line4.append(new Date().getTime(), h);
      line5.append(new Date().getTime(), i);
    //}, 2000);
});
}, 2000);

// Add a random value to each line every second


// Add to SmoothieChart
//smoothie.addTimeSeries(line1);
//smoothie.addTimeSeries(line2);
function myYRangeFunction(range) {
  // TODO implement your calculation using range.min and range.max
  var min = -20;
  var max = 100;
  return {min: min, max: max};
}

var smoothie = new SmoothieChart({ millisPerPixel:34, yRangeFunction:myYRangeFunction,timestampFormatter:SmoothieChart.timeFormatter, grid: { sharpLines:true, strokeStyle: 'rgb(125, 0, 0)', fillStyle: 'rgb(255, 255, 255)', lineWidth: 1, millisPerLine: 250, verticalSections: 6 } });
      smoothie.addTimeSeries(line1, { strokeStyle: 'rgb(0, 255, 0)', lineWidth: 3 });
      smoothie.addTimeSeries(line2, { strokeStyle: 'rgb(255, 0, 255)', lineWidth: 3 });
      smoothie.addTimeSeries(line3, { strokeStyle: 'rgb(249,233,34)', lineWidth: 3 });
      smoothie.addTimeSeries(line4, { strokeStyle: 'rgb(255,255,255)', lineWidth: 3 });
      smoothie.addTimeSeries(line5, { strokeStyle: 'rgb(29,171,201)', lineWidth: 3 });

smoothie.addTimeSeries(line1, {lineWidth:4,strokeStyle:'rgba(0,0,0,0.13)'});
smoothie.streamTo(document.getElementById("mycanvas"), 2000 /*delay*/);
</script>
</body>
</html>

Credits

Shantam Raj

Shantam Raj

3 projects • 11 followers
ECE Undergrad,Daydreamer & Maker. Electronics, Robotics & hardware hacking enthusiast. Die hard soccer fan. New found love = IoT

Comments