Skip to content

Instantly share code, notes, and snippets.

View smetronic's full-sized avatar

Alexander Sikandar smetronic

View GitHub Profile
@smetronic
smetronic / WirelessController.cpp
Created November 15, 2019 18:50
Code to toggle relay over UART communication.
int d1 = 2;
int d2 = 3;
byte data[3] = {};
void setup() {
Serial.begin(9600);
}
void loop() {
@smetronic
smetronic / SerialEmulator.ino
Created August 31, 2019 19:45
Send byte data over serial connection
uint8_t b[]= { 0xE0, 0x10, 0x82, 0x00, 0x01, 0xE2, 0x00, 0x00, 0x19,
0x10, 0x10, 0x01, 0x05, 0x18, 0x30, 0x49,
0xD8, 0x03 };
int i;
void printHex(uint8_t num) {
char hexCar[2];
sprintf(hexCar, "%02X", num);
Serial.print(hexCar);
@smetronic
smetronic / NMEAParser.cs
Created February 13, 2019 10:02
C# NMEA Parser $GPRMC, $GPGSV, $GPGSA
using System;
using System.Globalization;
public class NmeaInterpreter
{
// Represents the EN-US culture, used for numers in NMEA sentences
public static CultureInfo NmeaCultureInfo = new CultureInfo("en-US");
// Used to convert knots into miles per hour
public static double MPHPerKnot = double.Parse("1.150779",
NmeaCultureInfo);
@smetronic
smetronic / PeakDetection.cs
Last active February 12, 2019 12:01
Peak signal detection in realtime timeseries data
public class ZScoreOutput
{
public List<double> input;
public List<int> signals;
public List<double> avgFilter;
public List<double> filtered_stddev;
}
public static class ZScore
{
@smetronic
smetronic / data.sql
Created November 14, 2018 18:12
List of duplicates rows
SELECT
UID, COUNT(Timestamp), Timestamp, GROUP_CONCAT(id)
FROM
Transactions
GROUP BY
UID,Timestamp
HAVING
COUNT(Timestamp) > 1;
@smetronic
smetronic / ListBox.cs
Created June 18, 2018 20:52
Getting all selected values from an ASP ListBox
// GetSelectedIndices
foreach (int i in ListBox1.GetSelectedIndices())
{
// ListBox1.Items[i] ...
}
// Items collection
foreach (ListItem item in ListBox1.Items)
{
if (item.Selected)
@smetronic
smetronic / PrimaryModel.cs
Created March 29, 2018 09:43
Retrieving data from database using SQLITE SqlDataReader
public class Primary
{
public int Id { get; set; }
public string Label { get; set; }
public int Flag { get; set; }
public DateTime Timestamp{ get; set; }
}
@smetronic
smetronic / tcp.ino
Created January 4, 2018 11:40
ATMega 328p: Sending TCP packet using SIM808, SIM900
#include <SoftwareSerial.h>
SoftwareSerial SIM(8, 9);
int8_t answer;
int onModulePin = 2;
char aux_str[50];
char ip_data[40] = "Test string from GPRS shieldrn";
void setup() {
pinMode(onModulePin, OUTPUT);
SIM.begin(9600);
@smetronic
smetronic / countdown.ino
Created December 27, 2017 12:11
ATMega 328p: Countdown timer
unsigned long Watch, _micro, time = micros();
unsigned int Clock = 0, R_clock;
boolean Reset = false, Stop = false, Paused = false;
volatile boolean timeFlag = false;
void setup()
{
Serial.begin(115200);
SetTimer(0,0,10); // 10 seconds
StartTimer();
@smetronic
smetronic / eeprom.ino
Created December 26, 2017 11:44
ATMega 328p: Saving string data to eeprom
#include <EEPROM.h>
char example_string[] = "~New eeprom string";
const int eeprom_size = 500; // values saved in eeprom should never exceed 500 bytes
char eeprom_buffer[eeprom_size];
char first_eeprom_value;