Skip to content

Instantly share code, notes, and snippets.

View rustyeddy's full-sized avatar
💭
Hacking

Rusty Eddy rustyeddy

💭
Hacking
View GitHub Profile
@rustyeddy
rustyeddy / adafruit-soil-moisture.cc
Created May 31, 2026 14:15
adafruit-soil-moisture.cc
/*
* main.cc example for the Adafruit Soil Moisture sensor
*
* This example code is in the Public Domain (or CC0 licensed, at your option.)
*
* Unless required by applicable law or agreed to in writing, this
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied.
*/
@rustyeddy
rustyeddy / macaddr.cc
Created October 25, 2022 23:51
Get MAC address on Linux
int getMacAddr(std::string ifname, char *macaddr) {
// need to open a socket to read the mac address
int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock == -1) {
auto err = std::string(strerror(errno));
return Status::UnknownError("failed to open socket" + err);
}
struct ifreq ifr;
strcpy(ifr.ifr_name, ifname.c_str());
# Workflow to build and deploy site to Github Pages using Hugo
# Name of Workflow
name: github pages
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
package main
import (
"flag"
"log"
)
type Configuration struct {
Broker string `json:"broker"`
Addr string `json:"Addr"
@rustyeddy
rustyeddy / mqtt.go
Created March 26, 2022 22:03
Adding MQTT to a Go program
package main
import (
"fmt"
"log"
"os"
mqtt "github.com/eclipse/paho.mqtt.golang"
)
var (
// Start Video opens the camera (sensor) and data (vidoe) starts streaming in.
// We will be streaming MJPEG for our initial use case.
func (vid *VideoPlayer) StartVideo() {
var err error
var buf []byte
l.Info("StartVideo Entered ... ")
defer l.Info("StartVideo Finished")
@rustyeddy
rustyeddy / echo_server.py
Created June 13, 2019 14:29
Echo Server in Python
import socket
def server(host, port):
sock = socket.socket()
sock.bind((host, port))
sock.listen(2)
print(f'Server up and listening on {host} {port}')
@rustyeddy
rustyeddy / led.cpp
Created May 19, 2019 20:35
esp32 C++ Program
#pragma once
class LED {
private:
gpio_num_t _pin = GPIO_NUM_0;
gpio_mode_t _mode = GPIO_MODE_OUTPUT;
int _state = 0;
public:
LED(gpio_num_t p);
@rustyeddy
rustyeddy / blinker.cpp
Created May 19, 2019 20:31
ESP32 C++ main_app
// ====================================================================
const int STACK_SIZE = 256;
const gpio_num_t LED_RED = GPIO_NUM_22;
const gpio_num_t LED_GREEN = GPIO_NUM_23;
// GLobal LEDs
// ====================================================================
LED red = LED(LED_RED);
LED green = LED(LED_GREEN);
class LED {
private:
gpio_num_t _pin = GPIO_NUM_0;
gpio_mode_t _mode = GPIO_MODE_OUTPUT;
int _state = 0;
public:
LED(gpio_num_t p);
void set(int val);