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 / 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 / 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 / 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 / MQTT_GraphQL_IoT.ino
Created August 11, 2019 15:28
Arduino Sketch to publish BME280 sensor data in JSON Format to an MQTT Broker
#include<Wire.h>
#include<PubSubClient.h>
#include<WiFi.h>
#include<Adafruit_BME280.h>
#include <ArduinoJson.h>
/*
* WLAN Configuration
*/
const char* ssid = "YOUR_SSID"; // FILL THIS ACCORDINGLY
@shantanoo-desai
shantanoo-desai / uploader_cont.py
Created July 21, 2019 14:38
upload_data function logic for Batch Uploader InfluxDB
def upload_data(batch_data):
if connected_to_cloud():
try:
if CLOUD_DB.write_points(batch_data, time_precision='ms'):
logger.info('Write Successful to Cloud')
logger.info('Updating local database with status=1 field')
# for each point add `status=1` field
for point in batch_data:
@shantanoo-desai
shantanoo-desai / uploader.py
Last active July 21, 2019 14:19
Data Query Function Snippet for the Uploader Script
def get_points(conf):
# We use the configuration in the TOML file
# to get the data points using `influxdb-python`
# Refer to Repository for complete code
# create the query string
dict_str = ''.join('"{}"=\'{}\''.format(key,value) for key, value in conf['tags'].items())
QUERY = 'SELECT "{}" FROM "{}" WHERE "status"=0 AND {} LIMIT {}'.format(
'","'.join(conf['fields']),
conf['measurement'],
@shantanoo-desai
shantanoo-desai / config.toml
Last active July 21, 2019 11:35
Batch Uploader InfluxDB Configuration File
[local]
# Local Instance of InfluxDB
host = 'localhost'
port = 8086
database = 'CISS'
[cloud]
# Cloud Instance of InfluxDB
# NOTE: doesn't have to InfluxDB it could be
# any technology stack that you wish to upload
@shantanoo-desai
shantanoo-desai / CISS.py
Created July 15, 2019 21:15
Code Snippet from cissflux repository
class ciss:
"""CISS Class"""
# parsing methods
# other necessary codes
def parse_payload(self, accepted_data):
data_type = {'measurement': 'ciss',
'fields':
{
'accX': 0.0,
'accY': 0.0,
@shantanoo-desai
shantanoo-desai / Filters.json
Last active September 24, 2019 09:47
Filters for QualiExplore
{
"categories": [
{
"name": "Goals",
"labels": [
{
"id": 1,
"name": "I want to track other’s products.",
"checked": false
},
@shantanoo-desai
shantanoo-desai / Data.json
Last active October 9, 2019 10:03
Data Quality Factors for QualiExplore
{
"text": "Platform information quality",
"checked": false,
"value": {
"description": null
},
"children": [{
"text": "Collection quality",
"checked": false,
"value": {