Using PWM functions in Mongoose OS for fan control - SugarFreeOrbit/MosquittoMQTT GitHub Wiki
Get yourself a 4-wire fan (it is supposed to be alright even with a 3-wire fan, but didn't work quite right for me).
Connect the red wire with the power supply and the black wire with ground(GND).
Connect the green wire with the pin which you mignt want to use later for reading the tachometric control.
Connect the last wire with the pin that you want to use for sending the PWM signal.
You need to add the PWM library to your Mongoose OS project and include it in the beggining of init.js.
Now to control the PWN you simply use the following PWM.set(PIN_NUMBER, FREQUENCY, DUTY) (FREQUENCY is in hz).
For a 4-wire fan you will need a frequency from 21kHz to 28kHz(the optimal is 25kHz), the higher the duty - the higher the speed(from 0 to 100).