Friday, August 25, 2023

Freeboard revisited 3: freeboard console

For an index to all my stories click this text.


What we are going to do.

For testing purposes I wanted to have some kind of console that can send data to Freeboard.



The above picture shows how the console looks. It is an HTML page (webpage) that resides on your harddisk and opens in your browser just by clicking on it.
The console sends at regular times (in this version every 10 seconds) a random value, the state of 2 simulated switches and the value of a slider to Dweet. That data then can be fetched by Freeboard.

Background.

The general idea is to build a complete IOT dashboard with Freeboard.
Freeboard is an IOT dashboard that is commercially and open-source available. A few years ago I wrote about Freeboard in this story: http://lucstechblog.blogspot.com/2019/10/freeboard.html
Unfortunately a few months after I published that story Freeboard was no longer available for free. If you used their servers you needed to pay a fee starting at 12$ a month. For most hobbyists that's a lot of money.

Fortunately Freeboard is also available on Github as open source. To use it you need to download the software and install it on your own webserver. I tried to put it on a github page. But that was not going to work. Read why Freeboard does not work on a Github page here: http://lucstechblog.blogspot.com/2023/08/freeboard-revisisted-part-1.html

So then I put it on a webpage, build on the free webhost service 000webhost (https://www.000webhost.com/) and that worked just fine as this story showed: http://lucstechblog.blogspot.com/2023/08/freeboard-revisited-2.html
In the end we are going to use Freeboard to display sensor data from ESP8266's and ESP32's and put virtual switches on Freeboard to switch lamps, fan's etc to build a complete home automation system.

How it is done

In the most simple setup Freeboard sends and gets it's data from Dweet. If you are not familiar with Dweet please read this story first: https://lucstechblog.blogspot.com/2019/05/dweet-volatile-iot-cloud-service.html

As our console is written in Javascript the first step is to analyse how you can send data from Javascript to Dweet. Well luckily that is easy with the fetch() command. Suppose your Thing name is dweettest and the data you are going to send is a fake temperature value. The fetch command looks like this:

fetch("https://dweet.io/dweet/for/dweettest?temp=22")

To send multiple values using the same thing we just have to expand this fetch command a bit.

fetch("https://dweet.io/dweet/for/dweettest?temp=22"+
       "&val1=12"+
       "&val2=28")


This example sends a fake temperature value of 22 and two other values named val1 and val2 (being 12 and 28) to dweet. So to send this to Dweet we have to make a small web-page which code looks like this:

<!DOCTYPE html>
<html>
<script>
    fetch("https://dweet.io/dweet/for/dweettest?temp=22"+
       "&val1=12"+
       "&val2=28")
</script>
</html>


Put this code in https://jsfiddle.net/ and run it.

Now open an empty webpage tab and paste this line into the url:
https://dweet.io/get/latest/dweet/for/dweettest and you will be presented the following result.

So here we have it. This is how Javascript sends data to Dweet.

The console program.

At the start of this story I showed you how the console would look. And here is the complete program that achieves this:

<!DOCTYPE html>
<html>
<body style="background-color:powderblue;">

<h2 style="color:red">Send multiple values to Dweet</h2>

<h2>Random</h2>
<div id="randdiv">Random Value = </div>

<h2>Switch</h2>
<button onclick="switchon()">ON</button>
<button onclick="switchoff()">OFF</button>

<h2>Switch2</h2>
<button onclick="switchon2()">ON</button>
<button onclick="switchoff2()">OFF</button>

<h2>Default range slider:</h2>
<input type="range" min="1" max="100" value="50" id="slider" class="slider">
<p id="slidval">Value : </p>

<script>

// send a randon value each 10 seconds
var repeat = setInterval(dooften, 10000);

var buttonsw = 0;
var sliderval = document.getElementById("slider").value;
var whole=0;

document.getElementById("slidval").innerHTML="Slider Value = "+sliderval;
document.getElementById("randdiv").innerHTML="Random Value = "+whole;

// switch 1 on or off
function switchon()
{
  buttonsw=1;
  senddata;
}

function switchoff()
{
  buttonsw=0;
  senddata();
}

// switch 2 on or off
function switchon2()
{
  buttonsw2=1;
  senddata;
}

function switchoff2()
{
  buttonsw2=0;
  senddata();
}

function dooften()
{
senddata();
}

slider.onchange = function() {
  slidval.innerHTML = "Slider Value = "+this.value;
  sliderval=this.value;
  senddata()
} 

function senddata() {
   random = Math.random() * (25);
   whole = Math.floor(random) + 1;
   fetch(`https://dweet.io/dweet/for/lucranval?
             randval=`+whole 
             +`&switch=`+buttonsw
             +`&switch2=`+buttonsw2
             +`&slider=`+sliderval);
   document.getElementById("randdiv").innerHTML="Random Value = "+whole;
};

</script>
 
</body>
</html>


I know it is frowned upon by all so called Javascript professionals. But for small projects like this I just use plain old Notepad as my editor.
Copy this program into Notepad on your PC and save it as console.html

For those interested in Javascript I can recommend my book that contains over 500 tips for working with Javascript. You can find the book on Amazon: 

Javascript tips by Luc Volders

To start the console you only have to open the folder where you saved console.html and double click on it. Your default web browser will open with the console up and ready.



Open your Freeboard in another webbrowser page and start with putting 2 switches, a sparkline and 2 gauges on the Dashboard. 

Assign the dweeted variables to the Freeboard elements and you can start testing. If you do not know how to do that please re-read my first story on Freeboard which you can find here: http://lucstechblog.blogspot.com/2019/10/freeboard.html

In the above program the Thing is called lucranval and the variables are randval (for the random value), switch, switch2 and slider. Please rename the Thing and variable names so your tests will not interfere with others that are reading this story and use the same names.

Go ahead. Experiment with Freeboard and this console. Look into Javascript and adapt the program to your own liking.

Till next time
have fun

Luc Volders



 

Friday, August 11, 2023

Freeboard revisited 2

 For an index to all my stories click this text

Freeboard is an IOT dashboard that looks great and is is easy to use.


 

You need to install Freeboard on a webserver so your ESP's or Raspberry Pico's can access it to show their data in the form of charts, gauges and indicator lights. For an introduction to Freeboard I urge you to read this story: http://lucstechblog.blogspot.com/2019/10/freeboard.html

When I wrote that story Freeboard was still a free service that offered free access to build your own Freeboard dashboard on their servers. However a few months later they became a paid service and no longer free for hobbyists like us.

Then I found the Freeboard software on Github. And it was published there under a Mit license meaning it was free to download and copy for your own purposes. So I made a copy of the Freeboard software (I urge you to do so yourself) by forking their repositry. You can find the source here: https://github.com/Freeboard/freeboard
 

I tried to run Freeboard from Github pages. However the previous story showed that Freeboard would not run on Github pages:
http://lucstechblog.blogspot.com/2023/08/freeboard-revisisted-part-1.html

So I needed another webhost to install Freeboard.

000webhost


 

In the past I had used 000webhost. Their servers are fast and they offer a free plan. That plan allows you to build 1 website, 300MB disk space and 3GB bandwidth. It is a bit meagre but sufficient to install and use Freeboard.


 

So sign in and choose + Create New Site.



 

Give your website a name (I choose surprisingly Lucsfreeboard) and choose a password.



 

On the right side choose File Managger.


 

Click on the public-html folder and it opens. There is one small file inside. Do not alter that.
We are going to upload the Freeboard software to this folder.

Open another browser window and go to your Freeboard repositry or to the original Freeboard repositry. Again I urge you to fork the Freeboard repositry to your own Github account. You can find it here: https://github.com/Freeboard/freeboard
You can also fork the code from my repositry: https://github.com/Lucvolders/freeboard



 

On your, Freeboards or mine repositry choose the green button on the left (Code).

Choose Download Zip and download the zipped files.
Now open the downloaded zip file and put its contents in a folder on your computer. Open that folder. Select all files in the folder and drag them to the 000webhost filemanager page.


 

All files will get uploaded into the public-html folder.

Done !!!

Close the file manager and choose My Sites on the left side of the 000webhost page.


 

As you can see lucsfreeboard is ready and already running. The name you can access this page with is: https://lucsfreeboard2.000webhostapp.com/ off course your name will be different.

And then you will encounter the same problem. Freeboard will not fetch data from Dweet because you opened the HTTPS page.


Luckily 000webhost allows to also open the page as: http://lucsfreeboard2.000webhostapp.com/ and then everything works as expected.

If you want to do some testruns before installing Freeboard on your own webserver you can use the link to my testversion: http://lucsfreeboard2.000webhostapp.com/

Now we can use Freeboard again just like we used to.
So start experimenting !!

Till next time
Have fun

Luc Volders












Friday, August 4, 2023

Freeboard revisisted part 1

For an index to all my stories click this text.

What we are going to do.

We are going to build an IOT dashboard with Freeboard that can be freely arranged by yourself.



As you can see the dashboard has a field displaying time. Gauges that give the temperature inside the house and outside. A graph displaying the temperature. Buttons for putting lamps on and off and indicator leds that show if people are in and if apparatus are functioning or off-line. You can add many more widgets to build a complete Home automation system.

This is going to be a multiple story project, so keep following this blog and see how we get Freeboard working with a lot more options as what the standard version offers.

Freeboard

Looong time ago (oktober 2019) I published a story about Freeboard. You can re-read that here: http://lucstechblog.blogspot.com/2019/10/freeboard.html

Freeboard was free at that time. Meaning anybody could sign up and use the service for free. You could build your dashboards and use ESP's to send data to them.
And then things changed. Suddenly the makers of Freeboard decided that the service could not be used for free anymore. This bothered me a lot cause I wrote a story on Freeboard and suddenly readers that got enthousiastic and started using it had to pay for it.

And then, sometime ago, I stumbled upon a story about a programming service called Bipes. Bipes works with programming blocks (just like MIT's App Inventor) which are translated into MicroPython and sends the code to your Microcontroller which can be an ESP (8266 or 32) or a Raspberry Pi Pico. Bipes in itself is somewhat interesting and maybe worth having a look at. You can find it here: http://bipes.net.br/beta2/ui/
If you read from the above lines that I am a bit reluctant to get further into this then you are right. These services (there are more like Bipes) are totally dependent on their makers. So libraries and sensors are only added when the makers decide so. Which makes you dependent.

The interesting part though was that Bipes included Freeboard for displaying sensor data. And the author claimed that it was easy to install Freeboard in your own projects. But he did not get into that. And so started my search.

Freeboard on Github.

I found Freeboard on Github: https://github.com/Freeboard/freeboard Then I saw that the makers of Freeboard had a demo version set up on Github: http://freeboard.github.io/freeboard/ I immediately started testing this demo version and it worked flawless.

The Freeboard page stated that Freeboard was published on Github under the MIT license. I looked into that license and it has the following statement:

 Copyright (c) <year> <copyright holders>

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the "Software"), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.


Now that opens perspectives !!! So I immediately forked Freeboard to my own repositry.

Some time ago I wrote a story on how to use Github as a web-server for your own web-pages. You can re-read that story here.
http://lucstechblog.blogspot.com/2023/07/using-github-for-building-website.html
And that is what I did with my own repositry. I made a web-page from the repositry.



And yes it started.



So I added my faithfull thermometer which was after all these years still sending data to Dweet. Weather stations and thermometers are really stupid things. Just look out of your window or go outside and you feel what the temperature is. No need for electronics to tell me.  Still I have an electronic thermometer as it is a constant data source which can be used for testing purposes like now...... So let´s have a look at how my thermometer Dweets. My ´Thing´ is called Lucstemp2018 and the thermometer value is in the variable `temp´. Let us use that.

Short intermezzo.

Freeboard uses (amongst others) Dweet to store data on and get data from. If you do not know what Dweet is and how to use it please read these stories:
https://lucstechblog.blogspot.com/2019/05/dweet-volatile-iot-cloud-service.html
https://lucstechblog.blogspot.com/2019/08/dweet-again.html
http://lucstechblog.blogspot.com/2019/12/dweet-with-arduino.html

The thermometer I am using is build with an ESP-01 and a Dallas DS18B20 temperature sensor. It is programmed in ESP-Basic and has been running since 2017. Story, schematics and program can be found here:
http://lucstechblog.blogspot.com/2017/11/oh-no-not-another-wifi-thermometer.html

I use the thermometer to send data to my Domoticz setup, Thingspeak and Dweet. The Dweet part is the most interesting for use with Freeboard. You can re-read how that's done here: https://lucstechblog.blogspot.com/2019/08/dweet-again.html

Something is wrong !!!

I thought that all was OK but it was not.



As you can see Freeboard is not getting the Thermometers value. It never updates its value. So where did I go wrong ???



Back to the Github demo from Freeboard itself. And hey that works ???????

So I send a requets to the makers of Freeboard on Github.
https://github.com/Freeboard/freeboard/issues/283

Within a day they responded with a suggestion, which I tried immediately. But alas it did not work.

And then I had an idea. I carefully looked at the url's that were used in Freeboards github page and mine.



This is the Freeboard URL



And this is mine.

Spot the difference ????
Well Freeboard's Github page is HTTP and mine is HTTPS.

When the Freeboard Github page was made Github allowed webpages to be HTTP. And now they only allow HTTPS (secure) pages. There is the difference.
Therefore Freeboard will not work as a GitHub webpage.

So I had to find another web-service that allowed me to setup a webpage as a HTTP page. And That was easier as I imagined. Read how to achieve this in an upcoming story.

Till that time dive into Freeboard with the Freeboard Github version http://freeboard.github.io/freeboard/ and look at all the possibilities. Freeboard is fun and an easy way to build an IOT dashboard. And re-read my first story about Freeboard which will help you setting up your own Dashboard: http://lucstechblog.blogspot.com/2019/10/freeboard.html

Till next time.
Have fun

Luc Volders