Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Start streaming on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
javier muñoz sáez
Published © GPL3+

ESP8266: Sending Data to an Online Deskboard

Easiest, cheapest and cleanest way to send small chunks of data. Wemos uploads data to Dweet.io and it is visualized via Freeboard.io.

IntermediateProtip1 hour10,410

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
dweet.io
freeboard.io

Story

Read more

Code

dweet that thang

Arduino
:) main code for dweeting , still in construction but working flawless
//coded for my wemos esp8266 pro mini, dweet.io posting
//Javier Muñoz Sáez 05/07/2017, javimusama@gmail.com
//////////////////wifi dweeting.io
// Import required libraries
#include "ESP8266WiFi.h"

// WiFi parameters
                    const char* ssid = "your wifi ssid";
                    const char* password = "password";
                    
  String thingName="TYPICALSENSORTHING"; 

const char* host = "dweet.io";


  String arrayVariableNames[]={"UNO","DOS","TRES","CUATRO","CINCO","SEIS","SIETE","OCHO"};//THIS WAY WE REFER TO EACH VARIABLE AS AN INDEX IN THIS GLOBAL ARRAY. arrayVariableNames[0]="UNO"
  int   arrayVariableValues[]={1,2,3,4,5,6,7,8};  
int numberVariables=sizeof(arrayVariableValues)/sizeof(arrayVariableValues[0]);//tells the number of arguments inside each array
//////////////////////////////

void setup() {
  Serial.begin(9600);
///////////wifi things
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  //initialice and connect to wifi lan
  WiFi.begin(ssid, password);  
  int retries = 0;
  while ((WiFi.status() != WL_CONNECTED) && (retries < 15)) {
    retries++;
    delay(500);
    Serial.print(".");
  }
  if(retries>14){
        Serial.println(F("WiFi conection FAILED"));
  }
  if (WiFi.status() == WL_CONNECTED) {
  Serial.println(F("WiFi connected"));
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println(F("======================================================")); 
  }
  
   Serial.println(F("Setup ready")); 


}

void loop() { 

arrayVariableValues[0]=25;//this is how you change values of the variables
arrayVariableValues[1]=42;
arrayVariableValues[2]=9;

arrayVariableNames[0]="veinticinco";//this is how you change the name of the variable( veinticinco=25)
dweetdata();//upload it
}

void dweetdata(){//connects TCP,sends dweet,drops connection, prints the server response on the console 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

    client.print(GetDweetStringHttpBuilder());

  delay(10);//slow doown ...stability stuff
  
  // Read all the lines of the reply from dweet server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  //just display ending conection on the serial port
  Serial.println();
  Serial.println("closing connection");
   
}

String GetDweetStringHttpBuilder() {
  int i=0;
  int numberVariables=sizeof(arrayVariableValues)/sizeof(arrayVariableValues[0]);//tells the number of arguments inside each array
  String dweetHttpGet="GET /dweet/for/";//initial empty get request
  dweetHttpGet=dweetHttpGet+String(thingName)+"?";//start concatenating the thing name (dweet.io)
  
  for(i=0;i<(numberVariables);i++){//concatenate all the variable names and values
   if(i==numberVariables-1){
    dweetHttpGet=dweetHttpGet + String(arrayVariableNames[i]) + "="+ String( arrayVariableValues[i]);//the lastone doesnt have a "&" at the end

   }
   else
    dweetHttpGet=dweetHttpGet + String(arrayVariableNames[i]) + "="+ String( arrayVariableValues[i]) + "&";  
  }
 dweetHttpGet=dweetHttpGet+" HTTP/1.1\r\n"+
                  "Host: " + 
                    host + 
                  "\r\n" + 
                  "Connection: close\r\n\r\n";
                  
  return dweetHttpGet;//this is our freshly made http string request
}

Credits

javier muñoz sáez

javier muñoz sáez

13 projects • 84 followers
Electronic engineer and sparky person. I make tutorials so my future self doesnt need to remember how he did the thing

Comments