<commit_before># homebridge-wssensor ESP8266 LUA Code

LUA programs for a nodeMCU device to read various sensors and integrate into homebridge-wssensor.  Supports direct notification and alerting of motion events from a PIR motion sensor.

# Hardware

1. Bill of materials
   - nodeMCU / esp8266 dev kit
   - dht22 Temperature / Humidity Sensor
	Or
   - BME280 Bosch DIGITAL HUMIDITY, PRESSURE AND TEMPERATURE SENSOR
   - PIR Monition Sensor ( https://www.aliexpress.com/item/Mini-IR-Pyroelectric-Infrared-PIR-Motion-Human-Sensor-Automatic-Detector-Module-high-reliability-12mm-x-25mm/32749737125.html?spm=a2g0s.9042311.0.0.6ec74c4dwcSLq4 )

# Circuit Diagrams

## BME-MS

![BME-MS](ESP8266%20-%20WSSensor_bb.jpg)

![BME-MS](ESP8266%20-%20WSSensor_schem.jpg)

# nodeMCU Firmware

1. Using http://nodemcu-build.com, create a custom firmware containing at least
   these modules:

   adc,bit,bme280,dht,file,gpio,i2c,mdns,net,node,tmr,uart,websocket,wifi


2. Please use esptool to install the float firmware onto your nodemcu.  There are alot of guides for this, so I won't repeat it here.

# Configuration

1. WIFI Setup - Copy passwords_sample.lua to passwords.lua and add your wifi SSID and passwords.  Please note
   that the configuration supports multiple wifi networks, one per config line.
   ```
   module.SSID["SSID1"] = { ssid="SSID1", pwd = "password" }
   ```

2. Model - Either DHT-MS,  BME-MS, or ACL used by homebridge-wssensor to determine which sensor type to create in homebridge

   ```
   module.Model = "DHT-MS"
   or
   module.Model = "BME-MS"
   or
   module.Model = "ACL"
   ```

# Lua Program installation

1. Please use ESPlorer to install the lua files on the device.

config.lua
setup.lua
test.lua
passwords.lua
led.lua
lua-mdns.lua

* ACL / MPU6050 module please also include

accel.lua
mpu6050.lua

* BME-MS module please also include

2. Compile all lua files to lc files using ESPlorer

3. Reboot your device

4. Output from boot via the serial console should look like this.

```
NodeMCU custom build by frightanic.com
	branch: master
	commit: <PASSWORD>
	SSL: false
	modules: adc,am2320,bit,dht,file,gpio,mdns,net,node,tmr,uart,wifi
 build 	built on: 2016-06-27 22:58
 powered by Lua 5.1.4 on SDK 1.5.1(e67da894)
Booting...
Setting Init Timer
Configuring Wifi ...
> Connecting to XXXXXXX ...
IP unavailable, Waiting...

====================================
ESP8266 mode is: 1
MAC address is: 5e:cf:7f:18:a6:b3
IP is 192.168.1.146
====================================
```<commit_msg>README Cleanup<commit_after># homebridge-wssensor ESP8266 LUA Code

LUA programs for a nodeMCU device to read various sensors and integrate into homebridge-wssensor.  Supports direct notification and alerting of motion events from a PIR motion sensor.

# Hardware

1. Bill of materials
   - nodeMCU / esp8266 dev kit

Sensor options

   - DHT22 Temperature / Humidity Sensor
   - BME280 Bosch DIGITAL HUMIDITY, PRESSURE AND TEMPERATURE SENSOR
   - AM312 PIR Monition Sensor  ( https://www.aliexpress.com/item/Mini-IR-Pyroelectric-Infrared-PIR-Motion-Human-Sensor-Automatic-Detector-Module-high-reliability-12mm-x-25mm/32749737125.html?spm=a2g0s.9042311.0.0.6ec74c4dwcSLq4 )
   - MPU 6050 Acceleration/gyroscope sensor aka GY-521 Breakout board

# Circuit Diagrams

## BME-MS

![BME-MS](ESP8266%20-%20WSSensor_bb.jpg)

![BME-MS](ESP8266%20-%20WSSensor_schem.jpg)

## AM312

Pinout

```
-- Gnd
-- Signal
-- VCC +5v
```

# nodeMCU Firmware

1. Using http://nodemcu-build.com, create a custom firmware containing at least
   these modules:

   adc,bit,bme280,dht,file,gpio,i2c,mdns,net,node,tmr,uart,websocket,wifi


2. Please use esptool to install the float firmware onto your nodemcu.  There are alot of guides for this, so I won't repeat it here.

# Configuration

1. WIFI Setup - Copy passwords_sample.lua to passwords.lua and add your wifi SSID and passwords.  Please note
   that the configuration supports multiple wifi networks, one per config line.
   ```
   module.SSID["SSID1"] = { ssid="SSID1", pwd = "password" }
   ```

2. Model - Either DHT-MS,  BME-MS, or ACL used by homebridge-wssensor to determine which sensor type to create in homebridge

   ```
   module.Model = "DHT-MS"
   or
   module.Model = "BME-MS"
   or
   module.Model = "ACL"
   ```

# Lua Program installation

1. Please use ESPlorer to install the lua files on the device.

config.lua
setup.lua
test.lua
passwords.lua
led.lua
lua-mdns.lua

* ACL / MPU6050 module please also include

accel.lua
mpu6050.lua

* BME-MS module please also include

bme.lua
motion.lua
sensors.lua


2. Compile all lua files to lc files using ESPlorer

3. Test your device by running test.lua

4. After you have completed testing, rename test.lua to init.lua
{'fraction_non_alphanumeric': 0.10695413231874867, 'fraction_numerical': 0.04819277108433735, 'mean_word_length': 3.843398157625384, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7084286', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1661, 'n_words': 513}