Skip to content

Instantly share code, notes, and snippets.

View noahp's full-sized avatar

Noah Pendleton noahp

  • Boston MA, USA
View GitHub Profile
@noahp
noahp / golioth_memfault.c
Created June 26, 2024 12:45
Golioth Memfault chunk upload snippet
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(golioth_memfault, LOG_LEVEL_DBG);
#include <golioth/stream.h>
#include <memfault/components.h>
/* Callback invoked by the Golioth SDK to read the next block of Memfault
data to send to Goliot */
static enum golioth_status read_memfault_chunk(uint32_t block_idx,
uint8_t *block_buffer,
@noahp
noahp / get_latest.c
Created May 29, 2024 17:05
Memfault example querying a Device's Latest OTA Release
//! @file
//!
//! Example code that uses libcurl to fetch the latest release for an example
//! device.
//!
//! Compiling: In Memfault UI, navigate to Settings->General Settings and
//! Copy/Paste "Project API Key" into PROJECT_KEY below:
//!
//! $ gcc get_latest.c -lcurl -lssl -lcrypto -Wall -DMEMFAULT_PROJECT_KEY=\"PROJECT_KEY\"
//!
@noahp
noahp / bundle_manifest.c
Last active December 11, 2023 21:00
Example bundle manifest reader
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
// supported manifest version, in case the structure needs to change
#define BUNDLE_MANIFEST_VERSION 1
enum bundle_manifest_entry_type {
BUNDLE_MANIFEST_ENTRY_TYPE_MAIN_FW,
BUNDLE_MANIFEST_ENTRY_TYPE_MODEM_FW,
#!/usr/bin/env python3
import base64
import os
import sys
import uuid
import requests
@noahp
noahp / update-cohort-for-device.py
Created December 22, 2022 14:52
Example using the Memfault Device API to update the Cohort for a Device ID
#!/usr/bin/env python3
"""
Example script to update the cohort for a device via the Memfault API.
Run with --help for usage information.
"""
import requests
@noahp
noahp / last_seen.py
Created June 5, 2022 20:24
Memfault Devices API python processing for last_seen field
#!/usr/bin/env python3
"""
Small python program to load json data generated by the Memfault "list Devices"
API:
https://api-docs.memfault.com/#2634f3fb-d137-42a8-b093-e05d420b8932
And spit out a json object with the following format:
{
# require make 4.3+ for grouped targets
MINIMUM_MAKE_VERSION = 4.3
MAKE_TEST_VERSION = $(shell printf "%s\n%s" $(MAKE_VERSION) $(MINIMUM_MAKE_VERSION) | sort --version-sort)
ifneq ($(MINIMUM_MAKE_VERSION),$(firstword $(MAKE_TEST_VERSION)))
$(error Make version is too low. Please upgrade to $(MINIMUM_MAKE_VERSION) or higher.)
endif
@noahp
noahp / cross-static-rsync.sh
Created September 27, 2021 23:51
Cross-compile rsync in static mode
# get rsync
❯ git clone [email protected]:WayneD/rsync.git
❯ git checkout v3.2.3 # recent tag
# get musl cross toolchain from https://musl.cc/
❯ wget https://musl.cc/arm-linux-musleabihf-cross.tgz
❯ tar zxvf arm-linux-musleabihf-cross.tgz
# now add the toolchain to path and configure + make
❯ export PATH=$PATH:$PWD/arm-linux-musleabihf-cross/bin
@noahp
noahp / doit.bash
Last active May 7, 2020 15:04
git reset all authors
#!/usr/bin/env bash
# disable warning for using filter branch, we don't care lalala
export FILTER_BRANCH_SQUELCH_WARNING=1
# rewrite all authors to = committer.
git filter-branch --commit-filter \
'GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" GIT_AUTHOR_EMAIL="$GIT_COMMITTER_EMAIL" git commit-tree "$@"'
# these are good examples:
@noahp
noahp / c-warning-available.mk
Last active December 16, 2019 17:57
Check if a C compiler warning is supported by clang/gcc
# Detect if a warning flag is supported by the $(CC) compiler
#
# HEADS UP- This should be used after including CppUTest MakefileWorker.mk,
# which populates the $(COMPILER_NAME) variable, but will work if you don't
# (it's just slower by a few ms because it will attempt to use the wrong
# option when testing).
#
# Example usage:
# ifeq ($(call WARNING_SUPPORTED,address-of-packed-member),supported)
# CPPUTEST_ADDITIONAL_CPPFLAGS += \