The ADC module provides access to the in-built ADC.
The ADC module provides access to the in-built ADC.
On the ESP8266 there is only a single-channel, which is multiplexed with the battery voltage. Depending on the setting in the "esp init data" (byte 107) one can either use the ADC to read an external voltage, or to read the system voltage, but not both.
On the ESP8266 there is only a single-channel, which is multiplexed with the battery voltage. Depending on the setting in the "esp init data" (byte 107) one can either use the ADC to read an external voltage, or to read the system voltage, but not both.
...
@@ -36,4 +40,4 @@ none
...
@@ -36,4 +40,4 @@ none
####Returns
####Returns
system voltage in millivolts (number)
system voltage in millivolts (number)
If the ESP8266 has been configured to use the ADC for sampling the external pin, this function will always return 65535. This is a hardware and/or SDK limitation.
If the ESP8266 has been configured to use the ADC for sampling the external pin, this function will always return 65535. This is a hardware and/or SDK limitation.
This module provides access to the [AM2320](https://akizukidenshi.com/download/ds/aosong/AM2320.pdf) humidity and temperature sensor, using the i2c interface.
This module provides access to the [AM2320](https://akizukidenshi.com/download/ds/aosong/AM2320.pdf) humidity and temperature sensor, using the i2c interface.
This module provides Lua access to [APA102 RGB LEDs](https://youtu.be/UYvC-hukz-0) which are similar in function to the common [WS2812](ws2812) addressable LEDs.
This module provides Lua access to [APA102 RGB LEDs](https://youtu.be/UYvC-hukz-0) which are similar in function to the common [WS2812](ws2812) addressable LEDs.
> DotStar LEDs are 5050-sized LEDs with an embedded micro controller inside the LED. You can set the color/brightness of each LED to 24-bit color (8 bits each red green and blue). Each LED acts like a shift register, reading incoming color data on the input pins, and then shifting the previous color data out on the output pin. By sending a long string of data, you can control an infinite number of LEDs, just tack on more or cut off unwanted LEDs at the end.
> DotStar LEDs are 5050-sized LEDs with an embedded micro controller inside the LED. You can set the color/brightness of each LED to 24-bit color (8 bits each red green and blue). Each LED acts like a shift register, reading incoming color data on the input pins, and then shifting the previous color data out on the output pin. By sending a long string of data, you can control an infinite number of LEDs, just tack on more or cut off unwanted LEDs at the end.
This module provides a simple interface to [BME280/BMP280 temperature/air presssure/humidity sensors](http://www.bosch-sensortec.com/bst/products/all_products/bme280)(Bosch Sensortec).
This module provides a simple interface to [BME280/BMP280 temperature/air presssure/humidity sensors](http://www.bosch-sensortec.com/bst/products/all_products/bme280)(Bosch Sensortec).
This module provides access to the [BMP085](https://www.sparkfun.com/tutorials/253) temperature and pressure sensor. The module also works with BMP180.
This module provides access to the [BMP085](https://www.sparkfun.com/tutorials/253) temperature and pressure sensor. The module also works with BMP180.
The basic endpoint server part is based on [microcoap](https://github.com/1248/microcoap), and many other code reference [libcoap](https://github.com/obgm/libcoap).
This module implements both the client and the server side. GET/PUT/POST/DELETE is partially supported by the client. Server can register Lua functions and varibles. No observe or discover supported yet.
The CoAP module provides a simple implementation according to [CoAP](http://tools.ietf.org/html/rfc7252) protocol.
## Caution
The basic endpoint server part is based on [microcoap](https://github.com/1248/microcoap), and many other code reference [libcoap](https://github.com/obgm/libcoap).
This module is only in the very early stage and not complete yet.
This module implements both the client and the server side. GET/PUT/POST/DELETE is partially supported by the client. Server can register Lua functions and varibles. No observe or discover supported yet.
## Caution
This module is only in the very early stage and not complete yet.
## Constants
## Constants
Constants for various functions.
Constants for various functions.
`coap.CON`, `coap.NON` represent the request types.
`coap.CON`, `coap.NON` represent the request types.
cs:var("myvar")-- get coap://192.168.18.103:5683/v1/v/myvar will return the value of myvar: 1
cs:var("myvar")-- get coap://192.168.18.103:5683/v1/v/myvar will return the value of myvar: 1
all='[1,2,3]'
all='[1,2,3]'
cs:var("all",coap.JSON)-- sets content type to json
cs:var("all",coap.JSON)-- sets content type to json
-- function should tack one string, return one string.
-- function should tack one string, return one string.
functionmyfun(payload)
functionmyfun(payload)
print("myfun called")
print("myfun called")
respond="hello"
respond="hello"
returnrespond
returnrespond
end
end
cs:func("myfun")-- post coap://192.168.18.103:5683/v1/f/myfun will call myfun
cs:func("myfun")-- post coap://192.168.18.103:5683/v1/f/myfun will call myfun
```
```
# CoAP Client
# CoAP Client
## coap.client:get()
## coap.client:get()
Issues a GET request to the server.
Issues a GET request to the server.
#### Syntax
#### Syntax
`coap.client:get(type, uri[, payload])`
`coap.client:get(type, uri[, payload])`
#### Parameters
#### Parameters
-`type``coap.CON`, `coap.NON`, defaults to CON. If the type is CON and request fails, the library retries four more times before giving up.
-`type``coap.CON`, `coap.NON`, defaults to CON. If the type is CON and request fails, the library retries four more times before giving up.
-`uri` the URI such as "coap://192.168.18.103:5683/v1/v/myvar", only IP addresses are supported i.e. no hostname resoltion.
-`uri` the URI such as "coap://192.168.18.103:5683/v1/v/myvar", only IP addresses are supported i.e. no hostname resoltion.
-`payload` optional, the payload will be put in the payload section of the request.
-`payload` optional, the payload will be put in the payload section of the request.
#### Returns
#### Returns
`nil`
`nil`
## coap.client:put()
## coap.client:put()
Issues a PUT request to the server.
Issues a PUT request to the server.
#### Syntax
#### Syntax
`coap.client:put(type, uri[, payload])`
`coap.client:put(type, uri[, payload])`
#### Parameters
#### Parameters
-`type``coap.CON`, `coap.NON`, defaults to CON. If the type is CON and request fails, the library retries four more times before giving up.
-`type``coap.CON`, `coap.NON`, defaults to CON. If the type is CON and request fails, the library retries four more times before giving up.
-`uri` the URI such as "coap://192.168.18.103:5683/v1/v/myvar", only IP addresses are supported i.e. no hostname resoltion.
-`uri` the URI such as "coap://192.168.18.103:5683/v1/v/myvar", only IP addresses are supported i.e. no hostname resoltion.
-`payload` optional, the payload will be put in the payload section of the request.
-`payload` optional, the payload will be put in the payload section of the request.
#### Returns
#### Returns
`nil`
`nil`
## coap.client:post()
## coap.client:post()
Issues a POST request to the server.
Issues a POST request to the server.
#### Syntax
#### Syntax
`coap.client:post(type, uri[, payload])`
`coap.client:post(type, uri[, payload])`
#### Parameters
#### Parameters
-`type` coap.CON, coap.NON, defaults to CON. when type is CON, and request failed, the request will retry another 4 times before giving up.
-`type` coap.CON, coap.NON, defaults to CON. when type is CON, and request failed, the request will retry another 4 times before giving up.
-`uri` the uri such as coap://192.168.18.103:5683/v1/v/myvar, only IP is supported.
-`uri` the uri such as coap://192.168.18.103:5683/v1/v/myvar, only IP is supported.
-`payload` optional, the payload will be put in the payload section of the request.
-`payload` optional, the payload will be put in the payload section of the request.
#### Returns
#### Returns
`nil`
`nil`
## coap.client:delete()
## coap.client:delete()
Issues a DELETE request to the server.
Issues a DELETE request to the server.
#### Syntax
#### Syntax
`coap.client:delete(type, uri[, payload])`
`coap.client:delete(type, uri[, payload])`
#### Parameters
#### Parameters
-`type``coap.CON`, `coap.NON`, defaults to CON. If the type is CON and request fails, the library retries four more times before giving up.
-`type``coap.CON`, `coap.NON`, defaults to CON. If the type is CON and request fails, the library retries four more times before giving up.
-`uri` the URI such as "coap://192.168.18.103:5683/v1/v/myvar", only IP addresses are supported i.e. no hostname resoltion.
-`uri` the URI such as "coap://192.168.18.103:5683/v1/v/myvar", only IP addresses are supported i.e. no hostname resoltion.
-`payload` optional, the payload will be put in the payload section of the request.
-`payload` optional, the payload will be put in the payload section of the request.
#### Returns
#### Returns
`nil`
`nil`
# CoAP Server
# CoAP Server
## coap.server:listen()
## coap.server:listen()
Starts the CoAP server on the given port.
Starts the CoAP server on the given port.
#### Syntax
#### Syntax
`coap.server:listen(port[, ip])`
`coap.server:listen(port[, ip])`
#### Parameters
#### Parameters
-`port` server port (number)
-`port` server port (number)
-`ip` optional IP address
-`ip` optional IP address
#### Returns
#### Returns
`nil`
`nil`
## coap.server:close()
## coap.server:close()
Closes the CoAP server.
Closes the CoAP server.
#### Syntax
#### Syntax
`coap.server:close()`
`coap.server:close()`
#### Parameters
#### Parameters
none
none
#### Returns
#### Returns
`nil`
`nil`
## coap.server:var()
## coap.server:var()
Registers a Lua variable as an endpoint in the server. the variable value then can be retrieved by a client via GET method, represented as an [URI](http://tools.ietf.org/html/rfc7252#section-6) to the client. The endpoint path for varialble is '/v1/v/'.
Registers a Lua variable as an endpoint in the server. the variable value then can be retrieved by a client via GET method, represented as an [URI](http://tools.ietf.org/html/rfc7252#section-6) to the client. The endpoint path for varialble is '/v1/v/'.
#### Syntax
#### Syntax
`coap.server:var(name[, content_type])`
`coap.server:var(name[, content_type])`
#### Parameters
#### Parameters
-`name` the Lua variable's name
-`name` the Lua variable's name
-`content_type` optional, defaults to `coap.TEXT_PLAIN`, see [Content Negotiation](http://tools.ietf.org/html/rfc7252#section-5.5.4)
-`content_type` optional, defaults to `coap.TEXT_PLAIN`, see [Content Negotiation](http://tools.ietf.org/html/rfc7252#section-5.5.4)
#### Returns
#### Returns
`nil`
`nil`
#### Example
#### Example
```lua
```lua
-- use copper addon for firefox
-- use copper addon for firefox
cs=coap.Server()
cs=coap.Server()
cs:listen(5683)
cs:listen(5683)
myvar=1
myvar=1
cs:var("myvar")-- get coap://192.168.18.103:5683/v1/v/myvar will return the value of myvar: 1
cs:var("myvar")-- get coap://192.168.18.103:5683/v1/v/myvar will return the value of myvar: 1
-- cs:var(myvar), WRONG, this api accept the name string of the varialbe. but not the variable itself.
-- cs:var(myvar), WRONG, this api accept the name string of the varialbe. but not the variable itself.
all='[1,2,3]'
all='[1,2,3]'
cs:var("all",coap.JSON)-- sets content type to json
cs:var("all",coap.JSON)-- sets content type to json
```
```
## coap.server:func()
## coap.server:func()
Registers a Lua function as an endpoint in the server. The function then can be called by a client via POST method. represented as an [URI](http://tools.ietf.org/html/rfc7252#section-6) to the client. The endpoint path for function is '/v1/f/'.
Registers a Lua function as an endpoint in the server. The function then can be called by a client via POST method. represented as an [URI](http://tools.ietf.org/html/rfc7252#section-6) to the client. The endpoint path for function is '/v1/f/'.
When the client issues a POST request to this URI, the payload will be passed to the function as parameter. The function's return value will be the payload in the message to the client.
When the client issues a POST request to this URI, the payload will be passed to the function as parameter. The function's return value will be the payload in the message to the client.
The function registered SHOULD accept ONLY ONE string type parameter, and return ONE string value or return nothing.
The function registered SHOULD accept ONLY ONE string type parameter, and return ONE string value or return nothing.
#### Syntax
#### Syntax
`coap.server:func(name[, content_type])`
`coap.server:func(name[, content_type])`
#### Parameters
#### Parameters
-`name` the Lua function's name
-`name` the Lua function's name
-`content_type` optional, defaults to `coap.TEXT_PLAIN`, see [Content Negotiation](http://tools.ietf.org/html/rfc7252#section-5.5.4)
-`content_type` optional, defaults to `coap.TEXT_PLAIN`, see [Content Negotiation](http://tools.ietf.org/html/rfc7252#section-5.5.4)
#### Returns
#### Returns
`nil`
`nil`
#### Example
#### Example
```lua
```lua
-- use copper addon for firefox
-- use copper addon for firefox
cs=coap.Server()
cs=coap.Server()
cs:listen(5683)
cs:listen(5683)
-- function should take only one string, return one string.
-- function should take only one string, return one string.
functionmyfun(payload)
functionmyfun(payload)
print("myfun called")
print("myfun called")
respond="hello"
respond="hello"
returnrespond
returnrespond
end
end
cs:func("myfun")-- post coap://192.168.18.103:5683/v1/f/myfun will call myfun
cs:func("myfun")-- post coap://192.168.18.103:5683/v1/f/myfun will call myfun
-- cs:func(myfun), WRONG, this api accept the name string of the function. but not the function itself.
-- cs:func(myfun), WRONG, this api accept the name string of the function. but not the function itself.
Provides an interface to do basic GET/POST/PUT/DELETE over HTTP(S), as well as customized requests. Due to the memory constraints on ESP8266, the supported page/body size is limited by available memory. Attempting to receive pages larger than this will fail. If larger page/body sizes are necessary, consider using `net.createConnection()` and stream in the data.
Provides an interface to do basic GET/POST/PUT/DELETE over HTTP(S), as well as customized requests. Due to the memory constraints on ESP8266, the supported page/body size is limited by available memory. Attempting to receive pages larger than this will fail. If larger page/body sizes are necessary, consider using [`net.createConnection()`](#netcreateconnection) and stream in the data.
Each request method takes a callback which is invoked when the response has been received from the server. The first argument is the status code, which is either a regular HTTP status code, or -1 to denote a DNS, connection or out-of-memory failure, or a timeout (currently at 10 seconds).
Each request method takes a callback which is invoked when the response has been received from the server. The first argument is the status code, which is either a regular HTTP status code, or -1 to denote a DNS, connection or out-of-memory failure, or a timeout (currently at 10 seconds).
...
@@ -13,10 +16,7 @@ For each operation it is also possible to include custom headers. Note that foll
...
@@ -13,10 +16,7 @@ For each operation it is also possible to include custom headers. Note that foll
The `Host` header is taken from the URL itself, the `Connection` is always set to `close`, and the `User-Agent` is `ESP8266`.
The `Host` header is taken from the URL itself, the `Connection` is always set to `close`, and the `User-Agent` is `ESP8266`.
Note that it is not possible to execute concurrent HTTP requests using this module. Starting a new request before the previous has completed will result in undefined behaviour.
Note that it is not possible to execute concurrent HTTP requests using this module. Starting a new request before the previous has completed will result in undefined behavior.
This module provides access to an [HX711 load cell amplifier/ADC](https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide). The HX711 is an inexpensive 24bit ADC with programmable 128x, 64x, and 32x gain. Currently only channel A at 128x gain is supported.
This module provides access to an [HX711 load cell amplifier/ADC](https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide). The HX711 is an inexpensive 24bit ADC with programmable 128x, 64x, and 32x gain. Currently only channel A at 128x gain is supported.
[Multicast DNS](https://en.wikipedia.org/wiki/Multicast_DNS) is used as part of Bonjour / Zeroconf. This allows system to identify themselves and the services that they provide on a local area network. Clients are then able to discover these systems and connect to them.
[Multicast DNS](https://en.wikipedia.org/wiki/Multicast_DNS) is used as part of Bonjour / Zeroconf. This allows system to identify themselves and the services that they provide on a local area network. Clients are then able to discover these systems and connect to them.
The client adheres to version 3.1.1 of the [MQTT](https://en.wikipedia.org/wiki/MQTT) protocol. Make sure that your broker supports and is correctly configured for version 3.1.1. The client is backwards incompatible with brokers running MQTT 3.1.
The client adheres to version 3.1.1 of the [MQTT](https://en.wikipedia.org/wiki/MQTT) protocol. Make sure that your broker supports and is correctly configured for version 3.1.1. The client is backwards incompatible with brokers running MQTT 3.1.