Skip to content

Instantly share code, notes, and snippets.

View vhuynen's full-sized avatar
🚀

Vincent Huynen vhuynen

🚀
View GitHub Profile
@vhuynen
vhuynen / LoadParser_TagoIO_RAK7204.js
Last active March 10, 2022 15:16
LoadParser TagoIO for devices RAK7204 and WisBlock Kit 1 (RAK4631) from RAKWireless.
/* This is an a generic payload parser for LoRaWAN. It will work for any network server.
** The code find the "payload" variable, sent by your sensor, and parse it if exists.
** The content of payload variable is always an Hexadecimal value.
**
** Note: Additional variables can be created by the Network Server and sent directly to the bucket. Normally they aren't handled here.
**
** Testing:
** You can do manual tests to the parse by using the Device Emulator. Copy and Paste the following JSON:
** [{ "variable": "data", "value": "0109611395" }]
*/
@vhuynen
vhuynen / RAK7204SensorDataDecoder_for_Ubidots.js
Last active February 16, 2022 21:45
Function to decode Helium's uplink data from RAK7204 device. Data are in LPP Cayenne format (RUI: RAK Unified Interface) and converted to Ubidots JSON format as expected. Inspired from GitHub projet : https://github.com/RAKWireless/RUI_LoRa_node_payload_decoder
// Function to decode Helium's uplink data from RAK7204 device.
// Data are in LPP Cayenne format (RUI: RAK Unified Interface) and converted to Ubidots JSON format as expected.
// Decoder decodes an array of bytes and uplink_info into an object.
// - port contains the LoRaWAN fPort number
// - bytes is an array of bytes, e.g. [225, 230, 255, 0]
// - uplink_info contains data from the device treated by the Helium router, e.g. { app_eui: <app_eui>, fcnt: <integer>, reported_at: <timestamp> }
// The function must return an object, e.g. { "temperature": { "value": <float>, "timestamp": <timestamp>} }
function Decoder(bytes, port, uplink_info) {
var decoded = {};
var hexString = bin2HexStr(bytes);
@vhuynen
vhuynen / lambda_function_send_sms_twilio.py
Last active March 9, 2021 21:14
Twilio Lambda function to send SMS by API Key Authentification
import json
import os
import requests
TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID')
TWILIO_CLIENT_ID = os.environ.get('TWILIO_CLIENT_ID')
TWILIO_CLIENT_SECRET = os.environ.get('TWILIO_CLIENT_SECRET')
TWILIO_SMS_URL = 'https://api.twilio.com/2010-04-01/Accounts/' \
+ TWILIO_ACCOUNT_SID + '/Messages.json'
TWILIO_ASSIGNED_NUMBER = os.environ.get('TWILIO_ASSIGNED_NUMBER')
@vhuynen
vhuynen / lambda_function_send_Free_SMS.py
Last active March 9, 2021 20:26
Lambda function to send SMS via Free Mobile API (French Operator) triggered by Amazon SNS
import json
import os
import requests
FREE_PASS =os.environ.get("FREE_PASS")
FREE_ACCOUNT=os.environ.get("FREE_ACCOUNT")
def lambda_handler(event, context):
sms_request = 'https://smsapi.free-mobile.fr/sendmsg?pass=' + FREE_PASS + '&user=' + FREE_ACCOUNT +'&msg=' + event['Records'][0]['Sns']['Message']
print(event)
@vhuynen
vhuynen / ssl_client_authn_mqtt_subscriber.py
Last active March 8, 2021 08:51
Simple example of MQTT subscriber using paho.mqtt and SSL Client Authentification for AWS Iot Core
import sys
import ssl
import time
import datetime
import json
import logging, traceback
import paho.mqtt.client as mqtt
IoT_protocol_name = "x-amzn-mqtt-ca"
aws_iot_endpoint = "XXXXXXXXXX-ats.iot.us-west-2.amazonaws.com" # <random>.iot.<region>.amazonaws.com
@vhuynen
vhuynen / ssl_client_authn_mqtt_publisher.py
Last active February 22, 2021 20:46
Simple example of MQTT publisher using paho.mqtt and SSL Client Authentification for AWS Iot Core
import sys
import ssl
import time
import datetime
import logging, traceback
import paho.mqtt.client as mqtt
IoT_protocol_name = "x-amzn-mqtt-ca"
aws_iot_endpoint = "XXXXXX-ats.iot.us-west-2.amazonaws.com" # <random>.iot.<region>.amazonaws.com
url = "https://{}".format(aws_iot_endpoint)