Skip to content

Commit

Permalink
Merge pull request #34 from devicehive/develop
Browse files Browse the repository at this point in the history
v0.7
  • Loading branch information
Nikolay-Kha authored Aug 9, 2017
2 parents 18d0a37 + 24b8065 commit fa0a124
Show file tree
Hide file tree
Showing 238 changed files with 10,363 additions and 5,813 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ release/build
release/*.zip
release/*.tar.gz
firmware-src/pages/debug.log
.DS_Store

151 changes: 89 additions & 62 deletions DeviceHiveESP8266.md

Large diffs are not rendered by default.

80 changes: 41 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,82 @@
# DeviceHive ESP8266 Firmware
Special firmware for usage ESP8266 as local web server with RESTful API and as DeviceHive clouds client.
This repo consist of few parts of this project which can be used with
Special firmware to use ESP8266 as a local web server with RESTful API and as a client of DeviceHive cloud.
This repo consists of a few parts which can be used with
other projects. Each project has dedicated readme file.

![](images/demo-device.jpg?raw=true)
Photo above is a real photo of the demo device contructed with esp8266. See
http://youtu.be/hzi4djt-wdg
[YouTube video](http://youtu.be/hzi4djt-wdg).

# [DeviceHiveESP8266.md](DeviceHiveESP8266.md)
This is the main documentation file for this firmware. Document contains
commands specification, describes all features and firmware usage.
[Click here to open it.](DeviceHiveESP8266.md)
commands specification, describes all features and firmware usage.
[Click here to open it](DeviceHiveESP8266.md).

# Demo videos
Zero wireless configuring with Android http://youtu.be/2J98YDpbJKo
DeviceHive clouds demos:
BH1750 Ambient light http://youtu.be/AkSFdO0soyo
DS18B20 + iButton + DHT11 http://youtu.be/IuvxwCPNZCc
Muscle connected to the cloud http://youtu.be/8L96nBNHE14
SSD1306 OLED display http://youtu.be/gKgU6RzaxFU
Multple sensor connection http://youtu.be/hzi4djt-wdg
Smart socket http://youtu.be/hCdzcCjYYMw
Wireless Configuring with Mac and Linux http://youtu.be/sFD2TTZNNvo
BMP180 Atmospheric pressure http://youtu.be/P2rxnVjRPyc
MPU6050 Accelerometer + Gyroscope http://youtu.be/IRj4tOfLTAM
MFRC522 RFID Reader http://youtu.be/VMT3v49d57g
Simple relay http://youtu.be/ZLq2X2n_wR0
- [Zero wireless configuring with Android](http://youtu.be/2J98YDpbJKo)
- [BH1750 Ambient light](http://youtu.be/AkSFdO0soyo)
- [DS18B20 + iButton + DHT11](http://youtu.be/IuvxwCPNZCc)
- [Muscle connected to the cloud](http://youtu.be/8L96nBNHE14)
- [SSD1306 OLED display](http://youtu.be/gKgU6RzaxFU)
- [Multple sensor connection](http://youtu.be/hzi4djt-wdg)
- [Smart socket](http://youtu.be/hCdzcCjYYMw)
- [Wireless Configuring with Mac and Linux](http://youtu.be/sFD2TTZNNvo)
- [BMP180 Atmospheric pressure](http://youtu.be/P2rxnVjRPyc)
- [MPU6050 Accelerometer + Gyroscope](http://youtu.be/IRj4tOfLTAM)
- [MFRC522 RFID Reader](http://youtu.be/VMT3v49d57g)
- [Simple relay](http://youtu.be/ZLq2X2n_wR0)

# custom firmwares
# Custom firmwares
There is a possibility to build custom firmware on top of this which sends some
notifications to DeviceHive server periodically. In pauses firmware goes to deep
sleep mode. Reimplement `custom_firmware_request()` method in
`custom_firmware.c` file with reading of some sensors data. There are
implementation for some sensors in `sources/devices` dir. Also, it is possible
to create interaction with any sensor using interface implementation modules
(dhi2c, dhspi, dhonewire etc). See `climate` branch as an example.
(`dh/i2c`, `dh/spi`, `dh/onewire` etc). See `climate` branch as an example.

# esp-utils
# Directory content

## esp-utils
Simple utils for flashing and connecting to ESP8266.

# examples-cloud
Simple web pages with JavaScript sample of sendind recieving command
from device via cloud. Onewire DS18B20 examples use 0x33[SKIP ROM] command
## examples-cloud
Simple web pages with JavaScript sample of sendind and receiving commands
from device via cloud. Onewire DS18B20 examples use `0x33[SKIP ROM]` command
which means that examples work only with one currently connected device. Some
browsers(for example Firefox) block cross domen requests even for local file.
browsers (for example Firefox) block cross domen requests even for local file.
Allow temporary cross domain requests in setting or use another browser to run
examples.

Local RESTful API samples are embedded to firmware. Sources of them can be found
at firmware-src/pages directory.

# firmware-src
## firmware-src
Sources of DeviceHive ESP8266 firmware.

# firmware-src/genbin.sh
## firmware-src/genbin.sh
Small utils which is written on bash and can be used on any OS. This util
creates binary firmware files files from crosstool-NG binary file output.
creates binary firmware files from crosstool-NG binary file output.

# firmware-tests
Tests for firmware. Youcan find sample of command in file requests.html. Each
addtest() instance have boolean third parameter. If this parameters is true it
## firmware-tests
Tests for firmware. You can find command samples in file requests.html. Each
`addtest()` instance have boolean third parameter. If this parameters is `true` it
means that command and parameters is written correctly and you can use it as
a sample.

# release
## release
Scripts for generating binary releases.

# sdk
## sdk
SDK from chip manufactor. Included in this repo to make sure that we are
using the same version of this SDK to avoid any surprises from changing APIs

# License
The MIT License. See LICENSE file. Except sdk directory, it has ESPRSSIF MIT
License, see sdk/License file for details.
## License
The MIT License. See [LICENSE](./LICENSE) file. Except sdk directory, it has ESPRSSIF MIT
License, see [sdk/License](./sdk/License) file for details.

# Authors
Nikolay Khabarov
Igor Malovitsa
Maksim Kleshchevnikov
- Nikolay Khabarov
- Sergey Polichnoy
- Igor Malovitsa
- Maksim Kleshchevnikov
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ v0.6
- access point mode
- embedded pages redesign
- sample of using D3.js for plotting graphs from different sensors on embedded web server

v0.7
- new command 'command/list'
- connectino to server now is implemeted with WebSocket
- latest DeviceHive server v3.x and playground support
- compile time ability to disable some devices
28 changes: 15 additions & 13 deletions esp-utils/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
# DeviceHive ESP8266 Simple utils
esp-terminal:
Simple tool for easy access to DeviceHive ESP8266 firmware terminal in production
`esp-terminal`:
Simple tool for easy access DeviceHive ESP8266 firmware terminal in production
release with simple support of ansi escape codes
esp-flasher:

`esp-flasher`:
Simple tool for flashing DeviceHive firmware in ESP8266

# How To Build
run 'make'
all binary files will be generated in 'build' directory.
Run `make`.
All binary files will be generated in `build` directory.

# esp-terminal usage
Run application and it will try to detect device automatically. You also can
specify device manually by passing port name in command line.
To quit from terminal press Ctrl+Q
To quit from terminal press `Ctrl+Q`.

# esp-flasher usage
Run application and it will try to detect device automatically. If no parameters
were specified it also will try to open files devicehive.bin in current directory
were specified it also will try to open files `devicehive.bin` in current directory
and directory with its binary and flash them to corresponding addresses.
You can specify port name in first argument if you want to specify it manually.
You also can specify which files have to be written in devices in arguments by
pairs hex address <space> file name. For exmaple:
pairs `hex address <space> file name`. For exmaple:

```
esp-flasher COM2 0x00000 boot.img 0x40000 spi.img
esp-flasher 0x40000 myimagefile.bin
```

There also `--developer` and `--reboot` arguments which supposed to be used by
developers only. First enables incremental flash mode, it compares previosuly
flashed file (should be saved as `devicehive.bin.prev`) and if differences are
minimal it will flash only them to save time on flashing. `--reboot` argument
simply reboot chip (serial adapter RTS should connected to GPIO0, DTR to RTS
simply reboot chip (serial adapter `RTS` should be connected to `GPIO0`, `DTR` to `RTS`
pin).

# License
see LICENSE file

# Authors
Nikolay Khabarov
See [LICENSE](./LICENSE) file.
7 changes: 6 additions & 1 deletion esp-utils/common/serialport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#include <string.h>
#include "serialport.h"

SerialPort::SerialPort(COM comport) {
SerialPort::SerialPort(COM comport, const char *name) {
mCom = comport;
mTreadFlag = true;
mReadFlag = false;
mReadError = false;
mBytesRecivedSinceLastSend = 0;
mThread = 0;
mLastReceived = 0;
snprintf(mName, sizeof(mName), "%s", name);
}

COM SerialPort::get_com() {
Expand Down Expand Up @@ -65,3 +66,7 @@ void SerialPort::send(const void *data, unsigned int len) {
if(bw != len)
SerialPortError(this, ERROR_WRITE_STRING);
}

const char *SerialPort::getName() {
return mName;
}
4 changes: 3 additions & 1 deletion esp-utils/common/serialport.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ class SerialPort
void setRts(bool val);
void setDtr(bool val);
void sleep(unsigned int ms);
const char *getName();
private:
#ifdef COMWINDOWS
static DWORD ThreadProc (LPVOID lpdwThreadParam);
#else
static void * thread_start(void *arg);
#endif
SerialPort(COM comport);
SerialPort(COM comport, const char *name);
unsigned int write_native(const void *data, unsigned int len);
bool read_native(const void *data, unsigned int len, unsigned int *rb);
static unsigned int getTick();
Expand All @@ -60,6 +61,7 @@ class SerialPort
unsigned int mBytesRecivedSinceLastSend;
bool mReadError;
unsigned int mLastReceived;
char mName[256];
};

extern void SerialPortRecieved(SerialPort *port, const char *text, unsigned int len);
Expand Down
12 changes: 6 additions & 6 deletions esp-utils/common/serialport_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ SerialPort *SerialPort::open(const char *port) {
{
struct termios tio;
memset(&tio,0,sizeof(tio));
if ( tcgetattr ( comp, &tio ) != 0 ) {
if( tcgetattr ( comp, &tio ) != 0 ) {
close(comp);
return 0;
}
Expand All @@ -77,12 +77,12 @@ SerialPort *SerialPort::open(const char *port) {

tcflush(comp, TCIOFLUSH);

if ( tcsetattr ( comp, TCSANOW, &tio ) != 0) {
if( tcsetattr ( comp, TCSANOW, &tio ) != 0) {
close(comp);
return 0;
}

SerialPort *comport = new SerialPort(comp);
SerialPort *comport = new SerialPort(comp, port);
pthread_t thr;
if(pthread_create(&thr, 0, thread_start, (void *)comport)!=0) {
delete comport;
Expand Down Expand Up @@ -118,7 +118,7 @@ void SerialPort::sleep(unsigned int ms) {
usleep(ms*1000);
}

#if ( defined(__APPLE__) || defined(__MACH__) )
#if( defined(__APPLE__) || defined(__MACH__) )
const static char TTYUSB_PATTERN[] = "tty.";
#else
const static char TTYUSB_PATTERN[] = "ttyUSB";
Expand Down Expand Up @@ -160,7 +160,7 @@ unsigned int SerialPort::getTick() {
void SerialPort::setRts(bool val) {
int flag;
if(ioctl(mCom, TIOCMGET, &flag) != -1) {
if (val)
if(val)
flag |= TIOCM_RTS;
else
flag &= ~TIOCM_RTS;
Expand All @@ -171,7 +171,7 @@ void SerialPort::setRts(bool val) {
void SerialPort::setDtr(bool val) {
int flag;
if(ioctl(mCom, TIOCMGET, &flag) != -1) {
if (val)
if(val)
flag |= TIOCM_DTR;
else
flag &= ~TIOCM_DTR;
Expand Down
6 changes: 3 additions & 3 deletions esp-utils/common/serialport_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ SerialPort *SerialPort::open(const char *port) {
char namebuff[MAX_PATH];
snprintf(namebuff, sizeof namebuff, "\\\\.\\%s", port);
HANDLE hCOM=CreateFileA(namebuff,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if (hCOM!=INVALID_HANDLE_VALUE)
if(hCOM!=INVALID_HANDLE_VALUE)
{
DCB cdcb;
if( GetCommState(hCOM,&cdcb)==0 ) {
Expand All @@ -86,9 +86,9 @@ SerialPort *SerialPort::open(const char *port) {
to.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(hCOM,&to);

SerialPort *comport = new SerialPort(hCOM);
SerialPort *comport = new SerialPort(hCOM, port);
DWORD dwThreadId;
if ( (comport->mThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&ThreadProc, (LPVOID)comport, 0, &dwThreadId)) == NULL)
if( (comport->mThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&ThreadProc, (LPVOID)comport, 0, &dwThreadId)) == NULL)
{
delete comport;
return 0;
Expand Down
2 changes: 1 addition & 1 deletion esp-utils/common/terminal_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void Terminal::put(char c) {
} else if(escRecieving) {
escSequence[escSequencePos++] = c;
escSequence[escSequencePos] = 0;
if (escSequencePos == 1 && c == '[')
if(escSequencePos == 1 && c == '[')
return;
if((c >= 0x40 && c <= 0x7e) || escSequencePos >= sizeof(escSequence) - 1) {
if(strcmp(escSequence, "[C") == 0) { // Right
Expand Down
Loading

0 comments on commit fa0a124

Please sign in to comment.