Skip to content

Instantly share code, notes, and snippets.

@wgbartley
wgbartley / proxy.php
Last active December 18, 2017 16:30
Spark PHP Proxy
<?php
// Set your access token here
define('ACCESS_TOKEN', 'your_access_token_here');
// Make sure we have an HTTP_ACCEPT header,
// and if so, make it lower-case for easier string matching
if(isset($_SERVER['HTTP_ACCEPT']))
$_SERVER['HTTP_ACCEPT'] = strtolower($_SERVER['HTTP_ACCEPT']);
else
@wgbartley
wgbartley / drain-list.sh
Last active September 26, 2017 15:39
Drain Redis List to X elements
#!/bin/sh
# Max number of concurrent Redis connections before we back off
CONN_LIMIT=10000
# Check to make sure all arguments were passed
DO_EXIT=0
if [ "$1" == "" ]; then
echo "Please provide a list name (in quotes) as first argument."
@wgbartley
wgbartley / elapsedMillis.h
Created April 24, 2014 03:28
Simple Spark Core firmware for reading temperature from TMP36 and light from an LDR
/* Elapsed time types - for easy-to-use measurements of elapsed time
* http://www.pjrc.com/teensy/
* Copyright (c) 2011 PJRC.COM, LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
@wgbartley
wgbartley / Spark-DHT22.pde
Last active November 20, 2016 17:09
Class for reading DHT22 values on a Spark Core
#define MAXTIMINGS 85
#define cli noInterrupts
#define sei interrupts
#define DHT11 11
#define DHT22 22
#define DHT21 21
#define AM2301 21
char srvIP[] = "256.256.256.256";
char srvHost[] = "myhost.mydomain.tld";
int srvPort = 80;
char srvPath[] = "/?l=test1";
void setup() {
delay(5000);
pinMode(D7, OUTPUT);
@wgbartley
wgbartley / Spark-Thermistor.pde
Last active January 2, 2016 12:09
Basic class for reading thermistor values on a Spark Core
#include <math.h>
class Thermistor {
private:
int _pin;
int _resistor;
int _temp_raw;
float _temp_k;
float _temp_c;
float _temp_f;
@wgbartley
wgbartley / Spark-SensorMadness.pde
Last active January 2, 2016 12:09
Combines all my environmental sensors into a single sketch. Data is retrieved by passing a string to fnrouter() exposed to the cloude API.
#include <math.h>
#define MAXTIMINGS 85
#define cli noInterrupts
#define sei interrupts
#define DHT11 11
#define DHT22 22
#define DHT21 21
@wgbartley
wgbartley / Spark-DS18B20.pde
Last active January 2, 2016 12:09
Class to read temperature from DS18B20 sensor attached to a Spark Core
#ifndef OneWire_h
#define OneWire_h
#include <inttypes.h>
// you can exclude onewire_search by defining that to 0
#ifndef ONEWIRE_SEARCH
#define ONEWIRE_SEARCH 1
#endif
// You can exclude CRC checks altogether by defining this to 0
@wgbartley
wgbartley / My_analogRead.cpp
Last active January 1, 2016 18:29
Custom analogRead function for testing different ADC_SAMPLING_TIME values
#define MY_ADC_SAMPLING_TIME ADC_SampleTime_239Cycles5
uint8_t My_adcInitFirstTime = true;
uint8_t My_adcChannelConfigured = NONE;
PinMode My_digitalPinModeSaved = (PinMode)NONE;
void My_ADCInit()
{
ADC_InitTypeDef ADC_InitStructure;
@wgbartley
wgbartley / Configuration.h
Last active December 5, 2015 06:24
Configuration.h for my Prusa i3
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
// This configuration file contains the basic settings.
// Advanced settings can be found in Configuration_adv.h
// BASIC SETTINGS: select your board type, temperature sensor type, axis scaling, and endstop configuration
//===========================================================================
//============================= DELTA Printer ===============================
//===========================================================================