Setting up InfluxDB and Grafana for storing and viewing Arduino measured sensor values

Setting up Grafana to view InfluxDB data

Grafana is most commonly used for visualizing time series data for Internet infrastructure and application analytics but many use it in other domains including industrial sensors, home automation, weather, and process control. Grafana features pluggable panels and data sources allowing easy extensibility and a variety of panels, including fully featured graph panels with rich visualization options. There is built-in support for many of the most popular time series data sources. An example of data visualization by Grafana can be seen in the below image:

Grafana in action!

Installing and setting up Grafana on Linux

Just like InfluxDB, you can find the Grafana package for your Linux distribution (or Windows as well) in the download page on their website. Since we are working on Ubuntu, we need to download the .deb package. After you have downloaded it, install it using ‘dpkg -i [filename.deb]’ command. After installation, since Grafana registers itself as a service, you will need to start the service:

After starting the Grafana server service, assuming InfluxDB is also running, head on to your browser and open the localhost at port 3000 which is the default port for Grafana (localhost:3000). There, the first step is to add a Datasource. Using the menu on top-left of the page, go to Data sources and add a new data source. Here you need to give your new data source a name and make sure to select the Type as InfluxDB. The address will be HTTP address of InfluxDB (http://localhost:8086). On the bottom of the page, enter the name of your database (remember we created a database named embedonix). After saving the data source, it is time to create a dashboard to get visualized data for our test scenario.

Head to Dashboards and select new to create a new dashboard. In the dashboard window, click on the Graph to create a new graph. Doing so will create a new panel named Panel Title which is filled with some default data. If you right click on the title you will be able to select Edit option to edit the query. What we want is a query to get data from our my_house_data measurements. Since it is hard to explain this process with words, please watch the quick video below to see how to configure Grafana to show the saved values in InfluxDB!

With a bit of practice, you can figure out how to make a great dashboard! Just give it a try 😉

Saeid Yazdani

An Electronics Engineer with passion in Embedded Systems, Wireless Sensor Networks, Assembly, Desktop and Mobile Development, Web Development and generally anything that has to do with hardware and software of any kind!

17 Comments:

  1. Thanks for sharing !!!

    Code “as-is” is giving me very weird errors en compiling for arduino 2560
    Still investigating on this

    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\main.cpp: In function 'main':
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\main.cpp:51:1: error: unable to find a register to spill in class 'NO_REGS'
    }
    ^
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\main.cpp:51:1: error: this is the insn:
    (insn 294 291 297 19 (set (mem:QI (post_dec:HI (reg/f:HI 32 __SP_L__)) [0 S1 A8])
    (subreg:QI (reg/f:HI 271) 1)) \\WIN7PRO\__Projets\Grid Tie solar et vent\arduino\to influxdb\v033 test influx\v033\v033.ino:144 1 {pushqi1}
    (expr_list:REG_ARGS_SIZE (const_int 5 [0x5])
    (nil)))
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\main.cpp:51: confused by earlier errors, bailing out
    lto-wrapper: C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc returned 1 exit status
    c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: lto-wrapper failed

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Error compiling for board Arduino/Genuino Mega or Mega 2560.

    but werirdly compile fine for arduino due !
    ( from all I know, back end compiler is not the same at all )

    Using arduino 1.8.1 on windows 10

    • I have only tested this with Due. I’m not sure what the problem could be as I don’t have any other arduinos to test again. I just guess it has something tido with your Ethernet library.

  2. Thank, I tought you were using a 2560 .
    BTW You dont need the board to test compilation

    I got the stock etherne lib
    Playing around commenting uncomenting lines, still got weird compil errors

    I’ll use a Due if its the only issue , just a bit more expensive

  3. Found a work around

    Seems a documented bug in the latest GCC Compiler
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60040

    Aplied a similar work around I got from here
    https://github.com/arduino/Arduino/issues/3972

    I’ve Added
    void eth_send_data(char* data, int dataSize) __attribute__((__optimize__(“O2”)));

    On line 2 of your code
    Now compile Fine for 2560 , dont ask me more details !!!!!

    Thanks !

  4. Eratum
    You need 2 “spaces” before “__attribute__”
    Dont ask me why , but it is not the same

    void eth_send_data(char* data, int dataSize) __attribute__((__optimize__(“O2”)));

  5. Sorry … itsjust because I ve taken back My own comment and it wasent compiling again

    The issue is not the double space at all

    it is because this web page convert the ” character to another type of ”
    Just have to type it back to the “real” ” one …. hard to explain

  6. Just gave up, moved it all to arduino due, still having compilation error for 2560, but all working fine on due. Rest of instructions are all good.

    Except minor error, on page 5:
    $sudo dpkg -i https://grafanarel.s3.amazonaws.com/builds/grafana_4.0.2-1481203731_amd64.deb
    that should read
    $sudo dpkg -i grafana_4.0.2-1481203731_amd64.deb

  7. Orange Juice

    Hi. Code is working fine, I also needed to Optimize due to using a Mega. I am actually using a ENC28J60 with the UIPEthernet which is drop in for Ethernet.h however I dont get any respone from the server shown in Serial Monitor just the “Reply from InfluxDB”, The information is reaching influx it just doesnt display the 204 error it should in serial monitor.

    Dont suppose you have any pointers, not that its essential as the code is working.

    • I think you should play around with the delay value between sending and waiting for the response. Give it a try.

    • And perhaps you can show the changes you made to make it work on Mega? maybe that’s the problem. Jean-Francois Payeur comments show that it doesn’t work on Mega, although I have never tried it with Mega so can’t say for sure.

  8. Orange Juice

    Thanks for responding, great tutorial by the way.

    I followed Jean’s instructions as I got the same compile error an it was the GCC .

    Only difference in code compared with yours is i added this at the top of the skect.
    #include

    void eth_send_data(char* data, int dataSize) __attribute__((__optimize__(“O2”)));

    I will check delay and have a look into if it is a issue with UIPEthernet and syntax

  9. Orange Juice

    I managed to get it working by replacing availible with connected.

    Serial.println(“Reply from InfluxDB”);
    while(client.connected()) { //receive char
    Serial.print((char)client.read());
    }

    Thanks for a great tutorial.

  10. Pingback: InfluxDB Week in Review – Feb 13, 2017 | InfluxData

  11. Orange Juice

    It could be because I’m using the UIPEthernet library.

    I regret to inform the test I had running which was taking humidity readings from 3x DHT11 stopped sending information to influx after 60hours.
    Unsure on why it failed as it wasnt plugged into the computer so didnt have Serial Monitor open 🙁 I have reset the Arduino and hope for a better result, maybe it was my cat.

Leave a Reply

Your email address will not be published. Required fields are marked *