element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
Design For A Cause 2021
  • Challenges & Projects
  • Design Challenges
  • Design For A Cause 2021
  • More
  • Cancel
Design For A Cause 2021
Blog EnergySaverHighScore - Bernhard - Design for A Cause 2021  #3 - Setup Raspberry Pi
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bernhardmayer
  • Date Created: 4 Jun 2021 1:16 AM Date Created
  • Views 563 views
  • Likes 2 likes
  • Comments 0 comments
  • mqtt
  • raspberry_pi
  • mosquitto
  • arduino_design_challenge
Related
Recommended

EnergySaverHighScore - Bernhard - Design for A Cause 2021  #3 - Setup Raspberry Pi

bernhardmayer
bernhardmayer
4 Jun 2021

Installing mosquitto

 

Setting up the Raspberry Pi is quite simple and straight forward. I used the default Raspbian image. Then a MQTT broker is needed. Under Linux this usually is mosquitto and it can be installed using the package manager.

 

So type in:

sudo apt-get install mosquitto mosquitto-clients

 

This installs mosquitto and the command line tools to control it. and this is it. Mosquitto starts automatically at every start at the system.

 

Testing mosquitto

 

As written in my previous blog post I decided to transfer the data under the topic /power_priority

 

To view all data under this topic you just type in:

mosquitto_sub -h localhost -t /power_priority

 

To send data to this topic type in:

mosquitto_pub -h localhost -t /power_priority -m 23

 

 

Automatic testing

 

These command line commands can be used to setup a script which sends values from 0 to 100 to the topic in a loop.

 

#!/bin/bash
sleeptime=2

while true; do
    i=0
    while [ $i -lt 100 ]; do echo Prio: $i  
        mosquitto_pub -h localhost -t /power_priority -m $i 
        sleep $sleeptime 
        i=$[$i+10];
    done

    while [ $i -gt 0 ]; do echo Prio: $i  
        mosquitto_pub -h localhost -t /power_priority -m $i
        sleep $sleeptime 
        i=$[$i-10];
    done

done

 

Using data from aWATTar

 

The next step is to use the data from aWATTar. Their API is described here https://www.awattar.at/services/api/

 

The prices for the next 24 hours can be obtained with

curl "https://api.awattar.at/v1/marketdata"

 

I only need the price for the running hour. So the output can be stripped using bash tools.

curl -s "https://api.awattar.at/v1/marketdata" | grep -m1 marketprice | tr -dc '0-9.'

 

This is transformed into a bash script:

 

#!/bin/bash
marketprice=$(curl -s "https://api.awattar.at/v1/marketdata" | grep -m1 marketprice | tr -dc '0-9.')
mosquitto_pub -h localhost -t /power_priority -m $marketprice

 

And this script is called every hour using cron

2 * * * * /home/pi/mqtt/awattar.sh > /dev/null

 

At the moment I directly publish the prices to the topic. For the start and testing this should be OK.

  • Sign in to reply
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