GSPRO Control box

esp32 code to create GSPRO Control box {: width=“350” height=“200” } {: width=“350” height=“200” } // Benedikt Gabriel Egilsson - bensiegils.com // 1= 5 - Camera to ball // 2= KEY_M_CTRL - Muligan // 3= T - Scorecard display // 4= P - See the pin // 5= O - Flyover of the hole // 6= . - shadow quality // 7= B - Hide - Make objects in your line of sight invisible // 8= Z - Hide or show the 3D gras // 9= KEY_UP_ARROW // 10= KEY_DOWN_ARROW // 11= KEY_LEFT_ARROW // 12= KEY_RIGHT_ARROW #define USE_NIMBLE #include <BleKeyboard.h> BleKeyboard bleKeyboard("GSPRO BOX"); #define NUM_KEYS 12 struct Key { int pin; uint8_t code; bool state; bool isCtrl; // New field to indicate if Ctrl needs to be held }; Key keys[NUM_KEYS] = { {16, '5', false, false}, {17, 'm', false, true}, // 'm' with Ctrl modifier {18, 't', false, false}, {19, 'p', false, false}, {21, 'o', false, false}, {22, '.', false, false}, {32, 'b', false, false}, {33, 'z', false, false}, {27, KEY_UP_ARROW, false, false}, {14, KEY_DOWN_ARROW, false, false}, {12, KEY_LEFT_ARROW, false, false}, {13, KEY_RIGHT_ARROW, false, false} }; bool connectNotificationSent = false; void setup() { Serial.begin(115200); Serial.println("Code running..."); // Set pin modes for (int i = 0; i < NUM_KEYS; i++) { pinMode(keys[i].pin, INPUT_PULLUP); } // Initialize BLE keyboard bleKeyboard.begin(); } void loop() { if (bleKeyboard.isConnected()) { if (!connectNotificationSent) { Serial.println("BLE connected..."); connectNotificationSent = true; } for (int i = 0; i < NUM_KEYS; i++) { handleButton(i); } } else { if (connectNotificationSent) { Serial.println("BLE disconnected..."); connectNotificationSent = false; } } delay(10); // Small delay to stabilize readings } void handleButton(int keyIndex) { bool currentState = !digitalRead(keys[keyIndex].pin); // Read the button state (active low) if (currentState != keys[keyIndex].state) { keys[keyIndex].state = currentState; if (currentState) { if (keys[keyIndex].isCtrl) { // Check if Ctrl modifier is needed bleKeyboard.press(KEY_LEFT_CTRL); } bleKeyboard.press(keys[keyIndex].code); Serial.print("Key pressed: "); } else { bleKeyboard.release(keys[keyIndex].code); if (keys[keyIndex].isCtrl) { // Check if Ctrl modifier is needed bleKeyboard.release(KEY_LEFT_CTRL); } Serial.print("Key released: "); } Serial.println(keys[keyIndex].code); } }

June 23, 2024 · 2 min · 333 words · Benedikt Gabriel Egilsson

Powershell Speedtest

Was having problems with my internet connection and wanted to monitor it. So I rewrote this script to use powershell and store the results in a table storage. The script is using the speedtest cli from https://www.speedtest.net/apps/cli {: .prompt-info } #$StorageAccountName = "StorageAcount" #$Key = "Storagekey" #$StorageContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $Key #$Table = (Get-AzStorageTable -Context $StorageContext | Where-Object {$_.name -eq "Speedtest"}).CloudTable $applocation = "C:\apps\speedtest" $path = "C:\temp\" $SpeedTestResults=@() $SpeedtestObj=@() $i = 0 while ($i -eq 0) { $PartitionKey = "1" $SpeedTestResults = & "$($applocation)\speedtest.exe" --progress=no --format=json $SpeedtestResults = $SpeedTestResults | ConvertFrom-Json $SpeedtestObj += [PSCustomObject] @{ Time = Get-Date -Format "dd/MM/yyyy HH:mm K" downloadspeed = [math]::Round($SpeedtestResults.download.bandwidth / 1000000 * 8, 2) uploadspeed = [math]::Round($SpeedtestResults.upload.bandwidth / 1000000 * 8, 2) packetloss = ($($SpeedtestResults.packetLoss).ToString("P")) isp = $SpeedtestResults.isp ExternalIP = $SpeedtestResults.interface.externalIp InternalIP = $SpeedtestResults.interface.internalIp UsedServer = $SpeedtestResults.server.host location = $SpeedTestResults.server.location Jitter = [math]::Round($SpeedtestResults.ping.jitter) Latency = [math]::Round($SpeedtestResults.ping.latency) } # ---- Move to table storage ---- # Add-AzTableRow -table $Table -PartitionKey $PartitionKey -RowKey (Get-Date).Ticks -property $SpeedtestObj Start-Sleep -Seconds 15 } #$SpeedtestObj | Format-Table | Out-String|ForEach-Object {Write-Host $_} $SpeedtestObj | Export-Csv -Path $path\speedtest.csv -NoTypeInformation

April 6, 2023 · 1 min · 179 words · Benedikt Gabriel Egilsson

Esp32 Hot tub controller

This is my hot tub controler with outdoor shower controler. It is based on a ESP32 and a 4 channel relay module. It has a DS18B20 temperature sensor for the hot tub and a DS18B20 for the water in the hot tub. It also has a DS18B20 for the outdoor shower and a DS18B20 for the water in system. esphome: name: pottastyring platform: ESP32 board: nodemcu-32s wifi: ssid: "" password: "" domain: .lan manual_ip: static_ip: 192.168.x.x gateway: 192.168.x.x subnet: 255.255.255.0 dns1: 192.168.x.x # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "hottub" password: "" captive_portal: web_server: port: 80 # Enable logging logger: # Enable Home Assistant API api: ota: time: - platform: sntp id: timer servers: - 0.pool.ntp.org - 1.pool.ntp.org - 2.pool.ntp.org dallas: - pin: GPIO13 sensor: - platform: dallas address: 0x67011464EA7EFF28 name: "Pottur hiti" id: pottur_hiti - platform: dallas address: 0x8B0314649975FF28 name: "Vatn i pott" id: vatn_i_hiti - platform: dallas address: 0x110000045976f328 name: "Hiti Skapur" id: Hiti_skapur - platform: dallas address: 0xe10314645814ff28 name: "Hiti Uti" id: hiti_uti binary_sensor: - platform: gpio filters: - delayed_on: 100ms id: fylla pin: number: GPIO17 mode: INPUT_PULLUP inverted: True name: "Pottur fylla takki" on_press: if: condition: lambda: 'return id(pottur_hiti).state < 20;' then: - logger.log: "The sensor value is below 20!" - switch.turn_on: relay_1 - delay: 1min - switch.turn_on: relay_4 - delay: 30min - switch.turn_off: relay_1 - delay: 3min - climate.control: id: pottur_climate mode: "HEAT" else: - logger.log: "The sensor value is above 20!" - platform: gpio filters: - delayed_on: 500ms id: sturta pin: number: GPIO21 mode: INPUT_PULLUP inverted: True name: "Sturta takki" on_press: if: condition: lambda: 'return id(pottur_hiti).state > 38;' then: - logger.log: "The sensor value is above 38!" - climate.control: id: pottur_climate mode: "OFF" - delay: 10sec - switch.turn_on: relay_3 - delay: 4min - switch.turn_off: relay_3 else: - logger.log: "The sensor value is below 20!" - switch.turn_on: relay_3 - delay: 4min - switch.turn_off: relay_3 - platform: gpio filters: - delayed_on: 500ms id: nidurfall pin: number: GPIO33 mode: INPUT_PULLUP inverted: True name: "taema takki" on_press: then: - switch.turn_off: relay_4 - climate.control: id: pottur_climate mode: "off" switch: - platform: gpio restore_mode: ALWAYS_OFF name: "Pottur fylla relay" pin: GPIO25 id: relay_1 - platform: gpio restore_mode: ALWAYS_OFF name: "Pottur hita relay" pin: GPIO26 id: relay_2 - platform: gpio restore_mode: ALWAYS_OFF name: "Sturta relay" pin: GPIO27 id: relay_3 - platform: gpio restore_mode: ALWAYS_ON name: "Loka nidurfalli" pin: GPIO18 id: relay_4 climate: - platform: bang_bang id: pottur_climate visual: min_temperature: 38 max_temperature: 42 temperature_step: 1.0 name: "Pottur vatn" sensor: pottur_hiti default_target_temperature_low: 38 °C default_target_temperature_high: 40 °C heat_action: if: condition: lambda: 'return id(pottur_hiti).state > 32;' then: - logger.log: "The sensor is above 32! then full" - switch.turn_on: relay_1 - switch.turn_on: relay_2 else: - logger.log: "The sensor value is below 32!" - switch.turn_on: relay_1 - delay: 1min - switch.turn_on: relay_4 - delay: 30min - switch.turn_on: relay_2 idle_action: - switch.turn_off: relay_2 - switch.turn_off: relay_1 mqtt: broker: 192.168.x.x username: xxx password: xxx

April 4, 2023 · 3 min · 482 words · Benedikt Gabriel Egilsson

Upgrade Hyper-V Hosts with Azure Arc

Azure Arc is a powerful tool for managing and updating hybrid infrastructure, including standalone Hyper-V hosts. Demo how to use Azure Arc to update a standalone Hyper-V host, using a scheduled update task in Automation Account and pre and post scripts that shut down and start up VMs. Pre-requisites # Stop all running VMs on the Hyper-V host and wait for them to shut down # save the names of the running VMs to a file $filePath = "C:\temp\runningvm.txt" (Get-vm | Where-Object { $_.State -eq "Running" }).name | Out-File $filePath $runningvm = Get-Content $filePath foreach ($Name in $runningvm) { Stop-VM $Name do { $VM1 = get-vm -Name $Name Write-Progress -Activity "Waiting for the VM to shutdown" } until ($Null -eq $VM1.Heartbeat) } # send a webhook to Teams to notify that the VMs have been shut down $webhookUri = "" $body = @{ "@context" = "http://schema.org/extensions" "@type" = "MessageCard" "themeColor" = "d70000" "title" = "Send Webhook to Teams" "text" = "This is a message sent from Powershell" } Invoke-RestMethod -Uri $webhookUri -Method Post -Body (ConvertTo-Json -InputObject $body) Post-requisites ...

April 4, 2023 · 2 min · 354 words · Benedikt Gabriel Egilsson