25. February 2017

How to limit amount of data downloaded by Windows 10 Updates?

Windows 10 often downloads a large volume of updates. This is not a problem when you have good connectivity. When you’re on some slower network like ADSL it might lead into problems with connectivity.

One option how to limit the amount of downloaded data by Windows 10 update is to set a connection as Metered connection.

Search for Change Wi-Fi settings in start menu:

In Wi-Fi section scroll down below list of available networks and click Advanced options.

Flip the toggle Set as metered connection to On.

Windows will limit the amount of downloaded data and it will download only necessary stuff.

20. February 2017

How to send command from Python via MQTT to RGB LED connected to ESP8266

I’ve described how to send server load as a number to MQTT in the previous article. The number could be then translated via Node-RED to command for LampESP with RGB LED. The result is simple. LED indicates server load by displaying different colors.

The other option is to deliver color command directly from the server using Python.

Just install paho-mqtt:

pip install paho-mqtt

Here is small snippet of Python code (publish_server_load.py):

#!/usr/bin/env python3

import paho.mqtt.publish as publish
import os

color = 'red'
load = os.getloadavg()[0]
if load < 0.7:
    color = 'black'
elif load < 1.5:
    color = 'blue'
elif load < 3:
    color = 'green'
elif load < 7:
    color = 'orange'

publish.single('/server/monitoring/command', color, hostname='iot.sinusgear.com')

ESP should listen to /server/monitoring. Code of LampESP 0.3 is available at GitHub.

Put this code into crontab

* * * * * /usr/local/bin/publish_server_load.py

If you’re using virtualenv the command should be:

* * * * * /opt/my-python-env3/bin/python /usr/local/bin/publish_server_load.py

18. February 2017

How to configure Two-Finger Scrolling in openSUSE KDE to behave the same way like Apple MacBook

Two-Finger scrolling in openSUSE – KDE has same default configuration like Windows 10 on Lenovo. This configuration came from old days when users were using only mouse to navigate on the web. When using touchpad it’s natural to expect that it would behave similarly to a tablet or Apple MacBook. Apple made the switch in the direction some time ago to make it more natural. For some reasons developers keep the old style on Linux and even on Windows. Luckily it is possible to change the configuration very easily.

Go to System Settings and click Hardware – Input Devices

Select Touchpad from left pane, Scrolling from the tabs and check option Reverse scrolling – Vertical. Then click Apply.

15. February 2017

GitHub unable to clone repository – Permission denied (publickey)

After upgrade to new version of SSH you may experience the following problem with return code 255:

Permission denied (public key).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

This happened to me after upgrade from Linux Mint 17 to 18.

How to diagnose the problem?

Run following command:

ssh -v git@github.com

You will see several lines of output and one of them is typically the reason. In my case it was:

...
debug1: SSH2_MSG_NEWKEYS received
debug1: Skipping ssh-dss key ~/.ssh/id_dsa - not in PubkeyAcceptedKeyTypes
...

DSA keys were disabled in SSH 7. Solution is to generate new key with different type, for example RSA.

ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub

Replace your key at GitHub by newly generated one. You can re-run “ssh -v” command to check whether the communication was established correctly:

PTY allocation request failed on channel 0
Hi georgik! You've successfully authenticated, but GitHub does not provide shell access.
...
debug1: Exit status 1

That’s a good sign. The connection was established and now you can try to clone a repo.

14. February 2017

Manual import of activities to Garmin Connect

Garmin is constantly improving Garmin Connect service.

One change which occurred on February 14, 2017, was that possibility for manual upload disappeared from Activities. This feature is sometimes very handy.

It took me a while to figure out where is the new place for manual upload.

Garmin moved it to the sidebar with Profile under Import data.

They also improved the feature and now you can drag’n’drop multiple files for upload. New uploader is much more advanced.

Good job Garmin. Just next time I recommend to display changelog or small hint about changes.

13. February 2017

Vertical text block selection in PlatformIO/Atom on Linux

Sometimes it is necessary to modify multiple lines at once. PlatformIO has support for multiple cursors which allows you to perform operation on multiple places.

You can place separate cursors by holding Ctrl and left click by mouse. That is handy, but when you need 4 or more lines it’s a little bit cumbersome.

When you need to select vertical text block of text in PlatformIO on Linux just hold Shift+Alt and use arrows Up/Down to select text block. Make sure that you press and hold keys in defined order. 1st is Shift and 2nd is Alt. If you change the order then the selection won’t work.

Here is how it looks like.

Shift+Alt+Up/Down:

Now you can use Shift+Left/Right to select block of text:

If you’d like to discuss this feature, there is a very very long discussion thread about it at Atom’s web page.

11. February 2017

Display server load on Linux Mint desktop delivered via MQTT

In previous article I wrote how to subscribe to MQTT topics and display also timestamp with color. There was one MQTT topic which represented server load and it demonstrates that MQTT could be used for server monitoring.

Here is an example how to measure server load and publish it as MQTT topic. Open crontab:

crontab -e

Add following line:

* * * * * /usr/bin/mosquitto_pub -t /server/reactor/load -m `cat /proc/loadavg | sed -e 's/ .*//g'`

Cron will invoke the command every minute. Command will publish data to MQTT topic /server/reactor/load (note: reactor is the name of my server).

We can subscribe at a workstation to the topic and execute some commands. mosquitto_sub will keep running in the background and we can use xargs to invoke a new command once the new message arrives.

Following example shows how to display notification on Linux Mint – Cinnamon using

mosquitto_sub -t '/server/reactor/load' -h iot.sinusgear.com | xargs -d$'\n' -L1 sh -c 'notify-send "Server load: $0"'

The result at workstation:

The only downside is that notifications are spamming desktop every minute. It does not make sense to notify admin when server load is too low. We can add a little bit of logic and display notifications about load which exceeded a certain threshold.

mosquitto_sub -t '/server/reactor/load' -h iot.sinusgear.com | xargs -d$'\n' -L1 /bin/zsh -c 'if (( $(echo "$0 > 1.2" | bc -l ) )); then notify-send "Server load: $0"; fi'

Note: just be aware that message from MQTT is not sanitized. Run such command only in trusted environment or add type check of value received from MQTT.

Enjoy 🙂

9. February 2017

Courier Mail Server stops delivering emails after upgrade to 0.76

It might seem like a minor upgrade to go from version 0.75 to 0.76. In the case of Courier Mail Server, it’s a huge change in the orchestration of services.

Courier Mail Server has a very good modular architecture which allows independent control of each aspect of mail delivery. You can separately restart or change each service like MTA, POP or IMAP. Even encrypted variants of servers are available as separate services. The version 0.76 is pushing it even further in the fashion of micro services.

There is new service ‘courier’ which is responsible for scheduling mail delivery after mail was accepted via SMTP or SMTP-SSL. If you’re not aware of this new service you might wonder why is Courier not logging any activity after accepting email. Just make sure that service is running. You can start it by:

service courier start

After the start of the service, you may see that emails are being processed, but they’re not delivered to local mail users. In the log, you can find many error messages like:

/usr/bin/maildrop: Unable to change to home directory.

The other major change is the switch from courier-maildrop to common maildrop. That might seem like a minor change, but it could render your server completely useless. Emails won’t be simply delivered to user’s mailbox:

/usr/bin/maildrop: Unable to change to home directory.

The problem is that maildrop is accepting different parameters than courier-maildrop. Package maintainers recommends to change line with maildrop in /etc/courier/esmtpd from:

DEFAULTDELIVERY='|/usr/bin/maildrop'

to:

DEFAULTDELIVERY='|/usr/bin/maildrop -w 90 -V 1 -d ""'

If you do not have time to play with maildrop, you can change to default configuration:

DEFAULTDELIVERY=./Maildir

Here is the explanation of changes from package maintainers (click image for detail):

Restart services and delivery should start. It might happen that services do not shut down, because upgrade changed user from ‘daemon‘ to ‘courier‘. Then the solution is to terminate services by:

pkill -9 -f courier

Then you can start services and everything should work ok.

5. February 2017

Colorful log from MQTT with timestamp

The easiest way to subscribe to all messages on MQTT server like Mosquitto is following command:

mosquitto_sub -v -t '/#'

The only problem is that result is just plain text without timestamp which makes it harder to spot some messages.

The solution to the problem is quite simple. Just pipe output of subscription command to xargs which will inject date and to ccze which will add colors. Here is the command:

mosquitto_sub -v -t '/#' | xargs -d$'\n' -L1 sh -c 'date "+%d.%m.%Y %T $0"' | ccze -m ansi

Result:

30. January 2017

LampESP 0.3 – small improvements

I’d like to announce small updates to LampESP code.

The first feature is that you can send commands with color via MQTT to RGB LED. It’s easy, just send color name to topic /parent/host/command. Available colors are:

  • blue
  • green
  • orange
  • red
  • white

Or you can send just off to turn the led off.

The other small feature is a configuration for PIR sensor. I moved the configuration of PIR uptime minimal limit to configuration. You can set a number of seconds which represents how long it will take to turn off the light. The configuration could be set by URL:

http://IP-address/config?pir_up_interval=30

Here you can see a configuration of ESP8266 with Photocell sensor, PIR and 3W LED powered by power bank.

One interesting thing is small breadboard ZY. Dimensions are just 5×5 and it’s very useful for small configurations like this one.

Enjoy 😉

  • Where’s the fish?

  • Translations

  • Further info

  • Twitter

    Follow @jurajmichalek on twitter.

  • Comments

  • Tags

  • Topics