element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Internet of Things
  • Technologies
  • More
Internet of Things
Blog Old meets new, the 1-Wire Weather Station on the SPARK Core. (part 3)
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Internet of Things requires membership for participation - click to join
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: gpolder
  • Date Created: 6 Dec 2014 11:21 AM Date Created
  • Views 875 views
  • Likes 1 like
  • Comments 4 comments
  • html
  • weather_station
  • 1-wire
  • embedded_webserver
  • 1_wire_bus
  • internet_of_things
  • spark_core
  • one_wire
  • iot
Related
Recommended

Old meets new, the 1-Wire Weather Station on the SPARK Core. (part 3)

gpolder
gpolder
6 Dec 2014

In Old meets new, the 1-Wire Weather Station on the SPARK Core. (part 1) I described the motivation of the project. In Old meets new, the 1-Wire Weather Station on the SPARK Core. (part 2) the first steps of programming the SPARK Core and interfacing it to the 1-Wire bus are described. I showed how the bus was scanned, and temperature values measured, but output was only sent to the serial USB port. Not really an The Internet of Things approach. I will now first look at the possibilities to present the weather data to the outside world. In later blogposts I will go into more detail about the hardware and software for a full functioning IoT weather station.


The old days, a local Webserver

In the old days of the TINI java controller the data was presented on a web page which was hosted on the device itself using a small HTTP server. This approach is also possible on the SPARK Core. Using the webserver library which was derived from the webduino library.

Here is the code to publish the device scan on a webpage. Each time the page is refreshed, a new device scan is carried out.

// This #include statement was automatically added by the Spark IDE.
#include "WebServer/WebServer.h"
#include "OneWire/OneWire.h"
#include "OWSensor.h"


#define NUM_SENSORS 10
#define PREFIX ""
WebServer webserver(PREFIX, 80);
OneWire one = OneWire(D3);
uint8_t resp[9];
char myIpAddress[24];
char tempfStr[16];
double temperature = 0;
int test = 0;


//unsigned int lastTime = 0;

OWSensor sensors[NUM_SENSORS];
int checkIndex = 0;


void getTempBytes(uint8_t *rom) {
    // Get the temp
    one.reset();
    one.write(0x55);
    one.write_bytes(rom,8);
    one.write(0x44);
    delay(10);

    //ask for the temperature from
    one.reset();
    one.write(0x55);
    one.write_bytes(rom, 8);
    one.write(0xBE);
    one.read_bytes(resp, 9);
}


float getTemp(char unit) {
    byte MSB = resp[1];
    byte LSB = resp[0];

    float tempRead = ((MSB << 8) | LSB); //using two's compliment
    if (unit == 'F') {
        float TemperatureSum = tempRead / 16;

        //Multiply by 9, then divide by 5, then add 32
        float fahrenheit =  ((TemperatureSum * 9) / 5) + 32;

        if (fahrenheit > 7000) {
            fahrenheit = 7404 - fahrenheit;
        }
        return fahrenheit;
    } else {
        float celcius = tempRead * 0.0625;
        return celcius;
    }
}




void findDevices() {
    uint8_t addr[12];
    int found = 0;
    while(one.search(addr)) {
   
        webserver.print("<br>Found device: ");
   
        char *owID = new char[24];
        sprintf(owID, "%02x%02x%02x%02x%02x%02x%02x%02x%02x",
            addr[0],  addr[1], addr[2] , addr[3] , addr[4] , addr[5], addr[6], addr[7] , addr[8]
        );
        sensors[found].id = owID;
   
        for(int i=0;i<9;i++)
        {
            sensors[found].rom[i] = addr[i];
        }
   
        sensors[found].updated = 0;
   
        webserver.print(owID);
   
        if (addr[0] == 0x22) { //ds1822 temp sensor
            getTempBytes(sensors[found].rom);
            temperature = getTemp('C');
            sensors[found].value = temperature;
            webserver.print(" Temperature: " + String(temperature));
            sensors[found].updated = millis();
        }
        found++;
    }
}


void helloCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  server.httpSuccess();
  if (type != WebServer::HEAD)
  {
    P(helloMsg) = "<h1>1-Wire Weather on SPARK Core</h1>";
    server.printP(helloMsg);
    server.print("<pre>");
    findDevices();
    server.print("</pre>");
  }
}




void setup() {
    IPAddress myIp = WiFi.localIP();
    sprintf(myIpAddress, "%d.%d.%d.%d", myIp[0], myIp[1], myIp[2], myIp[3]);

    // setup webserver
    webserver.setDefaultCommand(&helloCmd);
    webserver.addCommand("index.html", &helloCmd);
    webserver.begin();
}



void loop() {
    char buff[64];
    int len = 64;


    /* process incoming connections one at a time forever */
    webserver.processConnection(buff, &len);
}


The following web page is produced when your browser connects to the SPARK Core:


image

Off-course this is a very simple example, but by adding some html and javascript you can make a fancy looking weather station webpage.


But.......


Is this really what we want? I don't think so. In the old TINI days there was not much as an alternative, other than sending your measurements to an weather server. But nowadays plenty of IoT dashboards are available to present your data in nice graphs.

This also  solves another problem of the approach described above. When the SPARK Core acts as an webserver, it needs an official ip address in order to give it access from the outside world. You have to make arrangements for that in your internet router, otherwise it is only available from your local network.


So next blogpost will explore the possibilities of some IoT dashboards.


Stay tuned...........


(BTW, feel free to post questions or comments)

  • Sign in to reply

Top Comments

  • gpolder
    gpolder over 10 years ago in reply to fvan +1
    Frederick, The SPARK Core is a nice little board with a lot of functionality, although there are some teething problems once and a while. The platform is certainly not mature currently. As you can see…
Parents
  • fvan
    fvan over 10 years ago

    How are your experiences with the Spark Core so far? Do you like it? I preordered some Spark Photons, but never worked with Core.

     

    Frederick

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • fvan
    fvan over 10 years ago

    How are your experiences with the Spark Core so far? Do you like it? I preordered some Spark Photons, but never worked with Core.

     

    Frederick

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • gpolder
    gpolder over 10 years ago in reply to fvan

    Frederick,

     

    The SPARK Core is a nice little board with a lot of functionality, although there are some teething problems once and a while. The platform is certainly not mature currently.

    As you can see on spark.io there are a lot of plans for the near future, but the deadlines are shifted sometimes.

    Debugging your software is a pain using the web interface since it takes minutes to download and rebooting the Core.

    There is also a possibility for local downloading using a command line interface (Spark Docs | Command Line) but still then it takes a lot of time before the Core is rebooted.

     

    Gerrit

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube