├── Actuator └── init.js ├── Button └── init.js ├── Models ├── wifibutton.blend └── wifibutton.stl └── README.md /Actuator/init.js: -------------------------------------------------------------------------------- 1 | load('api_config.js'); 2 | load('api_gpio.js'); 3 | load('api_mqtt.js'); 4 | load('api_sys.js'); 5 | load('api_timer.js'); 6 | load("api_pwm.js"); 7 | 8 | //*********************************************** 9 | //io.adafruit mqtt settings and set feed name here: 10 | let feedName = 'wifiButton01'; 11 | //*********************************************** 12 | let D1 = 5; 13 | let subbed = false; 14 | 15 | //trying mqtt 16 | MQTT.setEventHandler(function(conn, ev, edata) 17 | { 18 | if (ev === MQTT.EV_CONNACK && !subbed) 19 | { 20 | print('subbing mqtt'); 21 | let topic = Cfg.get('mqtt.user') + '/feeds/' + feedName; 22 | MQTT.sub(topic, function(conn, topic, msg){ 23 | print('new value ' + topic + ' ' + msg); 24 | action(); 25 | }); 26 | subbed = true; 27 | } 28 | }, null); 29 | 30 | function action() 31 | { 32 | print('moving servo'); 33 | GPIO.set_mode(D1, GPIO.MODE_OUTPUT); 34 | //move to position 0 35 | PWM.set(D1, 50, 10); 36 | //wait for servo 37 | Timer.set(1000, false , function() { 38 | //turn off servo 39 | PWM.set(D1, 50, 0); 40 | //wait a sec 41 | Timer.set(1000, false , function() { 42 | //move to position 1 43 | PWM.set(D1, 50, 1); 44 | //wait for servo 45 | Timer.set(1000, false , function() { 46 | //turn off 47 | PWM.set(D1, 50, 0); 48 | print('servo off'); 49 | }, null); 50 | }, null); 51 | }, null); 52 | } 53 | -------------------------------------------------------------------------------- /Button/init.js: -------------------------------------------------------------------------------- 1 | load('api_config.js'); 2 | load('api_gpio.js'); 3 | load('api_mqtt.js'); 4 | load('api_sys.js'); 5 | load('api_timer.js'); 6 | load("api_esp8266.js"); 7 | load('api_http.js'); 8 | 9 | //*********************************************** 10 | //put the link in the quotes if using request... 11 | let requestUrl = ''; 12 | 13 | //...or set io.adafruit mqtt settings and set feed name here: 14 | let feedName = 'wifiButton01'; 15 | 16 | //some millisecond settings. adjust to your needs 17 | let millisToTurnOff = 60000; 18 | //*********************************************** 19 | 20 | // 21 | Timer.set(millisToTurnOff , false , function() { 22 | print("deep sleep"); 23 | ESP8266.deepSleep(0); 24 | }, null); 25 | 26 | if(requestUrl.length > 0) 27 | { 28 | //request url not empty so invoke it 29 | Net.setStatusEventHandler(function(ev, edata){ 30 | if(ev !== Net.STATUS_GOT_IP) return; 31 | print("httpRequest"); 32 | HTTP.query({ 33 | url: requestUrl, 34 | success: function(){ 35 | print('HTTP request sent'); 36 | }, 37 | error: function(){ 38 | print('HTTP request failed'); 39 | } 40 | }); 41 | Net.setStatusEventHandler(function(){}, null); 42 | }, null); 43 | } 44 | 45 | //trying mqtt 46 | MQTT.setEventHandler(function(conn, ev, edata) 47 | { 48 | if (ev === MQTT.EV_CONNACK) 49 | { 50 | let topic = Cfg.get('mqtt.user') + '/feeds/' + feedName; 51 | let ok = MQTT.pub(topic, JSON.stringify(1), 1); 52 | if(ok) print('sent mqtt') 53 | else print('failed mqtt'); 54 | MQTT.setEventHandler(function(){}, null); 55 | } 56 | }, null); 57 | -------------------------------------------------------------------------------- /Models/wifibutton.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitluni/wifiButton/4484ef0bd49981482d3dbf5707c0a41afbe426b5/Models/wifibutton.blend -------------------------------------------------------------------------------- /Models/wifibutton.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitluni/wifiButton/4484ef0bd49981482d3dbf5707c0a41afbe426b5/Models/wifibutton.stl -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is some code for a WiFi-Button project using Mongoose OS 2 | After flashing Mongoose on your microcontroller simply 3 | replace the contents of the init.js with the corresponding file. 4 | The button uses a direct link or mqtt. 5 | The Actuator simply moves a servo connected to D1(aon WemMos MCU) 6 | 7 | License: 8 | 9 | The contents of this repository are licenced under cc-by 10 | https://creativecommons.org/licenses/by/4.0/deed.de 11 | 12 | This menas you can use the stuff even commercially as long you attribute me. 13 | For attribution please use bitluni and the link https://youtube.com/bitlunislab 14 | 15 | have fun! --------------------------------------------------------------------------------