@echo off
SET portname=COM12
:loop
set /p x="~U" <nul >\\.\%portname%
ping -n 2 127.0.0.1 > nul
goto loop
#!/bin/bash
PORT=/dev/ttyACM0
while true
do
echo -n "~U" > $PORT
sleep 1
done
@echo off
SET hostname=google.com
SET portname=COM12
:loop
ping -n 1 -l 4 -w 1000 %hostname% >nul
if %errorlevel%==0 set /p x="~U" <nul >\\.\%portname%
ping -n 2 127.0.0.1 > nul
goto loop
#!/usr/bin/env bash
HOST="google.com"
PORT=/dev/ttyACM0
while true
do
if ping -c 1 $HOST; then
echo -n "~U" > $PORT
fi
sleep 3
done
#!/usr/bin/env bash
PORT=/dev/ttyACM0
PROCESS=crond
if [ ! -z "$1" ];then
PROCESS="$1"
echo "Monitor $PROCESS"
fi
while true; do
if pgrep "$PROCESS" > /dev/null; then
echo -n "~U" > $PORT
fi
sleep 3
done
#!/usr/bin/env bash
PORT=/dev/ttyACM0
URL=google.com
PROCESS=crond
while getopts ":ha:p:" opt; do
case ${opt} in
a)
URL=$OPTARG
;;
p)
PROCESS=$OPTARG
;;
h)
echo "Usage: $0 -a <url> -p <process>" 1>&2
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" 1>&2
exit 1
;;
esac
done
echo "Ping $URL"
echo "Monitor $PROCESS"
while true; do
ping -n -c 1 -w 1 "$URL" 2>/dev/null 1>&2 && pgrep "$PROCESS" 2>/dev/null 1>&2 && echo -n "~U" > $PORT
sleep 3
done
from time import sleep
import serial
port = '/dev/cu.usbmodem1411'
ser = serial.Serial(port)
while True:
ser.write(b'~G')
ser_data = ser.readline()
if ser_data:
data = ser_data.decode("utf-8")
print('Read from serial (repl to ~G): {0}'.format(data))
if data.startswith('~G'):
print('Temperature is {0}'.format(int(data[2:])/10))
else:
print('sensor error')
sleep(1)