Saturday, 14 March 2020

crontab doesn't run script

If crontab doesn't run a script and if the output is redirected to a zero length file, it may be because it is missing the #!/bin/bash or #!/bin/sh directive.

Another reason may be that the path is required.
change dotnet to /opt/dotnet/dotnet

Remember that crontab runs under a reduced environment. It may not have the necessary environment variables. For example echo @DOTNET_ROOT is empty when running as crontab. If you run it as su it returns /opt/dotnet

Consider the user you are running the crontab under. Does it need to be su?

In the end another approach was required: execute bash to run the script. This is the full crontab:
# Added dotnet to the path
MAILTO=""
PATH=/usr/bin:/bin:/opt/dotnet:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin
SHELL=/bin/bash
# It is necessary to execute bash in order to access the environment variables required for dotnet
* */12 * * * bash -l -c '/home/pi/SmartHome/easy-weatherstation/scripts/publishreadings.sh' > /home/pi/SmartHome/easy-weatherstation/scripts/logs/publishreadings.log 2>&1
*/30 * * * * bash -l -c '/home/pi/SmartHome/easy-weatherstation/scripts/onereading.sh' > /home/pi/SmartHome/easy-weatherstation/scripts/logs/onereading.log 2>&1

Sunday, 1 March 2020

the required library libhostfxr.so could not be found

Problem: Running .net core 3.1 app on a Raspberry Pi returns
"the required library libhostfxr.so could not be found."

check
dotnet --version
echo $DOTNET_ROOT

if the second line is empty then the environment variable needs to be set at startup.

Add a file set_dotnetroot.sh to /etc/profile.d
sudo nano /etc/profile.d/set_dotnet.sh

add
export DOTNET_ROOT="/opt/dotnet"

save and reboot

If you want it to run for su too, especially if running a su crontab,
edit /etc/bash.bashrc and add it there too.

Sunday, 9 February 2020

Raspberry Pi screen blanking

I have a Raspberry Pi 4b running Raspbian 4.

After 10 minutes the screen blanks an it is very hard to get it to return: even plugging in a keyboard and mouse and using them doesn't restore the display. Here are some of my findings:

"xset s activate" recreates the problem.

X11 is a client/server Windows Manager.
Raspbian 4 is running Pixel, a derivative of LXDE.

You can see the default display manager with:

cat /etc/X11/default-display-manager
/usr/sbin/lightdm

"sudo service lightdm restart" doesn't fix it.

Accessing the X11 tools differs if you use SSH out of the box from the local terminal connected directly to the Pi. For example I was getting errors such as xset:  unable to open display ""

Also:
echo $DISPLAY
returns :0.0 on the local terminal

but it returns a blank line on SSH unless you turn on X11 forwarding on the Putty console, then it displays:
locahost:10.0

X11 also has security controls.
"xhost +" disables the controls and allows everyone to access it.

References
https://raspberrypi.stackexchange.com/questions/2059/disable-screen-blanking-in-x-windows-on-raspbian




Friday, 10 January 2020

Can't install Minecraft on Twitch

I had a weird problem where whenever I tried to Install Minecraft on Twitch the screen would flash quickly then it would return you back.

I fixed it by changing the install location from my user profile folder (my username had a dot in it) to C:\Temp and then it seemed to work. Even more strangely the folder seem to revert back to the user profile folder.

Saturday, 28 December 2019

Setting up a Ring doorbell Pro on existing wiring for a Friedland 214

This was the process I performed for setting up a Ring Doorbell Pro in conjunction with my existing Friedland 214 doorbell.

The Ring Pro is designed for the US market where their doorbells operate at higher AC voltages. In the UK the standard household operates with lower AC voltages (around 8V AC) and so the Ring Pro in the UK comes with a power converter kit. You get a transformer and a solenoid bypass kit (which is effectively a 50W resistor).

My house was installed with a Friedland 752 transformer and and Friedland 214 door chime. I had both a front door and a back door push button wired up.

The first thing I had to do was figure out the wiring. I isolated the transformer, took the cover off the door chime and compared the wiring to an old diagram I found on the Internet. Note that inside the door chime there is a label and an arrow pointing "Top". Use this to align the chime correctly (mine was installed upside down with Top pointing downwards!). The diagram isn't very clear, but there are actually 3 wires connected to terminal 0 (one half of the AC transformer source and then one connection out to each of the two buttons).


By disconnecting the wires in turn and using a multimeter I found that the front door bell made the connection between terminal 2 and one of the wires screwed into terminal 0.

TerminalDescription
0Multiple wires:
A. Common transformer connection,
B. To Front push button,
C. To Back push button
1Return from Back push button
2Return from Front push button
3Transformer connection

Thus the wires screwed into terminals 2 and 3 were disconnected and pushed into the bypass unit. This puts the resistor in series with the Ring Pro, across the AC output.

To house the transformer I purchased a Wylex ESE2 IP40 2-Module Unpopulated DIN Enclosure from Screwfix (it cost less than £5).

I removed the old Friedland transformer and installed the new Ring transformer inside the Wylex enclosure. I wired up the mains connection and the 24V output.


Monday, 25 November 2019

Tuning ASP.NET

Here are a range of articles for tuning and ASP.NET server:

Performing an await on an async operation does not use a new thread (unless the implementation explicitly starts one). It is possible to write an write to disk asynchronously without using a new worker thread. This article explains why in detail.

Task.Run, TaskFactory.StartNew and ThreadPool.QueueUserWorkItem will use a worker thread.

Contention, poor performance on ASP.NET
ASP.NET Core best practices
Tuning ASP.NET Core and avoiding large memory allocations
ASP.NET Thread usage
Tuning IIS 10
How the garbage collector causes random slowness

IO

IO Completion Threads in more detail
IO Completion ports
Programming IOCP
IOCP and ASP.NET

Memory Management

Pooling memory buffers to avoid keep allocating memory on every request
Memory management and garbage collection
Using ArrayPool

Saturday, 23 November 2019

IO at a low level

This article describes the low level interactions that make up the async process when writing to disk.