Skip to content

Instantly share code, notes, and snippets.

@smching
smching / app_mqtt_mysql_completed.js
Last active May 9, 2024 01:12
Node.js application: Store messages from Mosquitto MQTT broker into SQL Database (completed)
var mqtt = require('mqtt'); //https://www.npmjs.com/package/mqtt
var Topic = '#'; //subscribe to all topics
var Broker_URL = 'mqtt://192.168.1.123';
var Database_URL = '192.168.1.123';
var options = {
clientId: 'MyMQTT',
port: 1883,
//username: 'mqtt_user',
//password: 'mqtt_password',
@smching
smching / app_mqtt_mysql.js
Last active August 30, 2022 01:28
Node.js application: Store messages from Mosquitto MQTT broker into SQL Database
var mqtt = require('mqtt');
var Topic = '#'; //subscribe to all topics
var Broker_URL = 'mqtt://192.168.1.123';
var Database_URL = '192.168.1.123';
var options = {
clientId: 'MyMQTT',
port: 1883,
//username: 'mqtt_user',
//password: 'mqtt_password',
@smching
smching / app_mqtt.js
Last active June 25, 2022 08:09
Node.js application: Subscribe to all topics of a MQTT broker
var mqtt = require('mqtt');
var Topic = '#'; //subscribe to all topics
var Broker_URL = 'mqtt://192.168.1.123';
var options = {
clientId: 'MyMQTT',
port: 1883,
keepalive : 60
};
@smching
smching / app_mysql.js
Last active March 22, 2023 07:45
Node.js application: Insert a row to a table in MySQL database
var mysql = require('mysql');
//Create Connection
var connection = mysql.createConnection({
host: "192.168.1.123",
user: "newuser",
password: "mypassword",
database: "mydb"
});
@smching
smching / split_message.ino
Last active March 6, 2024 05:59
Split comma or any other character delimited string into an array
/*
Arduino sketch: Split comma or any other character delimited string into an array
by SM Ching (http://ediy.com.my)
*/
#define MAX_WORLD_COUNT 5
#define MIN_WORLD_COUNT 2
char *Words[MAX_WORLD_COUNT];
char *StringToParse;
@smching
smching / three_buttons_one_analog.ino
Created July 12, 2016 10:16
Three buttons on one analog pin
/*
Arduino AD0
|
VCC---2K2---470---1k---
| | |
Up Down Select
(SW1) (SW2) (SW3)
| | |
Gnd--------------------
*/
#include <EEPROM.h>
// Absolute min and max eeprom addresses. Actual values are hardware-dependent.
// These values can be changed e.g. to protect eeprom cells outside this range.
const int EEPROM_MIN_ADDR = 0;
const int EEPROM_MAX_ADDR = 511;
// Returns true if the address is between the
// minimum and maximum allowed values, false otherwise.
//
// This function is used by the other, higher-level functions
@smching
smching / vixen_lights_6_channels_pwm.ino
Created April 3, 2016 05:50
Arduino communicate with Vixen Lighting Control Software
/*
Basic Pin setup:
------------ ---u----
ARDUINO 13|-> SCLK (pin 25) OUT1 |1 28| OUT channel 0
12| OUT2 |2 27|-> GND (VPRG)
11|-> SIN (pin 26) OUT3 |3 26|-> SIN (pin 11)
10|-> BLANK (pin 23) OUT4 |4 25|-> SCLK (pin 13)
9|-> XLAT (pin 24) . |5 24|-> XLAT (pin 9)
8| . |6 23|-> BLANK (pin 10)
7| . |7 22|-> GND
@smching
smching / vixen_lights_6_channels.ino
Created April 3, 2016 05:43
Arduino communicate with Vixen Lighting Control Software
/*
16 Channels Lighting Controller
By smching (ediy.com.my)
Allow Arduino Mega to communicate with Vixen via generic serial plugin
*/
#define CHANNELS_COUNT 16
////////// PWM pin
#define Ch1 2 // PWM Pin 2
#define Ch2 3 // PWM Pin 3
#define Ch3 4 // PWM Pin 4
@smching
smching / timeout.ino
Created March 30, 2016 14:00
Arduino电子密码锁
boolean isTimeout() {
runEventAnyTime();
if (millis() >= previousMillis + KEYBOARD_EVENT_TIMEOUT *1000){ //convert KEYBOARD_EVENT_TIMEOUT in milli second to second
playTimeOutTone();
return true;
} else return false;
}