Using Dweet

Posted on
  • getDweet.js 20 Aug2016
    Incorporates the Dweet example into code that connects the ESP8266 to WiFi.
    Setup parameters at the beginning of the code:

    //set DweetID to a unique value
    var DweetID="esp0912";
    
    // Select Espruino Bd or Pico hardware
    //var Hardware=0; //Espruino board
    var Hardware =1; //PICO
    
    //setup WiFi access parameters
    var SSID="xxxx";
    var 
    

    On the IOT page
    http://www.espruino.com/IoT+Services
    the link “quite a lot” returns a “Nothing out there” error
    http://www.postscapes.com/companies/iot-cloud-services

    Output of getdweet.js

    >echo(0);
    Start
    Start connection process
    Waiting for ESP8266 response
    =undefined
    Reset the ESP8266
    Connecting to WiFi
    Wi-Fi Connected
    IP=  192.168.1.4
    null
     
    put res.headers  {
      "Access-Control-Allow-Origin": "*",
      "Content-Type": "application/json",
      "Content-Length": "197",
      "Date": "Tue, 30 Aug 2016 16:49:56 GMT",
      "Connection": "close"
     }
    {"this":"succeeded","by":"dweeting","the":"dweet","with":{"thing":"esp0912","created":"2016-08-30T16:49:56.321Z","content":{"hello":"world99"},"transaction":"176f2d59-c8ff-4166-97e7-4ebaa01c3064"}}
     
    get res.headers  {
      "Access-Control-Allow-Origin": "*",
      "Content-Type": "application/json",
      "Content-Length": "146",
      "Date": "Tue, 30 Aug 2016 16:49:56 GMT",
      "Connection": "close"
     }
    {
      "hello": "world99"
     }
    

    Note that the data are appended to the URL in the putDweet() function.

      var options = {
        host: 'dweet.io',
        port: '80',
        path:'/dweet/for/'+dweet_name+"?"+data,
        method:'POST'
      };
    

    But in the Cubitic example the data (content) is not added to the end of the URL in the header but is sent after the header in the last line the function by the function call end(content).

    function putCubitic(event, data) {
      content = JSON.stringify(data);
      var options = {
        host: 'api.cubitic.io',
        port: '80',
        path:'/v1/event/'+event,
        method:'POST',
        headers: { 
          "Content-Type":"application/json",
          "cubitic-appid":CUBITIC.APPID, 
          "Authorization":"Bearer "+CUBITIC.TOKEN,
          "Content-Length":content.length 
        }
      };
      require("http").request(options, function(res)  {
        var d = "";
        res.on('data', function(data) { d+= data; });
        res.on('close', function(data) {
          console.log("Closed: "+d);
        });
      }).end(content);
    }
    

    1 Attachment

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Using Dweet

Posted by Avatar for ClearMemory041063 @ClearMemory041063

Actions