Skip to content

Instantly share code, notes, and snippets.

View mabbotts9797's full-sized avatar

Morgan mabbotts9797

View GitHub Profile
package main
import (
"strconv"
"github.com/gin-gonic/gin"
"github.com/sony/sonyflake"
)
var (
#include <Servo.h>
Servo servo;
int pos = 0;
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
servo.attach(9);
@mabbotts9797
mabbotts9797 / Azure_Retrieve.cs
Created May 26, 2018 15:21
Retrieves sensor readings from CosmosDB
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log, IEnumerable<AirData> documents)
{
List<AirData> docsToReturn = new List<AirData>();
string numberOfDocs = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "fetchno", true) == 0)
.Value;
@mabbotts9797
mabbotts9797 / Azure_Persist.cs
Created May 26, 2018 15:13
Code for the Azure serverless function that persists sensor readings
using System.Net;
public static HttpResponseMessage Run(HttpRequestMessage req, out object airQualityDocument, TraceWriter log)
{
string latitude = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "latitude", true) == 0)
.Value;
string longitude = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "longitude", true) == 0)
@mabbotts9797
mabbotts9797 / cloud_poster.ino
Created May 26, 2018 10:30
Arduino code for posting GPS and sensor reading to Azure:
#include <b64.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>
static const int RXPin = 12, TXPin = 13; //RX and TX pins for GPS
TinyGPS gps;
int LED_PIN = 9;
void setup() {
// put your setup code here, to run once:
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
Serial.begin(9600);
Serial.println("* * * * * * * * * *");
Serial.println("* LED I/O *");
Serial.println("* Program *");