Skip to content

Instantly share code, notes, and snippets.

View luigibrancati's full-sized avatar
🏠
Working from home

Luigi Brancati luigibrancati

🏠
Working from home
View GitHub Profile
@luigibrancati
luigibrancati / write_ble_schedule.py
Last active May 17, 2026 13:50
Schedule management for Phillips Hue light bulb
"""Helpers for reading and writing Philips Hue BLE schedules.
This script grew out of reverse-engineering sessions against the Hue BLE
schedule characteristic. It now supports four protocol flows on the schedule
characteristic:
- create a standard wake or sleep schedule from high-level parameters
- update an existing schedule by resending the full body
- delete a schedule by id
- query and read back stored schedules
const char* SSID = "YOUR_SSID";
const char* PWD = "YOUR_PWD";
void setup(){
Serial.begin(115200);
preferences.begin("credentials");
preferences.clear();
preferences.putString("ssid", SSID);
preferences.putString("pwd", PWD);
Serial.println(preferences.getString("ssid"));
@luigibrancati
luigibrancati / server_utils.h
Last active March 9, 2022 18:56
Code to run the APIs
#include "memory_utils.h"
#include <ArduinoJson.h>
StaticJsonDocument<250> responseJson;
char buffer[250];
void createJson(String message) {
responseJson.clear();
responseJson["message"] = message;
serializeJson(responseJson, buffer);
@luigibrancati
luigibrancati / server_utils.h
Last active March 9, 2022 18:03
Code to run wifi and server
#include <WiFi.h>
#include <WebServer.h>
const char* SSID = "YOUR_SSID";
const char* PWD = "YOUR_PASSWORD";
const String serverHostname = "esp32";
const int serverPort = 80;
// Set your Static IP address
const IPAddress serverIP(192, 168, 1, 184);
// Set your Gateway IP address
#include "include/server_utils.h"
void setup(){
Serial.begin(115200);
// Setup static IP and hostname
Serial.println("Configuring WIFI");
WiFi.mode(WIFI_STA);
if (!WiFi.config(serverIP, serverGateway, serverSubnet, serverPrimaryDNS, serverSecondaryDNS)) {
Serial.println("STA Failed to configure");
}
#include "include/memory_utils.h"
#include "include/morse_utils.h"
#include "include/wifi_utils.h"
const short OUT_PIN = 23;
const short START_END_PIN = 22;
const int uS_TO_mS_FACTOR = 1000; // Conversion factor for micro seconds to milli seconds
RTC_DATA_ATTR int bootCount = 0; // Boot count
#ifndef _WIFI_SERVER_UTILS_H
#define _WIFI_SERVER_UTILS_H
#include "memory_utils.h"
#include <WiFi.h>
#include <WebServer.h>
#include <ArduinoJson.h>
#include <Preferences.h>
const char* SSID = "YOUR_SSID";
@luigibrancati
luigibrancati / wifi_utils.h
Last active March 9, 2022 18:40
Full code
#ifndef _WIFI_UTILS_H
#define _WIFI_UTILS_H
#include "memory_utils.h"
#include "server_utils.h"
#include <HTTPClient.h>
#include <ArduinoJson.h>
StaticJsonDocument<250> httpResponseJson;
#ifndef _MEMORY_UTILS_H
#define _MEMORY_UTILS_H
#include <Preferences.h>
Preferences preferences;
const char* prefNamespace = "message";
const char* varName = "messagevar";
String readMessage(const String def){
#include "include/morse_utils.h"
const short OUT_PIN = 8;
const short START_END_PIN = 7;
void setup() {
Serial.begin(9600);
pinMode(OUT_PIN, OUTPUT);
pinMode(START_END_PIN, OUTPUT);
digitalWrite(OUT_PIN, LOW);