Skip to content

Instantly share code, notes, and snippets.

View kakopappa's full-sized avatar
🏠
Working from home

Aruna Tennakoon kakopappa

🏠
Working from home
View GitHub Profile
@kakopappa
kakopappa / app.js
Last active July 16, 2020 18:39
nodejs sinricpro example
const { SinricPro, SinricProActions, raiseEvent, eventNames, SinricProUdp } = require('sinricpro'); // Use require('sinricpro'); if you are using NPM
const appKey = ''; // d89f1***-****-****-****-************
const secretKey = ''; // f44d1d31-1c19-****-****-9bc96c34b5bb-d19f42dd-****-****-****-************
const device1 = ''; // 5d7e7d96069e275ea9******
const device2 = ''; // 5d80ac5713fa175e99******
const deviceId = [device1]
function setPowerState(deviceid, data) {
  console.log(deviceid, data);
@kakopappa
kakopappa / SinricProAirQualitySensor.h
Created August 4, 2020 02:15
SinricProAirQualitySensor.h
/*
* Copyright (c) 2019 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
*/
#ifndef _SINRICAIRQUALITYSENSOR_H_
#define _SINRICAIRQUALITYSENSOR_H_
@kakopappa
kakopappa / gist:f2a97c449199217e20cc7af688611d80
Last active October 1, 2024 08:17
How to Encrypt in Flutter and Decrypt in ESP8266
Encrypt in Flutter
String encryptDecrypt(String input) {
var key = ['KCQ']; //Can be any chars, and any size array
var output = [];
for(var i = 0; i < input.length; i++) {
var charCode = input.codeUnitAt(i) ^ key[i % key.length].codeUnitAt(0);
output.add(new String.fromCharCode(charCode));
}
@kakopappa
kakopappa / ChangeReport.json
Created March 29, 2021 09:58 — forked from sivar2311/ChangeReport.json
ContactSensor-AlexaJSON
{
"context": {},
"event": {
"header": {
"messageId": "cedd4af3-a6ce-4e13-9c72-6bed87261eb6",
"namespace": "Alexa",
"name": "ChangeReport",
"payloadVersion": "3"
},
"endpoint": {
@kakopappa
kakopappa / onoff.ino
Created May 7, 2021 02:16
relay on off example
const int RELAY_PIN = 3;
void setup() {
pinMode(RELAY_PIN, OUTPUT);
}
void loop() {
digitalWrite(RELAY_PIN, HIGH);
delay(500);
digitalWrite(RELAY_PIN, LOW);
@kakopappa
kakopappa / drape_and_curtain.ino
Last active September 15, 2021 16:19
drape and curtain
//#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#ifdef ESP8266
@kakopappa
kakopappa / wait.ino
Last active June 6, 2021 06:33
wait example without delay for esp8266/esp32 from Boris. Blame him if there are bugs
class Wait {
public:
Wait() : next_millis(0) {}
bool operator()(unsigned long wait_millis, bool instant=false) {
unsigned long current_millis = millis();
if (next_millis == 0 && instant==false) next_millis = current_millis + wait_millis;
if (current_millis >= next_millis) {
next_millis = current_millis + wait_millis;
return true;
}
@kakopappa
kakopappa / build-complete.txt
Created September 25, 2021 02:08 — forked from welshstew/build-complete.txt
Generating and using ssl client certificates for use in an nginx sidecar image
[user@localhost certs]$ oc get builds
NAME TYPE FROM STATUS STARTED DURATION
nodejs-mongo-persistent-1 Source Git@e59fe75 Complete About an hour ago 2m37s
simple-nginx-ssl-reverseproxy-1 Source Git@552932f Complete 16 minutes ago 47s
String encrypt(String plain_data){
int i;
// PKCS#7 Padding (Encryption), Block Size : 16
int len = plain_data.length();
int n_blocks = len / 16 + 1;
uint8_t n_padding = n_blocks * 16 - len;
uint8_t data[n_blocks*16];
memcpy(data, plain_data.c_str(), len);
for(i = len; i < n_blocks * 16; i++){
data[i] = n_padding;
@kakopappa
kakopappa / uptime.ino
Created January 24, 2023 14:12
ESP32 Uptime example
void setup() {
Serial.begin(115200);
}
void loop() {
char buf[50];
int64_t upTimeUS = esp_timer_get_time(); // in microseconds
int64_t seconds = upTimeUS/1000000;
uint32_t days = (uint32_t)seconds/86400;
uint32_t hr=(uint32_t)seconds % 86400 / 3600;