Create Your Internet of Things Dashboard

Create Your Internet of Things Dashboard

In this article, you are going to build a weather measurement station that will automatically send data to an online cloud service. To do so, we will simply use an Arduino Uno board, a WiFi module and some sensors.

Using completely free web services like Dweet.io and Freeboard.io, you will be able to build your own Internet of Things dashboard for home automation applications. Let’s dive in!

Hardware & Software Requirements

For this project, you will first need an Arduino Uno board.

For temperature and humidity measurements, you will also need a DHT11 sensor, along with a 4.7K resistor. You can also use a DHT22 sensor which is more precise, you will only have one line of code to change.

For light levels measurements, I used a photocell with a 10K Ohm resistor. This will return a signal which is proportional to the ambient light level.

Then, you need the CC3000 chip for WiFi connectivity. There are many different boards for this chip on the market. What I recommend is using the Adafruit CC3000 breakout board, which is the only one I tested that worked without a problem. It is nice and compact with an onboard antenna and voltage regulators (so you can directly connect it your Arduino board).

Finally, you need a breadboard and some jumper wires to make the connections between the different parts.

This a list of all required components for the project:

On the software side, you will need the library for the DHT sensor:

https://github.com/adafruit/DHT-sensor-library

You will also need a library for the CC3000 WiFi chip:

https://github.com/adafruit/Adafruit_CC3000_Library

To install a library, simply extract the library folder inside the /libraries folder of your main Arduino folder.

You will also need to create an account on Freeboard, as we will use this service to display the measured data. Go over to:

https://www.freeboard.io/

You will be taken to the welcome page of the Freeboard service, where you can create an account:

Create Your Internet of Things Dashboard

Hardware Configuration

The hardware connections for this project are actually quite simple. First, we have to connect the DHT11 sensor   (the part responsible for the light level measurement) to the photocell and the CC3000 WiFi chip. To help you out, the following picture summarizes the hardware connections:

Create Your Internet of Things Dashboard

First, connect the Arduino Uno +5V pin to the red rail on the breadboard, and the ground pin to the blue rail. Then, place the DHT sensor and the CC3000 breakout board on the breadboard.

After that, connect pin number 1 of the DHT11 sensor (see the schematic) to the red rail on the breadboard, and pin number 4 to the blue rail. Also, connect pin number 2 of the sensor to pin number 7 of the Arduino board. To complete the connections of the DHT11 sensor, connect the 4.7k Ohm between pin number 1 and 2 of the sensor.

For the photocell, first place the cell in series with the 10k Ohm resistor on the breadboard. Then, connect the other end of the photocell to the red rail on the breadboard, and the other end of the resistor to the ground. Finally, connect the common pin to the Arduino Uno analog pin A0.

Now, the WiFi module. First, connect the IRQ pin of the CC3000 board to pin number 3 of the Arduino board, VBAT to pin 5, and CS to pin 10. Then, you need to connect the SPI pins to the Arduino board: MOSI, MISO, and CLK go to pins 11,12, and 13, respectively. Finally, take care of the power supply: Vin goes to the Arduino 5V (red power rail), and GND to GND (blue power rail).

Testing Parts Individually

Now that the hardware of the project is fully assembled, we are going to test the different sensors on the board. And to do so, we are going to write a simple Arduino sketch. We will simply read out data from the sensors, and print this data on the Serial port.

This is the complete code for this section:

// Libraries
#include "DHT.h"

// DHT sensor
#define DHTPIN 7 
#define DHTTYPE DHT11

// DHT instance
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  // Initialize the Serial port
  Serial.begin(9600);
  
  // Init DHT
  dht.begin();
}


void loop()
{
  // Measure from DHT
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  
  // Measure light level
  float sensor_reading = analogRead(A0);
  float light = sensor_reading/1024*100;
  
  // Display temperature
  Serial.print("Temperature: ");
  Serial.print((int)temperature);
  Serial.println(" C");
  
   // Display humidity
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println("%");
  
  // Display light level
  Serial.print("Light: ");
  Serial.print(light);
  Serial.println("%");
  Serial.println("");
  
  // Wait 500 ms
  delay(500);
  
}

Let’s now see the details. It starts by importing the library for the DHT sensor:

#include "DHT.h"

And create a DHT instance:

DHT dht(DHTPIN, DHTTYPE);

In the setup() function of the sketch, we have to initialize the sensor:

dht.begin();

And the Serial port:

Serial.begin(9600);

In the loop() function, we are going to continuously read data from the sensors, and print it on the Serial port. It starts by getting data from the temperature & humidity sensor:

float temperature = dht.readTemperature();
float humidity = dht.readHumidity();

For the photocell, we first read data from the analog pin A0. This pin will return a value from 0 to 1023 as the resolution of the Analog-To-Digital converter of the Arduino Uno board is 10 bits. Thus, there are 1024 values. Then, we divide this reading by 1024 and multiply it by 100 to have the light level as a percentage:

float sensor_reading = analogRead(A0);
float light = sensor_reading/1024*100;

Then, we print these different measurements on the Serial port. First, the temperature:

Serial.print("Temperature: ");
Serial.print((int)temperature);
Serial.print((char)223);
Serial.println("C");

The humidity is exactly similar, just as the light level:

Serial.print("Light: ");
Serial.print(light);
Serial.println("%");

Finally, we introduce a delay of 500 ms between each new set of measurements:

delay(500);

Note that the complete code for this article can be found inside the GitHub repository of the article:

https://github.com/openhomeautomation/iot-dashboard

It’s now time to test this first Arduino sketch. Upload the code to the Arduino board and open the Serial monitor inside the Arduino IDE. Make sure of the Serial speed that we defined in the code.  This is what you should see:

Temperature: 25 C
Humidity: 36.00%
Light: 83.79%

If that works, congratulations, your sensors are working correctly! You can try, for example, to pass your hand in front of the photocell, and you should see that the light level is changing instantly.

In case it is not working at this point, there are several things you can check. First, make sure that you correctly downloaded and installed the required libraries for this article. Also make sure that you correctly connected the sensors to your Arduino board as defined earlier in the article. Finally, make sure that you are using the latest version of the code from the GitHub repository of the article.

Logging Data in the Cloud

We are now going to do the most important part of this chapter: upload data to the cloud via WiFi. To do so, we will use a service called dweet.io, which is a service that proposes to store your data online via a very simple API. You can check out their page at:

https://dweet.io/

The nice thing with Dweet.io is that it doesn’t require any account creation or configuration — you can upload data immediately. It is based on the principle of having objects called “things”, to which you will upload new data via HTTP requests. And if you upload data to a new thing that doesn’t exist yet, it will be created automatically.

Let’s now build the sketch that we will use to automatically make measurements, connect to the Dweet.io server, and upload the data there. This is the complete code for this section:

// Libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "DHT.h"
#include <avr/wdt.h>

// Define CC3000 chip pins
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

// DHT sensor
#define DHTPIN 7
#define DHTTYPE DHT11

// Create CC3000 instances
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, 
ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);
                                         
// DHT instance
DHT dht(DHTPIN, DHTTYPE);

// WLAN parameters
#define WLAN_SSID       "yourWiFiNetwork"
#define WLAN_PASS       "yourPassword"
#define WLAN_SECURITY   WLAN_SEC_WPA2

// Dweet parameters
#define thing_name  "yourThingName"

// Variables to be sent
int temperature;
int humidity;
int light;

uint32_t ip;

void setup(void)
{
  // Initialize
  Serial.begin(115200);
  
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
 
  // Connect to WiFi network
  Serial.print(F("Connecting to WiFi network ..."));
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("done!"));
  
  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100);
  }  
}

void loop(void)
{ 
  
  // Measure from DHT
  float t = dht.readTemperature();
  float h = dht.readHumidity();
  temperature = (int)t;
  humidity = (int)h;

  // Measure light level
  float sensor_reading = analogRead(A0);
  light = (int)(sensor_reading/1024*100);
  Serial.println(F("Measurements done"));
  
  // Start watchdog 
  wdt_enable(WDTO_8S); 
  
  // Get IP
  uint32_t ip = 0;
  Serial.print(F("www.dweet.io -> "));
  while  (ip  ==  0)  {
    if  (!  cc3000.getHostByName("www.dweet.io", &ip))  {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }  
  cc3000.printIPdotsRev(ip);
  Serial.println(F(""));
  
  // Reset watchdog
  wdt_reset();
  
  // Check connection to WiFi
  Serial.print(F("Checking WiFi connection ..."));
  if(!cc3000.checkConnected()){while(1){}}
  Serial.println(F("done."));
  wdt_reset();
  
  // Send request
  Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
  if (client.connected()) {
    Serial.print(F("Sending request... "));
    
    client.fastrprint(F("GET /dweet/for/"));
    client.print(thing_name);
    client.fastrprint(F("?temperature="));
    client.print(temperature);
    client.fastrprint(F("&humidity="));
    client.print(humidity);
    client.fastrprint(F("&light="));
    client.print(light);
    client.fastrprintln(F(" HTTP/1.1"));
    
    client.fastrprintln(F("Host: dweet.io"));
    client.fastrprintln(F("Connection: close"));
    client.fastrprintln(F(""));
    
    Serial.println(F("done."));
  } else {
    Serial.println(F("Connection failed"));    
    return;
  }
  
  // Reset watchdog
  wdt_reset();
  
  Serial.println(F("Reading answer..."));
  while (client.connected()) {
    while (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  }
  Serial.println(F(""));
  
  // Reset watchdog
  wdt_reset();
   
  // Close connection and disconnect
  client.close();
  Serial.println(F("Closing connection"));
  Serial.println(F(""));
  
  // Reset watchdog & disable
  wdt_reset();
  wdt_disable();
 
  // Wait 60 seconds until next update
  wait(60000);
    
}

// Wait for a given time using the watchdog
void wait(int total_delay) {
  
  int number_steps = (int)(total_delay/5000);
  wdt_enable(WDTO_8S);
  for (int i = 0; i < number_steps; i++){
    //Serial.println(F("Waiting for 5 seconds ..."));
    delay(5000);
    wdt_reset();
  }
  wdt_disable();
}

Let’s now go into the details of the code. It starts by importing the required libraries:

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include "DHT.h"
#include <avr/wdt.h>

We then define the pins which the CC3000 module is connected to:

#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10

Then, we can create an instance of the CC3000 WiFi chip:

Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, <br>ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);

Now, you will need to modify the sketch to enter your own SSID network name, and the associated password. If your network is not using WPA2 authentication, you will also have to change this parameter:

#define WLAN_SSID "yourWiFiNetwork"
#define WLAN_PASS "yourPassword"
#define WLAN_SECURITY WLAN_SEC_WPA2

You will also need to give a name to your ‘thing’. Note that all the things on dweet.io are public by default. It is not a problem here as we just want to upload and monitor simple data that is not sensible at all. However, I recommend choosing a complicated name for the device so nobody else can find it. For example, you can use names like weather_station_l5ir457xda. Once you have a good name, you can enter it inside the sketch:

#define thing_name "yourThingName"

We also need to define some variables that will contain the measurements made by the project:

int temperature;
int humidity;
int light;

In the setup() function of the sketch, we initialize the CC3000 chip:

Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
  Serial.println(F("Couldn't begin()! Check your wiring?"));
  while(1);
}

In the loop() function, we first connect the CC3000 chip to your local WiFi network:

cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);

We also need to start the watchdog. The watchdog is basically a circuit inside the Arduino microcontroller, independent from the code itself. It will reset the Arduino sketch automatically after a given time, unless we send it a reset signal. This will ensure that even if our Arduino sketch hangs for some reasons (for example, it it cannot connect to the Dweet.io servers), the Arduino sketch will just reset itself and the project will continue to work. We first need to enable the watchdog with the maximal delay of 8 seconds:

wdt_enable(WDTO_8S);

When we are connected, we perform the temperature, humidity and light level measurements:

float t = dht.readTemperature();
float h = dht.readHumidity();
temperature = (int)t;
humidity = (int)h;

float sensor_reading = analogRead(A0);
light = (int)(sensor_reading/1024*100);
Serial.println(F("Measurements done"));

Once we got the measurements, we can upload them on the Dweet.io service. To do so, we need to connect to their servers, and then send the data inside a standard HTTP GET request. This is done by the following piece of code:

Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
if (client.connected()) {
Serial.print(F("Sending request... "));

client.fastrprint(F("GET /dweet/for/"));
client.print(thing_name);
client.fastrprint(F("?temperature="));
client.print(temperature);
client.fastrprint(F("&humidity="));
client.print(humidity);
client.fastrprint(F("&light="));
client.print(light);
client.fastrprintln(F(" HTTP/1.1"));

client.fastrprintln(F("Host: dweet.io"));
client.fastrprintln(F("Connection: close"));
client.fastrprintln(F(""));

Serial.println(F("done."));
} else {
Serial.println(F("Connection failed"));
return;
}

We should also not forget to reset the watchdog after this long request:

wdt_reset();

After the data is sent, we read back the answer from the dweet.io server to be sure that the data was correctly received on the other end. We also close the connection and disconnect the CC3000 chip from your WiFi network, in order to save energy:

Serial.println(F("Reading answer..."));
while (client.connected()) {
  while (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
}
Serial.println(F(""));

// Reset watchdog
wdt_reset();

// Close connection and disconnect
client.close();
Serial.println(F("Disconnecting"));
Serial.println(F(""));
cc3000.disconnect();

After that, we also disable the watchdog:

wdt_disable();

Finally, we repeat this loop again after 10 seconds. Note that you can customize this delay if you want less frequent measurements:

delay(10000);

Note that the complete code for this part can be found inside the GitHub repository of the article:

https://github.com/openhomeautomation/iot-dashboard

We are now going to test this code. Make sure that you entered the name of your thing inside the sketch, and that you also entered the data for your WiFi network. Then, upload the code to the Arduino board. Open the Serial monitor, and after a while you should see the answer coming back from the dweet.io server:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 174
Date: Thu, 24 Jul 2014 12:08:32 GMT
Connection: keep-alive
{“this”:”succeeded”,”by”:”dweeting”,”the”:”dweet”,”with”:
{“thing”:”yourThingName”,”created”:”2014-07-24T12:08:32.443Z”,
“content”:{“temperature”:25,”humidity”:35,”light”:59}}}

You can also check online that the data was correctly recorded. Just type in a browser:

https://dweet.io/get/dweets/for/yourThingName

Of course, you have to replace the name with the name of thing you entered in the Arduino sketch. You should see that at least one measurement was inserted for this thing. For example:

{
 "thing": "weather_station_1a2cx3s8",
 "created": "2014-07-13T12:58:10.924Z",
 "content": {
 "temperature": 26,
 "humidity": 40,
 "light": 69
 }
}

In case it is not working at this point, there are several things you can check. First, make sure that you Internet connection is up and running, and that your Arduino board is actually connecting to your WiFi network. You can also check that the answer from the Dweet.io website is correct. Finally, make sure that you correctly entered your ‘Thing’ name inside the Arduino sketch.

Displaying the Measured Data

We are now able to store data in the cloud, using the dweet.io service. Your Arduino board is now continuously sending data over there. However, even if the data it returns is human-readable, it would be much better to visualize this data graphically. This is why we created an account on Freedboard before. Go over to this website again and log in:

https://www.freeboard.io/

Inside this interface, you will be able to create a new dashboard. This will be the main interface from which you will monitor everything. Do so by entering a name for your dashboard, and click on “Create New”. Then, you have to create two things: panes and datasources.

Let’s start with the datasource, which is the source of the data that will be displayed inside the dashboard. Click on “Add” to add a new data source, and select “Dweet.io” in the menu:

Create Your Internet of Things Dashboard

Inside this box, you also need to enter a name, and the name of your thing that you defined in the Arduino sketch. Then, click on “Save”.

Now, we need to create a new pane. A pane is basically a space on the dashboard where the data is displayed graphically. Click on the button, and then click on the pane “+” icon to add a widget. These widgets will display the data itself. I created three different panes, so I can display all the recorded data at the same time. I started with text widgets:

Create Your Internet of Things Dashboard

The most important thing here is to select the “Value” field by clicking on “+ Datasource” on the right. This will directly link the widget with the data coming from dweet.io. For example, you can name your first widget ‘temperature’, and then link it to the temperature field of the datasource we defined earlier.

This is the result I got with three text widgets:

Create Your Internet of Things Dashboard

I also played with the interface, and changed these widgets for gauges widgets, but based on the same data:

Create Your Internet of Things Dashboard

You can also notice that the data is changing in live depending on the measured data. This means that you can now monitor this data from anywhere in the world, just by having the URL of your dashboard.

In case it is not working at this point, make sure that the data is correctly received by the Dweet.io website first. Also make sure that you entered the correct ‘Thing’ name inside your Freeboard.io dashboard.

How to Go Further

Let’s summarize what you have learned in this article. You just learned how to send measurements from your Arduino board to the cloud, so this data can be accessed from outside of your local WiFi network. We also saw how to monitor this data from a central online dashboard, so you can monitor it from anywhere.

You can, of course, improve this project in many ways. The first one is to add more sensors to the project, for example a wind speed sensor or a smoke sensor. You can also install many of these boards around your home, all uploading data to a different “thing” on dweet.io. Then, you can use what you learned about Freeboard to monitor all these measurements from a central place.

Want to learn more? Get my free eBook about Arduino!

Arduino is an amazing platform that you can use to build all sorts of projects. Download today my free eBook "Building a Simple Alarm System with Arduino". Simply click on the button below!

Leave a Comment

navy eng a year ago
Hello Marco, Along your tutorials and some comments I finally get the project done, Thank you so much, those comments really save my time. There is one problem further. We have the board run by connecting to computer with USB and start Serial Monitor and we get the data in the Serial, and dweet. I try to disconnect microUSB from computer and instead use jack power supply. The board seem not to start up. It should not just be working computer, right?
Reply
abdella navy eng 9 months ago
how to predict the future temperature and humidity
Melissa Cavallo a year ago
Hello All,I was wondering if there was a way to have a button on freeboard and when pressed it sends data through dweet or straight to Ardiuno to say turn on a led light on the Ardiuno?
Reply
Abby Lemon a year ago
The cc3000 has been discontinued can you show how to send data using ATWINC1500? Thank you!
Reply
Naman Dosi a year ago
Hi Marco!!I loved the way you described the whole thing. I have one doubt, it would be really great if you could help me out. I want to use gas sensor(MQ2) instead of the temperature and humidity sensors. So what should i do as in how should i proceed?
Reply
Nitin a year ago
I want to use NODEMCU somebody help with code
Reply
Ahmed 2 years ago
Can I use the ESP8266 module instead of the CC300 one?
Reply
Andy 2 years ago
Hi,I've pulled the code and made some amends to measure different values, everything appears to work well and writes to dweet correctly but for some reason my upload often crashes after three successful dweets. It appears to be getting stuck on the following line in serial monitor.Checking WiFi connection ...done.Sending request... done.Reading answer...HTTP/1.1 200 OKAccess-Control-Allow-Origin: *Content-Type: application/jsonContent-Length: 198Date: Wed, 15 Feb 2017 16:04:57 GMTConnection: close{"this":"succeeded","by":"dweeting","the":"dweet","with":{"thing":"BogLog1234","created":"2017-02-15T16:04:57.064Z","content":{"proximity":801},"transaction":"5e6e7ae7-9789-4e58-90c2-24447ded2529"}}Any ideas would be greatly appriciated.Thanks,Andy
Reply
Jonathan Galdino 2 years ago
Hello, i'm using your code. It looks great!But I have a question.When I try to send the data collected from my sensors, check the answer that I get from the server (when I try to establish a HTTP Request to dweet io)Also, you can find "my" code right here: https://github.com/JohnzBal...---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Ola, bem vindo ao PMS - Plant Monitoring System (Sistema de Monitoramento de Plantas) Iniciando o Shield WiFi....MAC Adress do Shield Wifi: 0x00 0x19 0x94 0x37 0x35 0x39Tentando conectar a rede: pmsConectado!Requisitando IP via DHCP...--- CONECTANDO O WIFI ---www.dweet.io -> 52.7.51.248Enviando o request... Pronto.Lendo a resposta do servidor...HTTP/1.0 502 Bad GatewayServer: squidDate: Mon, 10 Oct 2016 18:14:26 GMTContent-Type: text/htmlContent-Length: 946X-Squid-Error: ERR_ZERO_SIZE_OBJECT 0X-Cache: MISS from proxy-utfpr-shX-Cache-Lookup: MISS from proxy-utfpr-sh:3128Via: 1.0 proxy-utfpr-sh:3128 (squid)Connection: close<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>ERRO: A URL solicitada não pode ser recuperada</title><style type="text/css"></style></head><body><h1>ERRO</h1><h2>A URL solicitada não pode ser recuperada</h2><hr noshade="" size="1px">Na tentativa de recuperar a URL:http://dweet.io/dweet/for/pmsbyutfpr?O seguinte erro foi encontrado:<ul><li>Resposta com tamanho zero</ul>Squid não recebeu nenhum dado para esta requisição.<hr noshade="" size="1px"><address>Generated Mon, 10 Oct 2016 18:14:26 GMT by proxy-utfpr-sh (squid)</address></body></html>Fechando a conexão...---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------That's it. I can't send any data to dweet and I'm kind worry about what I can do to fix it.I hope you can help me :)Regards!
Reply
Arun Boddu 2 years ago
Hello, after uploading the code , I am not getting response from dweet.iohere is my code#include <spi.h>#include <wifi.h>#include <wificlient.h>// WiFi ClientWiFiClient client;// Your network name also called SSIDchar ssid[] = "Aj101bc01";// your network passwordchar password[] = "1234567890";// your network key Index number (needed only for WEP)int keyIndex = 0;// Dweet parameterschar * server_name = "www.dweet.io";#define thing_name "Res rate"void setup() { Serial.begin(115200); // Initialize serial communication // 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); } // Pin for the PIR sensor pinMode(RED_LED, OUTPUT); 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); }}void loop() { // Measure motion //int motion = digitalRead(8); int sensorValue=analogRead(A3); Serial.println(sensorValue); /*// Measure temperature & humidity float temperature, humidity; if (dht::readFloatData(10, &temperature, &humidity, false) == 0) { Serial.print("T: "); Serial.print(temperature); Serial.print(" H: "); Serial.println(humidity); } */ // Send data to server if (client.connect(server_name, 80)) { Serial.println("Connected"); Serial.print(F("Sending request... ")); client.print(F("GET /dweet/for/")); client.print(thing_name); client.print(F("&sensorValue=")); client.print(sensorValue); client.println(F(" HTTP/1.1")); client.println(F("Host: dweet.io")); client.println(F("Connection: close")); client.println(F("")); Serial.println(F("done.")); } // Read answer Serial.println(F("Reading answer...")); while (client.connected()) { while (client.available()) { char c = client.read(); Serial.print(c); } } Serial.println(F("")); // Close connection client.stop(); Serial.println(F("Closing connection")); Serial.println(F(""));}please help me to find out the solution
Reply
Marco Schwartz Arun Boddu 2 years ago
This tutorial is for the CC3000 chip only :)
nishant 2 years ago
hello my code is not working in serial monitor it is not getting the ip address of dweet.io
Reply
Arun Boddu nishant 2 years ago
I have the same issue ... did you find the solution
yeastor 3 years ago
I use nice Stergraph application for android for create dweet.io dashboard
Reply
Kittipong Klunbut 3 years ago
Hello, Code it good work ahh , I have a question Help me please T_T"How to make data logger for check data in former-------------------------------------------------------------------------------------------#include <adafruit_cc3000.h>#include <spi.h>#include <avr wdt.h="">// Define CC3000 chip pins#define ADAFRUIT_CC3000_IRQ 3#define ADAFRUIT_CC3000_VBAT 5#define ADAFRUIT_CC3000_CS 10// Create CC3000 instancesAdafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2); // you can change this clock speed// WLAN parameters#define WLAN_SSID "jimmy"#define WLAN_PASS "taoprempunmay408"#define WLAN_SECURITY WLAN_SEC_WPA2#define thing_name "test2"uint32_t ip;void setup(void){ // Initialize Serial.begin(115200); Serial.println(F("\nCC3000 Initializing...")); if (!cc3000.begin()) { Serial.println(F("Couldn't begin()! Check your wiring?")); while (1); } // Connect to WiFi network Serial.print(F("Connecting to WiFi network ...")); cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY); Serial.println(F("done!")); /* Wait for DHCP to complete */ Serial.println(F("Request DHCP")); while (!cc3000.checkDHCP()) { delay(100); } while (! displayConnectionDetails()) { delay(1000); }}void loop(void){ // Start watchdog wdt_enable(WDTO_8S); // Get IP uint32_t ip = 0; Serial.print(F("www.dweet.io -> ")); while (ip == 0) { if (! cc3000.getHostByName("www.dweet.io", &ip)) { Serial.println(F("Couldn't resolve!")); } delay(500); } cc3000.printIPdotsRev(ip); Serial.println(F("")); // Reset watchdog wdt_reset(); // Check connection to WiFi Serial.print(F("Checking WiFi connection ...")); if (!cc3000.checkConnected()) { while (1) {} } Serial.println(F("done.")); wdt_reset(); // Send request Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80); if (client.connected()) { Serial.print(F("Sending request... ")); client.fastrprint(F("GET /dweet/for/")); client.print(thing_name); client.fastrprint(F("?latitude=")); client.print("CodeitWork!!"); client.fastrprint(F("&longitude=")); client.print("Doitagian "); client.fastrprintln(F(" HTTP/1.1")); client.fastrprintln(F("Host: dweet.io")); client.fastrprintln(F("Connection: close")); client.fastrprintln(F("")); Serial.println(F("done.")); } else { Serial.println(F("Connection failed")); return; }----------------------------------------------------------------------- // Reset watchdog wdt_reset(); Serial.println(F("Reading answer...")); while (client.connected()) { while (client.available()) { char c = client.read(); Serial.print(c); } } Serial.println(F("")); // Reset watchdog wdt_reset(); // Close connection and disconnect client.close(); Serial.println(F("Closing connection")); Serial.println(F("")); // Reset watchdog & disable wdt_reset(); wdt_disable(); // Wait 60 seconds until next update wait(5000);}// Wait for a given time using the watchdogvoid wait(int total_delay) { int number_steps = (int)(total_delay / 5000); wdt_enable(WDTO_8S); for (int i = 0; i < number_steps; i++) { //Serial.println(F("Waiting for 5 seconds ...")); delay(1000); wdt_reset(); } wdt_disable();}bool displayConnectionDetails(void){ uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; if (!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) { Serial.println(F("Unable to retrieve the IP Address!\r\n")); return false; } else { Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); Serial.println(); return true; }}
Reply
Slavoljub Petkovic 3 years ago
Hello, Can anyone help me address this issue bellow...I added rain sensor and i was able to manage the code and everything checks in on dashboard however i am getting values like 1023 when there is no water on the sensor and when there is i get much lower values than that depending how much water is on the surface of the sensor. Now, i want to get percent of rain that drops on that sensor. I saw similar sketch but they did it with mapping which i don`t understand really. So how do i convert these measurements in correct percent? // Measure light level float sensor_reading = analogRead(A0); light = (int)(sensor_reading/1024*100); // Measure rain level float sensor_reading1 = analogRead(A1); rain = (int)(sensor_reading1/1024*100); Serial.println(F("Measurements done")); I tried using only sensor_reading1/1024 which would theoretically give me percent% but for some reason i am getting constantly zero then.Any idea how to change that line correctly?
Reply
Daniel 3 years ago
Very clear starters guide that appears fully trustable. Order has been placed to try this on my own. Even though the project is "simple" it demonstrates key elements useful for future projects, especially the ability to access the data online. Thank you, Marco.
Reply
Wahyu Aji Sasongko 3 years ago
Hello Marco,can we send a value as a threshold from freeboard to arduino? so i can change the threshold variable arduino via internet.thank you Sir.
Reply
Marco Schwartz Wahyu Aji Sasongko 3 years ago
Hello! This project doesn't really allow to send data back to the Arduino. To do so look at my aREST project: http://arest.io/arduino-eth...
Denny Denis 3 years ago
Thank you Marco for nice tutorial how to call api using Uno and CC3000, all were working smooth for me, even i used random generator to simulate values and i have learned dweet.io and freeboard.cc as well. Very good guide for such newbie as me.
Reply
Marco Schwartz Denny Denis 3 years ago
You're welcome!
Viktor Gjorgjiev 3 years ago
Hallo Marco. I am trying your tutorial with the ethernet schield. Can you please help me with the connection to dweet? Thanks, Viktor
Reply
Marco Schwartz Viktor Gjorgjiev 3 years ago
Hello Viktor, I don't have yet a tutorial with the Ethernet shield + Dweet, but the code is really similar :)
Pedro Gonçalves 4 years ago
Marco, hello, ou ignore me hehe, my send request is too slow, turn 5min for send my datas, why?thanks
Reply
Pedro Gonçalves 4 years ago
Hello Marco , I'm sorry to disturb Once Again , Now with Your example could do work, but ONLY with static data (eg humidity = 1 only ) to do in "real time" data be collected every 1 second as in the example in the dweet.io site ( https://dweet.io/follow/gmx... ) as would be the GET that? for the loop take more data and fast . thank Marco for his contributions
Reply
Marco Schwartz Pedro Gonçalves 4 years ago
I guess real-time will be difficult with the hardware of this project indeed. It's perfect to be used with slow-changing variables like temperature or humidity.
Guest 4 years ago
This is what I am only getting, please help me Marco Schwartz, I am nearly there in finishing my project with the help of using your intelligent code. Thank you!All Im getting in serial monitor is this:Initializing...Connecting to WiFi network ...done!Request DHCPMeasurements donewww.dweet.io -> 54.84.241.136Checking WiFi connection ...done.Sending request...
Reply
Marco Schwartz Guest 4 years ago
Hey Billy! As mentioned earlier check the firmware of your CC3000 chip and update it if necessary.
xQubeZx Guest 4 years ago
I had to update mine to 1.13 i think it was, beacuse the latest didnt work somehow. Just try a few different firmwares. (Only the 3 latest or so)
Pedro Gonçalves 4 years ago
hello Mark , I'm using your code to measure water flow , I could not even work , this is my modified code , you can take a look ? thank you/*************************************************** This is a sketch to use the CC3000 WiFi chip & Dweet.io Written by Marco Schwartz for Open Home Automation ****************************************************/// Libraries#include <adafruit_cc3000.h>#include <spi.h>//#include "DHT.h"#include <avr wdt.h="">// Define CC3000 chip pins#define ADAFRUIT_CC3000_IRQ 3#define ADAFRUIT_CC3000_VBAT 5#define ADAFRUIT_CC3000_CS 10// DHT sensor//#define DHTPIN 7//#define DHTTYPE DHT11int vazao; //Variável para armazenar o valor em L/min//float media=0; //Variável para tirar a média a cada 1 minutoint contaPulso; //Variável para a quantidade de pulsos//int i=0; //Variável para contagem// Create CC3000 instancesAdafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2); // you can change this clock speed// DHT instance//DHT dht(DHTPIN, DHTTYPE);// WLAN parameters#define WLAN_SSID "Rede Vale"#define WLAN_PASS "valeinfo!11"#define WLAN_SECURITY WLAN_SEC_WPA2// Dweet parameters#define thing_name "watercost_25262728293031"//Variables to be sent//int temperature;//int humidity;//int light;uint32_t ip;void setup(void){ // Initialize Serial.begin(115200);// Serial1.begin(9600); //Inicia a serial com um baud rate de 9600 attachInterrupt(0, incpulso, RISING); //Configura o pino 2(Interrupção 0) para trabalhar como interrupção Serial.println("\n\nInicio\n\n"); //Imprime Inicio na serial Serial.println(F("\nInitializing...")); if (!cc3000.begin()) { Serial.println(F("Couldn't begin()! Check your wiring?")); while(1); } // Connect to WiFi network Serial.print(F("Connecting to WiFi network ...")); cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY); Serial.println(F("done!")); /* Wait for DHCP to complete */ Serial.println(F("Request DHCP")); while (!cc3000.checkDHCP()) { delay(100); }}void loop(void){ contaPulso = 0; //Zera a variável para contar os giros por segundos sei(); //Habilita interrupção delay (1000); //Aguarda 1 segundo cli(); //Desabilita interrupção vazao = contaPulso / 5.5; //Converte para L/min // media=media+vazao; //Soma a vazão para o calculo da media// i++; /* Serial.print(vazao); //Imprime na serial o valor da vazão Serial.print(" L/min - "); //Imprime L/min Serial.print(i); //Imprime a contagem i (segundos) Serial.println("s");*/ //Imprime s indicando que está em segundos // Measure from DHT// float t = dht.readTemperature(); // float h = dht.readHumidity();// temperature = (int)t; // humidity = (int)h; // Measure light level // float sensor_reading = analogRead(A0); // light = (int)(sensor_reading/1024*100); // Serial.println(F("Measurements done")); // Start watchdog // wdt_enable(WDTO_8S); // Get IP uint32_t ip = 0; Serial.print(F("www.dweet.io -> ")); while (ip == 0) { if (! cc3000.getHostByName("www.dweet.io", &ip)) { Serial.println(F("Couldn't resolve!")); } delay(500); } cc3000.printIPdotsRev(ip); Serial.println(F("")); // Reset watchdog // wdt_reset(); // Check connection to WiFi Serial.print(F("Checking WiFi connection ...")); if(!cc3000.checkConnected()){while(1){}} Serial.println(F("done.")); wdt_reset(); // Send request Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80); if (client.connected()) { Serial.print(F("Sending request... ")); client.fastrprint(F("GET /dweet/for/")); client.print(thing_name); client.fastrprint(F("&vazao=")); client.print(vazao); client.fastrprintln(F(" HTTP/1.1")); client.fastrprintln(F("Host: dweet.io")); client.fastrprintln(F("Connection: close")); client.fastrprintln(F("")); Serial.println(F("done.")); } else { Serial.println(F("Connection failed")); return; } // Reset watchdog wdt_reset(); Serial.println(F("Reading answer...")); while (client.connected()) { while (client.available()) { char c = client.read(); Serial.print(c); } } Serial.println(F("")); // Reset watchdog wdt_reset(); // Close connection and disconnect client.close(); Serial.println(F("Closing connection")); Serial.println(F("")); // Reset watchdog & disable wdt_reset(); wdt_disable(); // Wait 60 seconds until next update wait(60000);}// Wait for a given time using the watchdogvoid wait(int total_delay) { int number_steps = (int)(total_delay/5000); wdt_enable(WDTO_8S); for (int i = 0; i < number_steps; i++){ //Serial.println(F("Waiting for 5 seconds ...")); delay(5000); wdt_reset(); } wdt_disable();}void incpulso (){ contaPulso++; //Incrementa a variável de contagem dos pulsos}
Reply
patscomputerservices 4 years ago
What changes would need to be made to use a Raspberry Pi B (or B+) with this, instead of the Arduino Uno?
Reply
Marco Schwartz patscomputerservices 4 years ago
Actually it would be quite simple! You will need to send the exact same HTTP request from your Pi, for example using Node.js.
Justin Martin 4 years ago
MarcoJust wondering if you could help me with something.I am trying to figure out how I can add a dust sensor and a rain drop sensor to your code for the dashboard IOT. I am new to arduino and am using it for prototyping a thesis project and need to know the best way to add these new sensors.BestJustin
Reply
Marco Schwartz Justin Martin 4 years ago
Hey Justin, that would be really easy to do. Just get the right code to read from your new sensors & then follow exactly the same principles from this article.
xQubeZx 4 years ago
Hello,Im having some problems. It seems to work exept that it wont connect to dweet.io it just print this:Initializing...Connecting to WiFi network ...done!Request DHCPwww.dweet.io -> 127.0.0.1Checking WiFi connection ...done.
Reply
xQubeZx xQubeZx 4 years ago
I solved the problem :)I just had to do a firmware update took a while to figure it out though
krazz 4 years ago
Thanks for the hard work Marco. I having issues with my setup and maybe you could assist. I am using just the temp and humidity portion using a DHT22 sensor. The wifi is connecting fine, and it looks to be connecting to dweet fine, but the response from dweet looks to be incorrect, and freeboard is not manipulating the data correctly either. Here is what I did with the adruino sketch:// Send requestAdafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);if (client.connected()) {Serial.print(F("Sending request... ")); client.fastrprint(F("GET /dweet/for/"));client.print(thing_name);client.fastrprint(F("?temperature="));client.print(temperature);client.fastrprint(F("?humidity="));client.print(humidity);client.fastrprintln(F(" HTTP/1.1"));client.fastrprintln(F("Host: dweet.io"));client.fastrprintln(F("Connection: close"));client.fastrprintln(F("")); Serial.println(F("done."));} else {Serial.println(F("Connection failed")); return;}and here is what I get back in serial monitor:Measurements donewww.dweet.io -> 54.88.231.110Checking WiFi connection ...done.Sending request... done.Reading answer...HTTP/1.1 200 OKAccess-Control-Allow-Origin: *Content-Type: application/jsonContent-Length: 166Date: Sun, 14 Dec 2014 23:44:03 GMTConnection: close{"this":"succeeded","by":"dweeting","the":"dweet","with":{"thing":"Humidor_2x3546xb","created":"2014-12-14T23:44:03.289Z","content":{"temperature":"17?humidity=48"}}}Closing connectionThis is what it looks like on my dweet thing page:{"this":"succeeded","by":"dweeting","the":"dweet","with":{"thing":"Humidor_2x3546xb","created":"2014-12-14T23:34:05.743Z","content":{}}}Any help would be greatly appreciated.
Reply
Marco Schwartz krazz 4 years ago
Thanks! I think the issue is in this line:client.fastrprint(F("?humidity="));It should be:client.fastrprint(F("&humidity="));Hope that will solve the problem!
Vageesh Joshi 4 years ago
Thanks Marco. I had used &light= in place of ?light= . Its working fine now :) looking forward to a project which sends commands back from the dashboard to the Arduino. Big fan of you..!
Reply
Marco Schwartz Vageesh Joshi 4 years ago
Great to hear that it is working! Thanks!
Vageesh Joshi 4 years ago
Hi Marco. I am trying to upload light sensor data to dweet.io with no success.(I have not used the temperature and humidity sensor) I used the "iotdashboard" code from your github repository. The serial monitor output is as follows. Please help.Measurements donewww.dweet.io -> 54.88.231.110Checking WiFi connection ...done.Sending request... done.Reading answer...HTTP/1.1 200 OKAccess-Control-Allow-Origin: *Content-Type: application/jsonContent-Length: 140Date: Tue, 11 Nov 2014 10:55:17 GMTConnection: close{"this":"succeeded","by":"dweeting","the":"dweet","with":{"thing":"vagi8084ldr&light=32","created":"2014-11-11T10:55:17.596Z","content":{}}}Closing connectionMeasurements donewww.dweet.io -> 54.88.231.110Checking WiFi connection ...done.Sending request... done.Reading answer...HTTP/1.1 200 OKAccess-Control-Allow-Origin: *Content-Type: application/jsonContent-Length: 140Date: Tue, 11 Nov 2014 10:55:20 GMTConnection: close{"this":"succeeded","by":"dweeting","the":"dweet","with":{"thing":"vagi8084ldr&light=34","created":"2014-11-11T10:55:20.498Z","content":{}}}
Reply
Marco Schwartz Vageesh Joshi 4 years ago
Hello Vageesh, thanks for using my code! I think you just forgot to use: ?light= in the code, as you can see your content field is empty on the answer coming back from Dweet. Fix that and it will work :)
zerul 4 years ago
Hello sir, can i ask something about this project. It is possible i put the webcam for this project and then the picture will send to the freeboard.
Reply
Marco Schwartz zerul 4 years ago
With a standard TTL camera that should definitely be possible :)
Brad Snedeker 4 years ago
Hi Marco... Big fan since your first book. Is it possible thru those dashboard services to send commands back to the arduino from the dashboard? Is there Home automation software that you know of that can supply this type of two way processing?TIABrad
Reply
Marco Schwartz Brad Snedeker 4 years ago
Hey Brad, thanks a lot for the comment! That's not a simple as the other way. If you are using the Ethernet shield there is a project to do that:https://www.teleduino.org/But this is also something I am working on in my aREST project, so stay tuned for an announcement soon!
zerul 4 years ago
Hello... I want ask something about CC3000 WIFI Breakout. I don't have this component but can i use the another CC3000 WIFI SHIELD and the how i to connect the CC3000 WIFI SHIELD with arduino Uno
Reply
Marco Schwartz zerul 4 years ago
You can definitely use the CC3000 shield as well for the project, the code is the same and you just have to plug the shield to your Uno board !
Shares
Create Your Internet of Things Dashboard Create Your Internet of Things Dashboard Create Your Internet of Things Dashboard Create Your Internet of Things Dashboard Create Your Internet of Things Dashboard Create Your Internet of Things Dashboard
Someone from Spain
Recently signed up
4 months ago
Someone from the United States
Recently visited this page
4 hours ago
Someone from Colombia
Recently visited this page
8 hours ago
Someone from the United States
Recently visited this page
9 hours ago
Someone from Bulgaria
Recently visited this page
12 hours ago
Someone from Bulgaria
Recently visited this page
12 hours ago
Someone from Netherlands
Recently visited this page
14 hours ago
Someone from Germany
Recently visited this page
14 hours ago
Someone from Germany
Recently visited this page
14 hours ago
Someone from Hong Kong
Recently visited this page
14 hours ago
Someone from Brazil
Recently visited this page
16 hours ago