Node.js is a widely used programming language for web developers. To make use of wIoT, you should first install Node.js to your computer.
For **windows** user, you can follow the instruction in [this website](https://www.jianshu.com/p/03a76b2e7e00)
## Install wIoT package
After install Node.js and configure npm successfully, you should then use npm to download wIoT package by enter following command in your command window.
Windows user can use cmd or powershell
`npm install wiot`
It should be notice that this may report error for some users. The solution is to open your cmd window as administrator.
You right click on cmd and choose *run as an administrator*.
You can also press windows+R and input *cmd* then press Ctrl+Shift+Enter to open it as administrator.
## Burn firmware
## Connect your device to D1 MINI
After burning the firmware, you should try to connect your device to D1 MINI
Follow the steps below, I'm sure it would not be a problem for such a smart person like you
### 1. Reset your D1 MINI
Find pin **D0** on your D1 MINI, it should be in the middle of A0 and D5.
Use a wire to connect **3V3** to **D0**. If your MINI works normally, you would see its BUILT-IN LED blink.
You **don't** have to wait until it stops blink, just stay for **2s**, then you can pull out the wire and your MINI would reset.
### 2.Find your D1 MINI on your device
After you finish step 1, your MINI would work in AP mode, which means you can search it with your smart phone or personal computer by scanning the Wi-Fi around
If your MINI was reset successfully, you would find a Wi-Fi with SSID in the form of **wiot-xx:xx:xx:xx:xx:xx**.
+ `wiot.register.set(status1, status2, function)`: Add a rule to register that status can be either value or function,
function would trigger if status1 == status2
The registry is designed to facilitate the use of various extension modules, See [extension module] below (# Sensor Extension Module).
+ `wiot.register.set(status, function)`: You can also pass in two functions, where the return value of status is of type bool, it would trigger the function if it changes to true
```js
var myLED = wiot.led(MyMCU, wiot.D4);
var pir = wiot.pir(MyMCU, wiot.D2);
//注册一条规则,当pir探测到人时,myLED亮
//Sign up for a rule that says myLED lights up when pir detects a person
wiot.register.set(pir.getStatus, wiot.HIGH, ()=>{
myLED.set(wiot.HIGH);
});
//注册一条规则,当人离开时,myLED灭
//Sign up for a rule that when people leave, myLED goes off
wiot.register.set(()=>{
return (wiot.LOW == pir.getStatus);
}, ()=>{
myLED.clear();
});
```
## 传感器扩展模块
## Sensor extension module
### LED
+ `wiot.led(MCU, pin)`: 声明一个led模块
+ `wiot.led.getStatus()`: 获取led状态
+ `wiot.led.set(status, time = 0, isSmooth = false)`: 设置led状态,起始状态,中间状态,最终状态,周期
+ `wiot.led.breath(period)`: 设置一个呼吸灯
+ `wiot.led.clear()`: 重置led
+ `wiot.led(MCU, pin)`: Declare a LED module
+ `wiot.led.getStatus()`: Get status of LED
+ `wiot.led.set(status, time = 0, isSmooth = false)`: Set led state, initial state, intermediate state, final state, period
+ `wiot.led.breath(period)`: Set a breathing LED
+ `wiot.led.clear()`: Reset LED
```js
MCU0 = new wiot.client({MAC: "xx:xx:xx:xx:xx:xx", pin: {D4: wiot.OUTPUT}});
var wiot = require('wiot'); //Import wiot package from npm
MCU0 = new wiot.client({MAC: "3C:71:BF:3A:F6:CF", pin: {D4: wiot.OUTPUT}});
var myLED = wiot.led(MCU0, wiot.D4); //新建一个led对象,使用MCU0上的D4口
var myLED = wiot.led(MCU0, wiot.D4); //Create a new led object using the D4 port on MCU0
/* 如果myLED不亮,则点亮它 */
/* If myLED is not shining, light it up*/
if(!myLED.getStatus()){
myLED.set(wiot.HIGH);
}
/* 设置一个周期为2秒的呼吸灯 */
/* Set a breathing light with cycle of 2s */
myLED.breath(2000);
/* 设置一个亮三秒,灭四秒的led */
/* Set a LED which light 3 seconds and off 4 seconds */
myLED.set([wiot.HIGH, wiot.LOW], [3000, 4000]);
/* 设置一个呼1秒吸3秒的呼吸渐变灯 */
/* Set a breathing light which use 1 second to light and 3 second to extinguish */
+ `wiot.ir(MCU, pin)`: Declare an IR module, pin can be analog or digital port
+ `wiot.ir.getStatus()`: Get IR state, return value wiot.high (with a barrier), wiot.low (with no barrier), or a value of 0-1024 (only for analog port)
#### Event Trigger
#### 事件触发器
+ `wiot.ir.on(event, handler)`
**事件列表**
- `detected` 探测到障碍
- `undetected` 障碍消失
- `change` 状态改变
**Event List**
- `detected` Barrier detected
- `undetected` Barrier vanished
- `change` Change state
```js
MCU0 = new wiot.client({MAC: "xx:xx:xx:xx:xx:xx"});
var myIR = wiot.ir(MCU0, wiot.D2); //新建一个ir对象,使用MCU0上的D2口
var myIR = wiot.ir(MCU0, wiot.D2); //Create a new ir object using the D2 port on MCU0
/* 输出ir状态到控制台 */
/* Output ir status to console */
console.log(myIR.getStatus());
/* 当探测到物体,打印 "Detected Object!" 到控制台 */
/* When an object is detected, print "Detected Object!" to the console */
myIR.on("detected", ()=>{
console.log("Detected Object!");
});
/* 物体移动出探测范围,打印 "No Object!!" 到控制台 */
/* When the object move out of the detective area, print "No Object!!" to the console */
Use this module to send messages to the specified cooing machine.Goo goo is a portable private printer, see [official website](https://www.memobird.shop/).
To use this module, you need to apply for your own developer ak in advance on the official website. See [here](https://api.yimian.xyz/gugu/intro.php). Proudly reference [Yimian API](https://api.yimian.xyz/)!
+ `wiot.guguji(ak, userID, memobirdID)`: Declare a goo goo chicken module, parameter: developer's ak, user id, cooing machine id
+ `wiot.guguji.send(msg)`: Send message, need to pass in the message to be sent
```js
var gugu = wiot.guguji("9e55121803474371bfa25d20e554b31f", "832598", "b3ee06a8bd9b49e1");