Skip to content

Instantly share code, notes, and snippets.

View shantanoo-desai's full-sized avatar

Shan Desai shantanoo-desai

View GitHub Profile
@shantanoo-desai
shantanoo-desai / schema.js
Created August 11, 2019 16:59
Apollo GraphQL Schema for querying sensors and subscription
const { gql } = require('apollo-server-express');
const typeDefs = gql`
type SensorData {
temp: Float!
humid: Float!
time: String!
}
@shantanoo-desai
shantanoo-desai / resolvers.js
Created August 11, 2019 17:12
Resolvers for GraphQL Subscription and Query for MQTT Broker
const { MQTTPubSub } = require('graphql-mqtt-subscriptions');
const { connect } = require('mqtt');
const client = connect('mqtt://mqtt.eclipse.org', {
reconnectPeriod: 1000
});
const pubsub = new MQTTPubSub({
client
});
@shantanoo-desai
shantanoo-desai / server.js
Created August 11, 2019 17:17
Main GraphQL server app
const http = require('http');
const express = require('express');
const { ApolloServer } = require('apollo-server-express');
// GraphQL Schema and Resolvers
const { typeDefs } = require('./graphql/schema');
const { resolvers } = require('./graphql/resolvers');
const server = new ApolloServer({ typeDefs, resolvers });
const app = express();
@shantanoo-desai
shantanoo-desai / test.json
Last active August 13, 2019 08:49
GitHub Gist test to use it as a static endpoint for JSON
{
"test": "This JSON will keep changing",
"version" : 0.3,
"url": "https://stackoverflow.com/questions/12522539/github-gist-editing-without-changing-url",
"features": [
"Feature1",
"Feature2",
"Feature3"
]
}
@shantanoo-desai
shantanoo-desai / change_stream_example.py
Last active October 22, 2019 16:00
Change Stream for MongoDB using Windows 10, Docker, MongoDB and pymongo snippet
# Change Stream Example
# using PYMONGO v3.9.0
import sys
import pprint
from pymongo import MongoClient
# Create a Client to our Replica Set
cl = MongoClient(host='localhost', port=37017, replicaSet='rs0')
# Database: `team` # Collection: `players`
@shantanoo-desai
shantanoo-desai / ESP32_9DOF_MQTT.ino
Created March 24, 2020 09:47
Arduino Sketch for programming an ESP32 with Adafruit's LSM9DS0 Sensor to publish data via MQTT
/* Arduino Sketch to Program an ESP32 to read LSM9DS0 Sensor from
* its I2C Bus, convert the data into InfluxDB's Line Protocol Strings
* and Publish it to an MQTT broker running on an IoT Edge Device (Pi4)
* Author: Shan Desai <https://github.com/shantanoo-desai>
*/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Sensor.h>
@shantanoo-desai
shantanoo-desai / .travis.yml
Created April 25, 2020 17:13
travis.yml file for nestjs-products-api GitHub Repository
language: node_js
services:
- 'docker'
node_js:
- "10"
- "12"
cache:
@shantanoo-desai
shantanoo-desai / ESP32_9DOF_MQTT_Secure.ino
Last active June 29, 2020 13:21
Arduino Sketch for Sending Secure Data (TLSv1.2 Certificate) and Username/Password over MQTT Broker with ESP32 and LSM9DS0
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Sensor.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <PubSubClient.h>
// CERTIFICATE Header File
@shantanoo-desai
shantanoo-desai / LineProtocolPayload.txt
Last active July 29, 2020 19:44
telegraf configuration file that connects to Mosquitto Open broker and pushes data into InfluxDB v1.x
# IOT/sensor2/temp
env,type=A temp=23.39
env,type=B temp=40.00
# IOT/sensor1/acc
env,type=A x=0.2
env,type=B x=1.3
@shantanoo-desai
shantanoo-desai / telegraf.convert.toml
Created September 3, 2020 13:49
Telegraf Configuration to connect to an MQTT Broker and converting Field to a Tag for InfluxDB
[agent]
interval = "2s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 12000000