Skip to content

Instantly share code, notes, and snippets.

View gguuss's full-sized avatar

Gus Class gguuss

View GitHub Profile
@gguuss
gguuss / gist:4d94a7ddbcb0538f3177c58fa9c75842
Created April 5, 2018 03:10
git Google Cloud IoT Arduino
git clone https://github.com/googlecloudplatform/google-cloud-iot-arduino
gcloud pubsub subscriptions pull <your-project-id> --limit 50 --auto-ack
@gguuss
gguuss / dusty.h
Last active April 13, 2018 07:17
Arduino dust sensor
// Based on instructions at:
// http://www.instructables.com/id/How-to-Interface-With-Optical-Dust-Sensor/
int measurePin = A3; int ledPower = 12; int samplingTime = 280;int deltaTime = 40;
int sleepTime = 9680; float voMeasured = 0; float calcVoltage = 0;
float dustDensity = 0;
float readDust(){
digitalWrite(ledPower,LOW); // power on the LED
delayMicroseconds(samplingTime);
voMeasured = analogRead(measurePin); // read the dust value
void loop() {
char buf[12];
float mq = readMQ7();
sprintf(buf, "%f", mq);
Serial.println("" + String(buf));
sendTelemetry("" + String(buf));
delay(60000);
}
@gguuss
gguuss / dusty2.h
Created April 12, 2018 18:13
Reading MQ7 sensor
int MQ7_APIN = A3, int MQ7_DPIN = 8;
float readMQ7() {
float value = analogRead(MQ7_APIN);
//int limit = digitalRead(MQ7_DPIN)
return value;
}
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Hello, waiting...");
delay(5000);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
void loop(void) {
unsigned long currTime = millis();
if (!booted){
bootLoop();
}
if (hasStrip){
blinkyLoop(moveConfig );
}
int getHexConfig () {
WiFiClientSecure client;
doRequest(&client, true, "");
int toReturn = -1;
while (client.available()) {
String line = client.readStringUntil('\n');
Serial.println(line);
// NOTE: This method and the following are character length sensitive
if (line.indexOf("version\": \"") > 0) {
void postRange() {
String data = "{\"deviceId\": \"" + String(device_id)
+ "\", \"time\": " + String(time(nullptr)) + ", \"range\": \"" +
String(getRangeCm(), DEC) + " cm\", \"scanId\": \""+ String(scanId) +
"\", \"scanAngle\": \"" + String(HEXBUG_ROT % 360) + " deg\"}";
sendTelemetry(data);
Serial.println(data);
}
// Test surroundings
def updateConfig(project_id, region, registry_id, device_id, data):
"""Push the data to the given device as configuration."""
config_data_json = json.dumps(data)
body = {
'version_to_update': 0,
'binary_data': base64.b64encode(
config_data_json.encode('utf-8')).decode('ascii')
}
device_name = ('projects/{}/locations/{}/registries/{}/'