Connect ESP8266 + Arduino with FlowThings

You will learn how to connect arduino with flowthings.io

Step 1

What we need

We need :

  1. Arduino UNO
  2. ESP8266 01
  3. Breakout board for ESP
  4. Wires
  5. DHT22
  6. Resistor(4.7kOhm)
Step 2

Put firmware

First we need to put firmware on esp8266 you can do that on this http://cityos.io/tutorial/1935/How-to-put-AT-firmware-ON-ESP8266

Step 3

Add esp library in Arduino IDE

  • Click on link and download library for Arduino ide from Sparkfun. link
  • If you don't know how to put library in Arduino ide follow this tutorial How to put arduino library.
  • Library is from Sparkfun.
Step 4

Set baud rate

Connect breakout(esp8266) to ftdi as :

ftdi---------esp8266

rx-------------tx

tx-------------rx

gnd------------gnd

3,3v-------------vcc

  • Than open a Arduino IDE .
  • Open serial monitor .
  • Set baud rate to 115200(default esp).
  • write "AT" (without quotes) and if you see "ok" esp is working
  • Than send this command "AT+UART_DEF=9600,8,1,0,0" this mean that you will change esp baudrate to 9600 after this reset a ftdi and test again but change baud rate in serial monitor to 9600.
  • Send again "AT" and test.
Step 6

Fetch your FlowThings master token

We’ll use this token to authenticate all of our requests to th FlowThings platform.

Step 7

Sensor connection

Connect dht22 sensor as on the picture

Step 8

Fetch your FlowThings master token

We’ll use this token to authenticate all of our requests to th FlowThings platform.

Step 9

Create a Flow

Go to the Flows section of your Devepolers Dashboard, and create a new Flow.

Flow is a queriable real-time stream of data. The data is represented by Drops, data entities implemented as JSON objects, boosted by rich metadata.

Step 10

Enter Flow data

Call the new Flow meteo and hit the Save button.

Step 11

Add a Drop

You can add a Drop to a Flow manually by clicking the New button in the Drops section.

Step 12

Enjoy your new Drop

You can now see a new Drop in the Drop list. If you select it, you’ll see all the metadata FlowThings added to it.

Step 13

Test the sensor with some code

Download library from here Library

 #include "DHT.h"
 
 DHT dht;

 void setup()
{
  Serial.begin(9600);
  Serial.println();
  Serial.println("StatustHumidity (%)tTemperature (C)t(F)");

  dht.setup(2); // data pin 2
}

void loop()
{
  delay(dht.getMinimumSamplingPeriod());

 float humidity = dht.getHumidity();
 float temperature = dht.getTemperature();

 Serial.print(dht.getStatusString());
 Serial.print("t");
 Serial.print(humidity, 1);
 Serial.print("tt");
 Serial.print(temperature, 1);
 Serial.print("tt");
 Serial.println(dht.toFahrenheit(temperature), 1);
}
Step 14

Write a code for wifi

`

#include "DHT.h"
#include <SoftwareSerial.h>
#include <SparkFunESP8266WiFi.h>

DHT dht;

const char mySSID[] = "ssidname";//wifi ssid
const char myPSK[] = "password";//wifi pw

const String flowServer = "169.53.41.241"; //flow server

char* token = "xxxxxxxxxxx";//flow master token



void setup() 
{

int status;
Serial.begin(9600);
status = esp8266.begin();
if (status <= 0)
{
Serial.println(F("Unable to communicate with shield. Looping"));
while(1) ;
}

esp8266.setMode(ESP8266_MODE_STA); // Set WiFi mode to station
if (esp8266.status() <= 0) // If we're not already connected
{
if (esp8266.connect(mySSID, myPSK) < 0)
{
  Serial.println(F("Error connecting"));
  while (1) ;
}    
}
dht.setup(2); // data pin 2
}

void loop()
{

dropToFlow();
delay(500);
}

void dropToFlow()
{

// Create a client, and initiate a connection
 ESP8266Client client;

if (client.connect(flowServer, 80) <= 0)
{
Serial.println(F("Failed to connect to server."));
return;
}
Serial.println(F("Connected."));

 // Set up our Flow post parameters:
String data = "{"path":"/salca/meteo","elems":{"temp":"+String(temp())+","humid":"+ String(humid())+"}}";

client.println("POST /v0.1/salca/drop HTTP/1.1"); //change "salca" to your username
client.println("Host: api.flowthings.io");
client.println("Connection: close");
client.print("X-Auth-Token: ");
client.println(token);
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);



// available() will return the number of characters
// currently in the receive buffer.
while (client.available())
Serial.write(client.read()); // read() gets the FIFO char

// connected() is a boolean return value - 1 if the 
// connection is active, 0 if it's closed.
if (client.connected())
 client.stop(); // stop() closes a TCP connection.
 }



float temp(){
float temp1 = dht.getTemperature();
 return temp1;
}

float humid(){
float humid1 = dht.getHumidity();
return humid1;
}

`

  • Change a code as i commented and upload it you should see drops on your flow

Tutorial Forum

There are no posts here yet. Add the first post