Skip to content

Instantly share code, notes, and snippets.

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

Manfred Müller-Späth mamuesp

🏠
Working from home
View GitHub Profile
@mamuesp
mamuesp / handle_queue.js
Created March 13, 2019 12:31
Idea for a queued MQTT publishing in MJS
// sketch to publish MQTT message with queue, if MQTT is not connected
// when connected, on every try to pubslish a message, eventually queued
// messages will be published fist
let mqtt_test = {
_queue: [], // a simple filo queue by array
_mqttConected: false, // will be set in other function by event
publishMsgQueued: function (topic, payload) {
if (this.handleQueue(topic, payload)) {
@mamuesp
mamuesp / prototypes.js
Created March 13, 2019 12:10
Queue "prototyp" fpr MJS
load("api_config.js");
let protQueue = {
_queue: [],
isEmpty: function() {
return (this._queue.length === 0);
},
add: function(obj) {
this._queue.push(obj);
},
@mamuesp
mamuesp / system_start.js
Created November 5, 2018 14:15
MJS code of a start procedure in Mongoose-OS with a pattern which will wait until WiFi, MQTT and SNTP connections are succefully set up.
load('api_http.js');
load('api_config.js');
let connected = 0;
let step = 3;
let started = false;
let watchDog = 0;
let timeOut = 30; // might be defined in the configuration ...
@mamuesp
mamuesp / mgos_draw_dif_zipped.c
Created July 28, 2018 17:09
Extend the Mongoose-OS lib ili9341-spi and allows to draw DIFs driectly from memory
bool mgos_draw_dif_zipped(uint16_t x, uint16_t y, const char * difName) {
struct mbuf *picRead = NULL;
struct mbuf *picCache = NULL;
char *bmpBuf = NULL;
char *dif_hdr = NULL;
char *dif_start = NULL;
size_t bufLen = 0;
size_t picLen = 0;
size_t difhLen = 16;
@mamuesp
mamuesp / tools.js
Last active June 1, 2018 12:34
Tool collection to use with mjs (Mongoose-OS JavaScript)
/**
Copyright 2018 M.Mueller-Spaeth <fms1961+github@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
@mamuesp
mamuesp / extract.js
Created December 8, 2015 13:17
A smal node.js based tool to extract script tags from a HTML page.
/**
*
* Created by M.MUeller-Spaeth on 07.12.15.
* Copyright 2015 by M.Mueller-Spath, fms1961@gmail.com
*
* usage: node extract.js <HTML file> <output path> <attribute name for file names>
*
*/
var fs = require('fs');
var cheerio = require('cheerio');