Skip to content

Instantly share code, notes, and snippets.

View smetronic's full-sized avatar

Alexander Sikandar smetronic

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / DataStructure_EEPROM.cpp
Created January 31, 2020 23:26
Reading and storing data structure from EEPROM,
#include <EEPROM.h>
uint8_t rx_buffer[10];
uint8_t rx_mem[10];
void setup() {
Serial.begin(115200);
loadStruct(&rx_mem, sizeof(rx_mem)); // Load data from EEPROM into array.
}
@smetronic
smetronic / RestClient.cs
Last active February 13, 2020 09:09
C# REST client using legacy code, HttpWebRequest
JObject jObjectbody = new JObject();
jObjectbody.Add("label", item.PlateNo);
jObjectbody.Add("asset", item.AssetCode);
jObjectbody.Add("rfid", item.RFID);
var baseAddress = $"http://xx.xx.xx.xx/casper/api/FCS/SecondaryTag?key={userModel.Session}";
var http = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress));
http.Accept = "application/json";
http.ContentType = "application/json";