├── .github └── workflows │ ├── stale.yml │ ├── sync_issues.yml │ └── sync_prs.yml ├── .gitmodules ├── Dockerfile ├── Main.cpp.template ├── Makefile.template ├── README.md ├── alert_database.sql ├── boards.json ├── build_firmware.py ├── cache.py ├── config.py ├── coroutine_msgbus.py ├── database.db ├── esp8266_arduino ├── Arduino.h ├── Client.h ├── Esp.cpp ├── Esp.h ├── HardwareSerial.cpp ├── HardwareSerial.h ├── Print.cpp ├── Print.h ├── Printable.h ├── Stream.cpp ├── Stream.h ├── WCharacter.h ├── WMath.cpp ├── WString.cpp ├── WString.h ├── Wire.cpp ├── Wire.h ├── abi.cpp ├── binary.h ├── cbuf.h ├── cont.h ├── cont.s ├── cont_util.c ├── core_esp8266_main.cpp ├── core_esp8266_noniso.c ├── core_esp8266_si2c.c ├── core_esp8266_timer.c ├── core_esp8266_wiring.c ├── core_esp8266_wiring_analog.c ├── core_esp8266_wiring_digital.c ├── core_esp8266_wiring_pulse.c ├── core_esp8266_wiring_pwm.c ├── core_esp8266_wiring_shift.c ├── debug.cpp ├── debug.h ├── esp8266_peri.h ├── interrupts.h ├── libc_replacements.c ├── pgmspace.cpp ├── pgmspace.h ├── pins_arduino.h ├── stdlib_noniso.h ├── twi.h └── wiring_private.h ├── esp8266_sdk ├── include │ ├── at_custom.h │ ├── c_types.h │ ├── eagle_soc.h │ ├── espconn.h │ ├── espnow.h │ ├── ets_sys.h │ ├── gpio.h │ ├── ip_addr.h │ ├── json │ │ ├── json.h │ │ ├── jsonparse.h │ │ └── jsontree.h │ ├── mem.h │ ├── mesh.h │ ├── os_type.h │ ├── osapi.h │ ├── ping.h │ ├── pwm.h │ ├── queue.h │ ├── smartconfig.h │ ├── sntp.h │ ├── spi_flash.h │ ├── upgrade.h │ └── user_interface.h ├── ld │ ├── eagle.app.v6.new.1024.app1.ld │ ├── eagle.app.v6.new.1024.app2.ld │ ├── eagle.app.v6.new.2048.ld │ ├── eagle.app.v6.new.512.app1.ld │ ├── eagle.app.v6.new.512.app2.ld │ ├── eagle.app.v6.new.sections.ld │ ├── eagle.rom.addr.v6.ld │ └── spiffs.ld.tobedelete ├── lib │ ├── libat.a │ ├── libcrypto.a │ ├── libespnow.a │ ├── libhal.a │ ├── libjson.a │ ├── liblwip.a │ ├── libmain.a │ ├── libmesh.a │ ├── libnet80211.a │ ├── libphy.a │ ├── libpp.a │ ├── libpwm.a │ ├── libsmartconfig.a │ ├── libssl.a │ ├── libupgrade.a │ ├── libwpa.a │ └── libwps.a └── tools │ ├── gen_appbin.py │ ├── make_cert.py │ └── makefile.sh ├── handlers.py ├── node_main ├── circular_buffer.cpp ├── circular_buffer.h ├── eeprom.cpp ├── eeprom.h ├── esp8266.h ├── network.cpp ├── network.h ├── ota.cpp ├── ota.h ├── plugins.cpp ├── polarssl │ ├── aes.c │ ├── aes.h │ ├── aesni.h │ ├── base64.c │ ├── base64.h │ ├── bignum.c │ ├── bignum.h │ ├── bn_mul.h │ ├── check_config.h │ ├── config.h │ ├── md5.c │ ├── md5.h │ ├── padlock.h │ ├── platform.h │ ├── sha256.c │ └── sha256.h ├── user_config.h ├── user_main.cpp ├── wio.cpp └── wio.h ├── pre_build.py ├── repair ├── README.md ├── blank.bin ├── boot_v1.7.bin ├── esp_init_data_default_v08.bin ├── user1.bin └── user2.bin ├── requirements.txt ├── rpc_server ├── rpc_queue.h ├── rpc_server.cpp ├── rpc_server.h ├── rpc_stream.cpp └── rpc_stream.h ├── scan_drivers.py ├── server.py ├── server_lean.py ├── suli ├── suli2.cpp └── suli2.h ├── templates ├── resources.html └── test.html ├── update.sh ├── users_build └── local_user_00000000000000000000 │ ├── Main.cpp │ ├── connection_config.json │ ├── grove_oled_12864.cpp │ ├── grove_oled_12864.h │ ├── user1.bin │ └── user2.bin └── wio_server.conf /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: 'Close stale issues and PRs' 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '* 4 * * *' 7 | 8 | jobs: 9 | stale: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout repository 14 | uses: actions/checkout@v4 15 | 16 | - name: Checkout script repository 17 | uses: actions/checkout@v4 18 | with: 19 | repository: Seeed-Studio/sync-github-all-issues 20 | path: ci 21 | 22 | - name: Run script 23 | run: ./ci/tools/stale.sh 24 | env: 25 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | -------------------------------------------------------------------------------- /.github/workflows/sync_issues.yml: -------------------------------------------------------------------------------- 1 | name: Automate Issue Management 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | - edited 8 | - assigned 9 | - unassigned 10 | - labeled 11 | - unlabeled 12 | - reopened 13 | 14 | jobs: 15 | add_issue_to_project: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Add issue to GitHub Project 19 | uses: actions/add-to-project@v1.0.2 20 | with: 21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17 22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }} 23 | labeled: bug 24 | label-operator: NOT -------------------------------------------------------------------------------- /.github/workflows/sync_prs.yml: -------------------------------------------------------------------------------- 1 | name: Automate PR Management 2 | 3 | on: 4 | pull_request: 5 | types: [opened, reopened] 6 | 7 | jobs: 8 | add_to_project: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Checkout repository 13 | uses: actions/checkout@v4 14 | 15 | - name: Checkout script repository 16 | uses: actions/checkout@v4 17 | with: 18 | repository: Seeed-Studio/sync-github-all-issues 19 | path: ci 20 | 21 | - name: Run script 22 | run: ./ci/tools/addPr2Project.sh 23 | env: 24 | PROJECT_ID: "17" 25 | URL: ${{ github.event.pull_request.html_url }} 26 | GITHUB_TOKEN: ${{ secrets.PR_ASSEMBLE }} 27 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "grove_drivers"] 2 | path = grove_drivers 3 | url = https://github.com/Seeed-Studio/Grove_Drivers_for_Wio 4 | branch = master 5 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:2.7-buster 2 | 3 | #install required packages 4 | RUN apt-get update && \ 5 | apt-get install -qqy wget openssl python2.7-dev python-pip vim git 6 | 7 | #get the toolchain 8 | WORKDIR /opt 9 | RUN dpkg --print-architecture 10 | RUN /bin/bash -c "if dpkg --print-architecture | grep -q -e x86 -e amd ; then \ 11 | wget -O xtensa.tar.gz https://github.com/esp8266/Arduino/releases/download/2.3.0/linux64-xtensa-lx106-elf-gb404fb9.tgz; else \ 12 | wget -O xtensa.tar.gz https://github.com/esp8266/Arduino/releases/download/2.3.0/linuxarm-xtensa-lx106-elf-g46f160f-2.tar.gz; \ 13 | ln -sf /lib/arm-linux-gnueabi/ld-2.24.so /lib/ld-linux-armhf.so.3; fi" 14 | RUN tar -zxvf xtensa.tar.gz 15 | ENV PATH="${PATH}:opt/xtensa-lx106-elf/bin" 16 | 17 | COPY requirements.txt . 18 | RUN pip install -r requirements.txt 19 | 20 | #add the files into image 21 | RUN mkdir -p /root/wio 22 | WORKDIR /root/wio 23 | COPY . /root/wio 24 | #this is for marina.io builder 25 | RUN git submodule init || true 26 | RUN git submodule update || true 27 | RUN python ./scan_drivers.py 28 | RUN mv ./update.sh ../update.sh 29 | RUN chmod a+x ../update.sh 30 | 31 | #expose ports 32 | EXPOSE 8000 8001 8080 8081 33 | 34 | CMD python server.py 35 | 36 | -------------------------------------------------------------------------------- /Main.cpp.template: -------------------------------------------------------------------------------- 1 | #include "wio.h" 2 | #include "suli2.h" 3 | #include "Main.h" 4 | 5 | void setup() 6 | { 7 | } 8 | 9 | void loop() 10 | { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Wio Link 2 | 3 | 4 | 5 | ![](https://ksr-ugc.imgix.net/assets/004/976/751/7d273f1694c9c37b446ae820ea49c92a_original.jpg?v=1448431948&w=680&fit=max&auto=format&q=92&s=d0c984a9f958d807035d12c045619660) 6 | 7 | ## Introduction 8 | Wio Link is designed to simplify your IoT development. It is an ESP8266 based Wi-Fi development board for you to create IoT applications with open-source, plug and play electronics, mobile APPs and RESTful APIs.The key feature of this project is that users never need to program one line of code before he get all the Grove modules into Web of Things. 9 | 10 | Features: 11 | 12 | * Totally open sourced for both software and hardware 13 | * No need microcontroller programming 14 | * Config with GUI 15 | * Web of Things for hundreds of Grove modules (covering most IOT application domains) 16 | * WiFi enabled with ESP8266 which is not expensive to have 17 | * Security enhenced (AES for session between node & server, https for API calls) 18 | * RESTful APIs for application 19 | * Lightweighted and open sourced broker server based on Tornado 20 | * Deploy private server with Docker 21 | 22 | 23 | [Video: 3 Steps. 5 Minutes. Build IoT Device.](https://www.youtube.com/watch?v=P_SO_a6X-y0#action=share) 24 | 25 | 26 | ## About the Server 27 | 28 | Currently we have two sandbox servers - one for international users while another for users inside China. Due to the (G)(F)(W), users in China mainland can not access the international server smoothly. There're options in the App to select the server. 29 | 30 | The sandbox servers are free to use, but we can't guarantee the quality of the service persists good if the amount of connections becomes large. As the project is open sourced, we recommend users deploy their own server for private application. The server can be a local server or a VPS, even can be a lean computer like Raspberry Pi. See next section "Documentation" for the deployment guide. []() 31 | 32 | 33 | 34 | ## Documentation 35 | 36 | * [API Documentation](https://github.com/Seeed-Studio/Wio_Link/wiki/API%20Documentation) 37 | * [Server Deployment Guide](https://github.com/Seeed-Studio/Wio_Link/wiki/Server%20Deployment%20Guide) 38 | * [Advanced User Guide](https://github.com/Seeed-Studio/Wio_Link/wiki/Advanced%20User%20Guide) 39 | 40 | 41 | ## How to write module driver for Wio Link? 42 | 43 | A compatible module driver can be scanned by the server and be integrated into the online compilation service. Users can develop driver for their own modules. The low level of this project is based on the esp8266 Arduino project. Arduino SDK functions can be called in the drivers. 44 | 45 | The only difference between writing a Wio Link compatible driver and writing an Arduino compatible driver is that, you need to follow some rules to write the header file. It is for the scanning script to process it correctly. Please move to this [guide](https://github.com/Seeed-Studio/Wio_Link/wiki/How-to-write-module-driver-for-Wio-Link%3F) to see the rules. 46 | 47 | Users can pull request to [this github repo](https://github.com/Seeed-Studio/Grove_Drivers_for_Wio) to integrate the developed driver into the online compiling system, and at the same time into the mobile App. SEEED's staff will test the merged driver. If it's written correctly, we will accept the pull request and update the web services to let users use this module. For advanced users, we recommend to deploy a self server, to add 3rd party drivers immediately. 48 | 49 | ## License 50 | 51 | This project is developed by Jack Shao() for seeed studio. 52 | 53 | This project refers to: 54 | 55 | ESP8266_Arduino, mbed ssl, Espressif SDK, Tornado, PyYaml, PyJWT, pycrypto 56 | 57 | Thank them very much. 58 | 59 | 60 | The code written in this project is licensed under the [GNU GPL v3 License](http://www.gnu.org/licenses/gpl-3.0.en.html). 61 | 62 | [![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/Wio_Link)](https://github.com/igrigorik/ga-beacon) -------------------------------------------------------------------------------- /alert_database.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE nodes RENAME TO sqlitestudio_temp_table; 2 | 3 | CREATE TABLE nodes (node_id VARCHAR (120), user_id VARCHAR (120), node_sn VARCHAR (120), name VARCHAR (256), private_key VARCHAR (120), dataxserver VARCHAR (1024), board VARCHAR (256)); 4 | 5 | INSERT INTO nodes (node_id, user_id, node_sn, name, private_key, dataxserver, board) SELECT node_id, user_id, node_sn, name, private_key, dataxserver, board FROM sqlitestudio_temp_table; 6 | 7 | DROP TABLE sqlitestudio_temp_table; 8 | 9 | CREATE INDEX private_key_index ON nodes (private_key); 10 | 11 | 12 | 13 | ALTER TABLE resources RENAME TO sqlitestudio_temp_table; 14 | 15 | CREATE TABLE resources (res_id INTEGER PRIMARY KEY AUTOINCREMENT, node_id VARCHAR (120), chksum_config VARCHAR (120), chksum_dbjson VARCHAR (120), render_content TEXT); 16 | 17 | INSERT INTO resources (res_id, node_id, chksum_config, chksum_dbjson, render_content) SELECT res_id, node_id, chksum_config, chksum_dbjson, render_content FROM sqlitestudio_temp_table; 18 | 19 | DROP TABLE sqlitestudio_temp_table; 20 | 21 | CREATE INDEX node_id_index ON resources (node_id); 22 | 23 | 24 | 25 | ALTER TABLE users RENAME TO sqlitestudio_temp_table; 26 | 27 | CREATE TABLE users (user_id VARCHAR (120), email VARCHAR (256), pwd VARCHAR (256), token VARCHAR (120), ext_bind_id VARCHAR (120), ext_bind_region VARCHAR (120), created_at DATETIME); 28 | 29 | INSERT INTO users (user_id, email, pwd, token, ext_bind_id, ext_bind_region, created_at) SELECT user_id, email, pwd, token, ext_bind_id, ext_bind_region, created_at FROM sqlitestudio_temp_table; 30 | 31 | DROP TABLE sqlitestudio_temp_table; 32 | 33 | CREATE INDEX token_index ON users (token); 34 | 35 | -------------------------------------------------------------------------------- /boards.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "board_name": "Wio Link v1.0", 4 | "board_vendor": "seeedstudio", 5 | "board_flash_map": 6, 6 | "board_flash_spi_speed": 40, 7 | "board_flash_spi_mode": "QIO", 8 | "board_builtin": 9 | { 10 | "FUNCTION_KEY": 0, 11 | "STATUS_LED": 2, 12 | "GROVE_POWER_SWITCH": 15 13 | }, 14 | "interfaces": 15 | { 16 | "D0": { "type": "GPIO", "pin": 14 }, 17 | "D1": { "type": "GPIO", "pin": 12 }, 18 | "D2": { "type": "GPIO", "pin": 13 }, 19 | "A0": { "type": "ANALOG", "pin": 17 }, 20 | "I2C0": { "type": "I2C", "pinsda": 4, "pinscl": 5 }, 21 | "UART0": { "type": "UART", "pintx": 1, "pinrx": 3 } 22 | } 23 | }, 24 | { 25 | "board_name": "Wio Node v1.0", 26 | "board_vendor": "seeedstudio", 27 | "board_flash_map": 6, 28 | "board_flash_spi_speed": 40, 29 | "board_flash_spi_mode": "QIO", 30 | "board_builtin": 31 | { 32 | "FUNCTION_KEY": 0, 33 | "STATUS_LED": 2, 34 | "GROVE_POWER_SWITCH": 15 35 | }, 36 | "interfaces": 37 | { 38 | "D0": { "type": "GPIO", "pin": 3 }, 39 | "D1": { "type": "GPIO", "pin": 5 }, 40 | "A0": { "type": "ANALOG", "pin": 17 }, 41 | "I2C0": { "type": "I2C", "pinsda": 1, "pinscl": 3 }, 42 | "I2C1": { "type": "I2C", "pinsda": 4, "pinscl": 5 }, 43 | "UART0": { "type": "UART", "pintx": 1, "pinrx": 3 } 44 | } 45 | } 46 | ] 47 | -------------------------------------------------------------------------------- /cache.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 Seeed 2 | # Author: Jack Shao (jack.shaoxg@gmail.com) 3 | # 4 | # Expiring in-memory cache module 5 | # 6 | 7 | from collections import OrderedDict 8 | from time import time 9 | 10 | from tornado import ioloop 11 | from tornado.log import * 12 | 13 | 14 | class CacheException(Exception): 15 | """ 16 | Generic cache exception 17 | """ 18 | pass 19 | 20 | 21 | class CachedObject(object): 22 | def __init__(self, name, obj, ttl): 23 | """ 24 | Initializes a new cached object 25 | 26 | Args: 27 | name (str): Human readable name for the cached entry 28 | obj (type): Object to be cached 29 | ttl (int): The TTL in seconds for the cached object 30 | 31 | """ 32 | self.hits = 0 33 | self.name = name 34 | self.obj = obj 35 | self.ttl = ttl 36 | self.timestamp = time() 37 | 38 | 39 | class CacheInventory(object): 40 | """ 41 | Inventory for cached objects 42 | 43 | """ 44 | 45 | def __init__(self, maxsize=0, housekeeping=0): 46 | """ 47 | Initializes a new cache inventory 48 | 49 | Args: 50 | maxsize (int): Upperbound limit on the number of items 51 | that will be stored in the cache inventory 52 | housekeeping (int): Time in seconds to perform periodic cache housekeeping 53 | 54 | """ 55 | if maxsize < 0: 56 | raise CacheException('Cache inventory size cannot be negative') 57 | 58 | if housekeeping < 0: 59 | raise CacheException('Cache housekeeping period cannot be negative') 60 | 61 | self._cache = OrderedDict() 62 | self.maxsize = maxsize 63 | self.housekeeping = housekeeping 64 | 65 | if self.housekeeping > 0: 66 | self._timer = ioloop.PeriodicCallback(self.housekeeper, self.housekeeping * 1000) 67 | self._timer.start() 68 | 69 | def __len__(self): 70 | return len(self._cache) 71 | 72 | def __contains__(self, key): 73 | if key not in self._cache: 74 | return False 75 | 76 | item = self._cache[key] 77 | if self._has_expired(item): 78 | return False 79 | return True 80 | 81 | def _has_expired(self, item): 82 | """ 83 | Checks if a cached item has expired and removes it if needed 84 | 85 | If the upperbound limit has been reached then the last item 86 | is being removed from the inventory. 87 | 88 | Args: 89 | item (CachedObject): A cached object to lookup 90 | 91 | """ 92 | if item.ttl == 0: 93 | return False 94 | if time() > item.timestamp + item.ttl: 95 | gen_log.debug( 96 | 'Object %s has expired and will be removed from cache [hits %d]', 97 | item.name, 98 | item.hits 99 | ) 100 | self._cache.pop(item.name) 101 | return True 102 | return False 103 | 104 | def add(self, key, obj, ttl=0): 105 | """ 106 | Add an item to the cache inventory 107 | 108 | Args: 109 | obj (CachedObject): A CachedObject instance to be added 110 | 111 | Raises: 112 | CacheException 113 | 114 | """ 115 | item = CachedObject(key, obj, ttl) 116 | 117 | if self.maxsize > 0 and len(self._cache) == self.maxsize: 118 | popped = self._cache.popitem(last=False) 119 | gen_log.debug('Cache maxsize reached, removing %s [hits %d]', popped.name, popped.hits) 120 | 121 | gen_log.debug('Caching object %s [ttl: %d seconds]', item.name, item.ttl) 122 | self._cache[item.name] = item 123 | 124 | def get(self, key): 125 | """ 126 | Retrieve an object from the cache inventory 127 | 128 | Args: 129 | key (str): Name of the cache item to retrieve 130 | 131 | Returns: 132 | The cached object if found, None otherwise 133 | 134 | """ 135 | if key not in self._cache: 136 | return None 137 | 138 | item = self._cache[key] 139 | if self._has_expired(item): 140 | return None 141 | 142 | item.hits += 1 143 | gen_log.debug( 144 | 'Returning object %s from cache [hits %d]', 145 | item.name, 146 | item.hits 147 | ) 148 | 149 | return item.obj 150 | 151 | def housekeeper(self): 152 | """ 153 | Remove expired entries from the cache on regular basis 154 | 155 | """ 156 | total = len(self._cache) 157 | expired = 0 158 | for name, item in self._cache.items(): 159 | if self._has_expired(item): 160 | expired += 1 161 | gen_log.debug('Cache housekeeper completed [%d total] [%d removed]', total, expired) 162 | 163 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # Set the URL base which will be displayed in the resource page. 4 | # For example: 5 | # vhost_url_base = 'https://192.168.18.18' 6 | # vhost_url_base = 'https://my-domain.com' 7 | # If set to empty or None, 'https://IP-address-of-your-server' will be used. 8 | vhost_url_base = os.environ.get('WIO_VHOST_URL_BASE', '') 9 | 10 | 11 | ############################### 12 | # Set ALWAYS_BUILD_FROM_SRC to True to enable the building always from source code 13 | # It's useful when under dev stage, to figure out the newly developed code correct or not 14 | ALWAYS_BUILD_FROM_SRC = False 15 | 16 | 17 | 18 | ############################### 19 | # Set the smtp server which is used to send the password retreive email 20 | smtp_server = 'smtp.sendgrid.net' 21 | smtp_user = 'yours' 22 | smtp_pwd = 'yours' 23 | 24 | 25 | ############################### 26 | # Enable tornado's auto reload 27 | auto_reload_for_debug = False 28 | 29 | 30 | ############################### 31 | # The secrect for external user login 32 | ext_user_secret = 'secret' 33 | 34 | -------------------------------------------------------------------------------- /database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/database.db -------------------------------------------------------------------------------- /esp8266_arduino/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef client_h 21 | #define client_h 22 | #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client: public Stream { 27 | 28 | public: 29 | virtual int connect(IPAddress ip, uint16_t port) =0; 30 | virtual int connect(const char *host, uint16_t port) =0; 31 | virtual size_t write(uint8_t) =0; 32 | virtual size_t write(const uint8_t *buf, size_t size) =0; 33 | virtual int available() = 0; 34 | virtual int read() = 0; 35 | virtual int read(uint8_t *buf, size_t size) = 0; 36 | virtual int peek() = 0; 37 | virtual void flush() = 0; 38 | virtual void stop() = 0; 39 | virtual uint8_t connected() = 0; 40 | virtual operator bool() = 0; 41 | protected: 42 | uint8_t* rawIPAddress(IPAddress& addr) { 43 | return addr.raw_address(); 44 | } 45 | ; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /esp8266_arduino/Esp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Esp.h - ESP8266-specific APIs 3 | Copyright (c) 2015 Ivan Grokhotkov. All rights reserved. 4 | This file is part of the esp8266 core for Arduino environment. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef ESP_H 22 | #define ESP_H 23 | /** 24 | * AVR macros for WDT managment 25 | */ 26 | typedef enum { 27 | WDTO_0MS = 0, //!< WDTO_0MS 28 | WDTO_15MS = 15, //!< WDTO_15MS 29 | WDTO_30MS = 30, //!< WDTO_30MS 30 | WDTO_60MS = 60, //!< WDTO_60MS 31 | WDTO_120MS = 120, //!< WDTO_120MS 32 | WDTO_250MS = 250, //!< WDTO_250MS 33 | WDTO_500MS = 500, //!< WDTO_500MS 34 | WDTO_1S = 1000,//!< WDTO_1S 35 | WDTO_2S = 2000,//!< WDTO_2S 36 | WDTO_4S = 4000,//!< WDTO_4S 37 | WDTO_8S = 8000 //!< WDTO_8S 38 | } WDTO_t; 39 | 40 | 41 | #define wdt_enable(time) ESP.wdtEnable(time) 42 | #define wdt_disable() ESP.wdtDisable() 43 | #define wdt_reset() ESP.wdtFeed() 44 | 45 | #define cli() ets_intr_lock() // IRQ Disable 46 | #define sei() ets_intr_unlock() // IRQ Enable 47 | 48 | enum WakeMode { 49 | WAKE_RF_DEFAULT = 0, // RF_CAL or not after deep-sleep wake up, depends on init data byte 108. 50 | WAKE_RFCAL = 1, // RF_CAL after deep-sleep wake up, there will be large current. 51 | WAKE_NO_RFCAL = 2, // no RF_CAL after deep-sleep wake up, there will only be small current. 52 | WAKE_RF_DISABLED = 4 // disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current. 53 | }; 54 | 55 | typedef enum { 56 | FM_QIO = 0x00, 57 | FM_QOUT = 0x01, 58 | FM_DIO = 0x02, 59 | FM_DOUT = 0x03, 60 | FM_UNKNOWN = 0xff 61 | } FlashMode_t; 62 | 63 | class EspClass { 64 | public: 65 | EspClass(); 66 | 67 | // TODO: figure out how to set WDT timeout 68 | void wdtEnable(uint32_t timeout_ms = 0); 69 | // note: setting the timeout value is not implemented at the moment 70 | void wdtEnable(WDTO_t timeout_ms = WDTO_0MS); 71 | 72 | void wdtDisable(void); 73 | void wdtFeed(void); 74 | 75 | void deepSleep(uint32_t time_us, WakeMode mode = WAKE_RF_DEFAULT); 76 | 77 | void reset(void); 78 | void restart(void); 79 | 80 | uint16_t getVcc(void); 81 | uint32_t getFreeHeap(void); 82 | 83 | uint32_t getChipId(void); 84 | 85 | const char * getSdkVersion(void); 86 | 87 | uint8_t getBootVersion(void); 88 | uint8_t getBootMode(void); 89 | 90 | uint8_t getCpuFreqMHz(void); 91 | 92 | uint32_t getFlashChipId(void); 93 | //gets the actual chip size based on the flash id 94 | uint32_t getFlashChipRealSize(void); 95 | //gets the size of the flash as set by the compiler 96 | uint32_t getFlashChipSize(void); 97 | uint32_t getFlashChipSpeed(void); 98 | FlashMode_t getFlashChipMode(void); 99 | uint32_t getFlashChipSizeByChipId(void); 100 | 101 | inline uint32_t getCycleCount(void); 102 | }; 103 | 104 | uint32_t EspClass::getCycleCount(void) 105 | { 106 | uint32_t ccount; 107 | __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); 108 | return ccount; 109 | } 110 | 111 | extern EspClass ESP; 112 | 113 | #endif //ESP_H 114 | -------------------------------------------------------------------------------- /esp8266_arduino/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 28 September 2010 by Mark Sproul 20 | Modified 14 August 2012 by Alarus 21 | Modified 3 December 2013 by Matthijs Kooijman 22 | Modified 18 December 2014 by Ivan Grokhotkov (esp8266 platform support) 23 | Modified 31 March 2015 by Markus Sattler (rewrite the code for UART0 + UART1 support in ESP8266) 24 | Modified 25 April 2015 by Thomas Flayols (add configuration different from 8N1 in ESP8266) 25 | */ 26 | 27 | #ifndef HardwareSerial_h 28 | #define HardwareSerial_h 29 | 30 | #include 31 | 32 | #include "Stream.h" 33 | 34 | #define SERIAL_TX_BUFFER_SIZE 256 35 | #define SERIAL_RX_BUFFER_SIZE 256 36 | 37 | // Define config for Serial.begin(baud, config); 38 | #define SERIAL_5N1 0x10 39 | #define SERIAL_6N1 0x14 40 | #define SERIAL_7N1 0x18 41 | #define SERIAL_8N1 0x1c 42 | #define SERIAL_5N2 0x30 43 | #define SERIAL_6N2 0x34 44 | #define SERIAL_7N2 0x38 45 | #define SERIAL_8N2 0x3c 46 | #define SERIAL_5E1 0x12 47 | #define SERIAL_6E1 0x16 48 | #define SERIAL_7E1 0x1a 49 | #define SERIAL_8E1 0x1e 50 | #define SERIAL_5E2 0x32 51 | #define SERIAL_6E2 0x36 52 | #define SERIAL_7E2 0x3a 53 | #define SERIAL_8E2 0x3e 54 | #define SERIAL_5O1 0x13 55 | #define SERIAL_6O1 0x17 56 | #define SERIAL_7O1 0x1b 57 | #define SERIAL_8O1 0x1f 58 | #define SERIAL_5O2 0x33 59 | #define SERIAL_6O2 0x37 60 | #define SERIAL_7O2 0x3b 61 | #define SERIAL_8O2 0x3f 62 | 63 | #define SERIAL_FULL 0 64 | #define SERIAL_RX_ONLY 1 65 | #define SERIAL_TX_ONLY 2 66 | 67 | class cbuf; 68 | 69 | struct uart_; 70 | typedef struct uart_ uart_t; 71 | 72 | class HardwareSerial: public Stream { 73 | public: 74 | HardwareSerial(int uart_nr); 75 | 76 | void begin(unsigned long baud) { 77 | begin(baud, SERIAL_8N1, SERIAL_FULL); 78 | } 79 | void begin(unsigned long baud, uint8_t config) { 80 | begin(baud, config, SERIAL_FULL); 81 | } 82 | void begin(unsigned long, uint8_t, uint8_t); 83 | void end(); 84 | void swap(); //toggle between use of GPIO13/GPIO15 or GPIO3/GPIO1 as RX and TX 85 | int available(void) override; 86 | int peek(void) override; 87 | int read(void) override; 88 | int availableForWrite(void); 89 | void flush(void) override; 90 | size_t write(uint8_t) override; 91 | inline size_t write(unsigned long n) { 92 | return write((uint8_t) n); 93 | } 94 | inline size_t write(long n) { 95 | return write((uint8_t) n); 96 | } 97 | inline size_t write(unsigned int n) { 98 | return write((uint8_t) n); 99 | } 100 | inline size_t write(int n) { 101 | return write((uint8_t) n); 102 | } 103 | using Print::write; // pull in write(str) and write(buf, size) from Print 104 | operator bool() const; 105 | 106 | void setDebugOutput(bool); 107 | bool isTxEnabled(void); 108 | bool isRxEnabled(void); 109 | 110 | protected: 111 | friend void uart_interrupt_handler(uart_t* uart); 112 | void _rx_complete_irq(char c); 113 | void _tx_empty_irq(void); 114 | 115 | protected: 116 | int _uart_nr; 117 | uart_t* _uart; 118 | cbuf* _tx_buffer; 119 | cbuf* _rx_buffer; 120 | bool _written; 121 | }; 122 | 123 | extern HardwareSerial Serial; 124 | extern HardwareSerial Serial1; 125 | 126 | #endif 127 | 128 | -------------------------------------------------------------------------------- /esp8266_arduino/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Print_h 21 | #define Print_h 22 | 23 | #include 24 | #include 25 | 26 | #include "WString.h" 27 | #include "Printable.h" 28 | 29 | #define DEC 10 30 | #define HEX 16 31 | #define OCT 8 32 | #define BIN 2 33 | 34 | class Print { 35 | private: 36 | int write_error; 37 | size_t printNumber(unsigned long, uint8_t); 38 | size_t printFloat(double, uint8_t); 39 | protected: 40 | void setWriteError(int err = 1) { 41 | write_error = err; 42 | } 43 | public: 44 | Print() : 45 | write_error(0) { 46 | } 47 | 48 | int getWriteError() { 49 | return write_error; 50 | } 51 | void clearWriteError() { 52 | setWriteError(0); 53 | } 54 | 55 | virtual size_t write(uint8_t) = 0; 56 | size_t write(const char *str) { 57 | if(str == NULL) 58 | return 0; 59 | return write((const uint8_t *) str, strlen(str)); 60 | } 61 | virtual size_t write(const uint8_t *buffer, size_t size); 62 | size_t write(const char *buffer, size_t size) { 63 | return write((const uint8_t *) buffer, size); 64 | } 65 | 66 | size_t printf(const char * format, ...); 67 | size_t print(const __FlashStringHelper *); 68 | size_t print(const String &); 69 | size_t print(const char[]); 70 | size_t print(char); 71 | size_t print(unsigned char, int = DEC); 72 | size_t print(int, int = DEC); 73 | size_t print(unsigned int, int = DEC); 74 | size_t print(long, int = DEC); 75 | size_t print(unsigned long, int = DEC); 76 | size_t print(double, int = 2); 77 | size_t print(const Printable&); 78 | 79 | size_t println(const __FlashStringHelper *); 80 | size_t println(const String &s); 81 | size_t println(const char[]); 82 | size_t println(char); 83 | size_t println(unsigned char, int = DEC); 84 | size_t println(int, int = DEC); 85 | size_t println(unsigned int, int = DEC); 86 | size_t println(long, int = DEC); 87 | size_t println(unsigned long, int = DEC); 88 | size_t println(double, int = 2); 89 | size_t println(const Printable&); 90 | size_t println(void); 91 | }; 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /esp8266_arduino/Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Printable_h 21 | #define Printable_h 22 | 23 | #include 24 | 25 | class Print; 26 | 27 | /** The Printable class provides a way for new classes to allow themselves to be printed. 28 | By deriving from Printable and implementing the printTo method, it will then be possible 29 | for users to print out instances of this class by passing them into the usual 30 | Print::print and Print::println methods. 31 | */ 32 | 33 | class Printable { 34 | public: 35 | virtual size_t printTo(Print& p) const = 0; 36 | }; 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /esp8266_arduino/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | Stream.h - base class for character-based streams. 3 | Copyright (c) 2010 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | parsing functions based on TextFinder library by Michael Margolis 20 | */ 21 | 22 | #ifndef Stream_h 23 | #define Stream_h 24 | 25 | #include 26 | #include "Print.h" 27 | 28 | // compatability macros for testing 29 | /* 30 | #define getInt() parseInt() 31 | #define getInt(skipChar) parseInt(skipchar) 32 | #define getFloat() parseFloat() 33 | #define getFloat(skipChar) parseFloat(skipChar) 34 | #define getString( pre_string, post_string, buffer, length) 35 | readBytesBetween( pre_string, terminator, buffer, length) 36 | */ 37 | 38 | class Stream: public Print { 39 | protected: 40 | unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read 41 | unsigned long _startMillis; // used for timeout measurement 42 | int timedRead(); // private method to read stream with timeout 43 | int timedPeek(); // private method to peek stream with timeout 44 | int peekNextDigit(); // returns the next numeric digit in the stream or -1 if timeout 45 | 46 | public: 47 | virtual int available() = 0; 48 | virtual int read() = 0; 49 | virtual int peek() = 0; 50 | virtual void flush() = 0; 51 | 52 | Stream() { 53 | _timeout = 1000; 54 | } 55 | 56 | // parsing methods 57 | 58 | void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second 59 | 60 | bool find(const char *target); // reads data from the stream until the target string is found 61 | bool find(uint8_t *target) { 62 | return find((char *) target); 63 | } 64 | // returns true if target string is found, false if timed out (see setTimeout) 65 | 66 | bool find(const char *target, size_t length); // reads data from the stream until the target string of given length is found 67 | bool find(const uint8_t *target, size_t length) { 68 | return find((char *) target, length); 69 | } 70 | // returns true if target string is found, false if timed out 71 | 72 | bool findUntil(const char *target, const char *terminator); // as find but search ends if the terminator string is found 73 | bool findUntil(const uint8_t *target, const char *terminator) { 74 | return findUntil((char *) target, terminator); 75 | } 76 | 77 | bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); // as above but search ends if the terminate string is found 78 | bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) { 79 | return findUntil((char *) target, targetLen, terminate, termLen); 80 | } 81 | 82 | long parseInt(); // returns the first valid (long) integer value from the current position. 83 | // initial characters that are not digits (or the minus sign) are skipped 84 | // integer is terminated by the first character that is not a digit. 85 | 86 | float parseFloat(); // float version of parseInt 87 | 88 | size_t readBytes(char *buffer, size_t length); // read chars from stream into buffer 89 | size_t readBytes(uint8_t *buffer, size_t length) { 90 | return readBytes((char *) buffer, length); 91 | } 92 | // terminates if length characters have been read or timeout (see setTimeout) 93 | // returns the number of characters placed in the buffer (0 means no valid data found) 94 | 95 | size_t readBytesUntil(char terminator, char *buffer, size_t length); // as readBytes with terminator character 96 | size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) { 97 | return readBytesUntil(terminator, (char *) buffer, length); 98 | } 99 | // terminates if length characters have been read, timeout, or if the terminator character detected 100 | // returns the number of characters placed in the buffer (0 means no valid data found) 101 | 102 | // Arduino String functions to be added here 103 | String readString(); 104 | String readStringUntil(char terminator); 105 | 106 | protected: 107 | long parseInt(char skipChar); // as above but the given skipChar is ignored 108 | // as above but the given skipChar is ignored 109 | // this allows format characters (typically commas) in values to be ignored 110 | 111 | float parseFloat(char skipChar); // as above but the given skipChar is ignored 112 | }; 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /esp8266_arduino/WCharacter.h: -------------------------------------------------------------------------------- 1 | /* 2 | WCharacter.h - Character utility functions for Wiring & Arduino 3 | Copyright (c) 2010 Hernando Barragan. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Character_h 21 | #define Character_h 22 | 23 | #include 24 | #define isascii(__c) ((unsigned)(__c)<=0177) 25 | #define toascii(__c) ((__c)&0177) 26 | 27 | // WCharacter.h prototypes 28 | inline boolean isAlphaNumeric(int c) __attribute__((always_inline)); 29 | inline boolean isAlpha(int c) __attribute__((always_inline)); 30 | inline boolean isAscii(int c) __attribute__((always_inline)); 31 | inline boolean isWhitespace(int c) __attribute__((always_inline)); 32 | inline boolean isControl(int c) __attribute__((always_inline)); 33 | inline boolean isDigit(int c) __attribute__((always_inline)); 34 | inline boolean isGraph(int c) __attribute__((always_inline)); 35 | inline boolean isLowerCase(int c) __attribute__((always_inline)); 36 | inline boolean isPrintable(int c) __attribute__((always_inline)); 37 | inline boolean isPunct(int c) __attribute__((always_inline)); 38 | inline boolean isSpace(int c) __attribute__((always_inline)); 39 | inline boolean isUpperCase(int c) __attribute__((always_inline)); 40 | inline boolean isHexadecimalDigit(int c) __attribute__((always_inline)); 41 | inline int toAscii(int c) __attribute__((always_inline)); 42 | inline int toLowerCase(int c) __attribute__((always_inline)); 43 | inline int toUpperCase(int c) __attribute__((always_inline)); 44 | 45 | // Checks for an alphanumeric character. 46 | // It is equivalent to (isalpha(c) || isdigit(c)). 47 | inline boolean isAlphaNumeric(int c) { 48 | return (isalnum(c) == 0 ? false : true); 49 | } 50 | 51 | // Checks for an alphabetic character. 52 | // It is equivalent to (isupper(c) || islower(c)). 53 | inline boolean isAlpha(int c) { 54 | return (isalpha(c) == 0 ? false : true); 55 | } 56 | 57 | // Checks whether c is a 7-bit unsigned char value 58 | // that fits into the ASCII character set. 59 | inline boolean isAscii(int c) { 60 | return ( isascii (c) == 0 ? false : true); 61 | } 62 | 63 | // Checks for a blank character, that is, a space or a tab. 64 | inline boolean isWhitespace(int c) { 65 | return (isblank(c) == 0 ? false : true); 66 | } 67 | 68 | // Checks for a control character. 69 | inline boolean isControl(int c) { 70 | return (iscntrl(c) == 0 ? false : true); 71 | } 72 | 73 | // Checks for a digit (0 through 9). 74 | inline boolean isDigit(int c) { 75 | return (isdigit(c) == 0 ? false : true); 76 | } 77 | 78 | // Checks for any printable character except space. 79 | inline boolean isGraph(int c) { 80 | return (isgraph(c) == 0 ? false : true); 81 | } 82 | 83 | // Checks for a lower-case character. 84 | inline boolean isLowerCase(int c) { 85 | return (islower(c) == 0 ? false : true); 86 | } 87 | 88 | // Checks for any printable character including space. 89 | inline boolean isPrintable(int c) { 90 | return (isprint(c) == 0 ? false : true); 91 | } 92 | 93 | // Checks for any printable character which is not a space 94 | // or an alphanumeric character. 95 | inline boolean isPunct(int c) { 96 | return (ispunct(c) == 0 ? false : true); 97 | } 98 | 99 | // Checks for white-space characters. For the avr-libc library, 100 | // these are: space, formfeed ('\f'), newline ('\n'), carriage 101 | // return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). 102 | inline boolean isSpace(int c) { 103 | return (isspace(c) == 0 ? false : true); 104 | } 105 | 106 | // Checks for an uppercase letter. 107 | inline boolean isUpperCase(int c) { 108 | return (isupper(c) == 0 ? false : true); 109 | } 110 | 111 | // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 112 | // 8 9 a b c d e f A B C D E F. 113 | inline boolean isHexadecimalDigit(int c) { 114 | return (isxdigit(c) == 0 ? false : true); 115 | } 116 | 117 | // Converts c to a 7-bit unsigned char value that fits into the 118 | // ASCII character set, by clearing the high-order bits. 119 | inline int toAscii(int c) { 120 | return toascii(c); 121 | } 122 | 123 | // Warning: 124 | // Many people will be unhappy if you use this function. 125 | // This function will convert accented letters into random 126 | // characters. 127 | 128 | // Converts the letter c to lower case, if possible. 129 | inline int toLowerCase(int c) { 130 | return tolower(c); 131 | } 132 | 133 | // Converts the letter c to upper case, if possible. 134 | inline int toUpperCase(int c) { 135 | return toupper(c); 136 | } 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /esp8266_arduino/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | $Id$ 24 | */ 25 | 26 | extern "C" { 27 | #include 28 | } 29 | 30 | void randomSeed(unsigned int seed) { 31 | if(seed != 0) { 32 | srand(seed); 33 | } 34 | } 35 | 36 | long random(long howbig) { 37 | if(howbig == 0) { 38 | return 0; 39 | } 40 | return rand() % howbig; 41 | } 42 | 43 | long random(long howsmall, long howbig) { 44 | if(howsmall >= howbig) { 45 | return howsmall; 46 | } 47 | long diff = howbig - howsmall; 48 | return random(diff) + howsmall; 49 | } 50 | 51 | long map(long x, long in_min, long in_max, long out_min, long out_max) { 52 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 53 | } 54 | 55 | unsigned int makeWord(unsigned int w) { 56 | return w; 57 | } 58 | 59 | unsigned int makeWord(unsigned char h, unsigned char l) { 60 | return (h << 8) | l; 61 | } 62 | -------------------------------------------------------------------------------- /esp8266_arduino/Wire.h: -------------------------------------------------------------------------------- 1 | /* 2 | TwoWire.h - TWI/I2C library for Arduino & Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts 20 | Modified December 2014 by Ivan Grokhotkov (ivan@esp8266.com) - esp8266 support 21 | Modified April 2015 by Hrsto Gochkov (ficeto@ficeto.com) - alternative esp8266 support 22 | */ 23 | 24 | #ifndef TwoWire_h 25 | #define TwoWire_h 26 | 27 | #include 28 | #include "Stream.h" 29 | 30 | 31 | 32 | #define BUFFER_LENGTH 32 33 | 34 | class TwoWire : public Stream 35 | { 36 | private: 37 | static uint8_t rxBuffer[]; 38 | static uint8_t rxBufferIndex; 39 | static uint8_t rxBufferLength; 40 | 41 | static uint8_t txAddress; 42 | static uint8_t txBuffer[]; 43 | static uint8_t txBufferIndex; 44 | static uint8_t txBufferLength; 45 | 46 | static uint8_t transmitting; 47 | static void (*user_onRequest)(void); 48 | static void (*user_onReceive)(int); 49 | static void onRequestService(void); 50 | static void onReceiveService(uint8_t*, int); 51 | public: 52 | TwoWire(); 53 | void begin(int sda, int scl); 54 | void pins(int sda, int scl) __attribute__((deprecated)); // use begin(sda, scl) in new code 55 | void begin(); 56 | void begin(uint8_t); 57 | void begin(int); 58 | void setClock(uint32_t); 59 | void beginTransmission(uint8_t); 60 | void beginTransmission(int); 61 | uint8_t endTransmission(void); 62 | uint8_t endTransmission(uint8_t); 63 | size_t requestFrom(uint8_t address, size_t size, bool sendStop); 64 | 65 | uint8_t requestFrom(uint8_t, uint8_t); 66 | uint8_t requestFrom(uint8_t, uint8_t, uint8_t); 67 | uint8_t requestFrom(int, int); 68 | uint8_t requestFrom(int, int, int); 69 | 70 | virtual size_t write(uint8_t); 71 | virtual size_t write(const uint8_t *, size_t); 72 | virtual int available(void); 73 | virtual int read(void); 74 | virtual int peek(void); 75 | virtual void flush(void); 76 | void onReceive( void (*)(int) ); 77 | void onRequest( void (*)(void) ); 78 | 79 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 80 | inline size_t write(long n) { return write((uint8_t)n); } 81 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 82 | inline size_t write(int n) { return write((uint8_t)n); } 83 | using Print::write; 84 | }; 85 | 86 | extern TwoWire Wire; 87 | 88 | #endif 89 | 90 | -------------------------------------------------------------------------------- /esp8266_arduino/abi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | extern "C" { 21 | #include "ets_sys.h" 22 | #include "os_type.h" 23 | #include "osapi.h" 24 | #include "mem.h" 25 | #include "user_interface.h" 26 | } 27 | 28 | void *operator new(size_t size) { 29 | size = ((size + 3) & ~((size_t)0x3)); 30 | return os_malloc(size); 31 | } 32 | 33 | void *operator new[](size_t size) { 34 | size = ((size + 3) & ~((size_t)0x3)); 35 | return os_malloc(size); 36 | } 37 | 38 | void operator delete(void * ptr) { 39 | os_free(ptr); 40 | } 41 | 42 | void operator delete[](void * ptr) { 43 | os_free(ptr); 44 | } 45 | 46 | extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__)); 47 | extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__)); 48 | 49 | void __cxa_pure_virtual(void) { 50 | abort(); 51 | } 52 | 53 | void __cxa_deleted_virtual(void) { 54 | abort(); 55 | } 56 | 57 | namespace std { 58 | void __throw_bad_function_call() { 59 | abort(); 60 | } 61 | } 62 | 63 | // TODO: rebuild windows toolchain to make this unnecessary: 64 | void* __dso_handle; 65 | 66 | -------------------------------------------------------------------------------- /esp8266_arduino/cbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | cbuf.h - Circular buffer implementation 3 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 4 | This file is part of the esp8266 core for Arduino environment. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef __cbuf_h 22 | #define __cbuf_h 23 | 24 | #include 25 | class cbuf { 26 | public: 27 | cbuf(size_t size) : 28 | _size(size), _buf(new char[size]), _bufend(_buf + size), _begin(_buf), _end(_begin) { 29 | } 30 | 31 | ~cbuf() { 32 | delete[] _buf; 33 | } 34 | 35 | size_t getSize() const { 36 | if(_end >= _begin) return _end - _begin; 37 | 38 | return _size - (_begin - _end); 39 | } 40 | 41 | size_t room() const { 42 | if(_end >= _begin) return _size - (_end - _begin) - 1; 43 | 44 | return _begin - _end - 1; 45 | } 46 | 47 | bool empty() const { 48 | return _begin == _end; 49 | } 50 | 51 | int peek() { 52 | if(_end == _begin) return -1; 53 | 54 | return static_cast(*_begin); 55 | } 56 | 57 | int read() { 58 | if(getSize() == 0) return -1; 59 | 60 | char result = *_begin; 61 | if(++_begin == _bufend) _begin = _buf; 62 | return static_cast(result); 63 | } 64 | 65 | size_t read(char* dst, size_t size) { 66 | size_t bytes_available = getSize(); 67 | size_t size_to_read = (size < bytes_available) ? size : bytes_available; 68 | size_t size_read = size_to_read; 69 | if((_end < _begin) && (size_to_read > (_bufend - _begin))) { //mod by jack 70 | size_t top_size = _bufend - _begin; 71 | if(top_size > 0) { 72 | memcpy(dst, _begin, top_size); 73 | } 74 | _begin = _buf; 75 | size_to_read -= top_size; 76 | dst += top_size; 77 | } 78 | if(size_to_read > 0) { 79 | memcpy(dst, _begin, size_to_read); 80 | _begin += size_to_read; 81 | } 82 | if(_begin == _bufend) _begin = _buf; 83 | return size_read; 84 | } 85 | 86 | size_t write(char c) { 87 | if(room() == 0) return 0; 88 | 89 | *_end = c; 90 | if(++_end == _bufend) _end = _buf; 91 | return 1; 92 | } 93 | 94 | size_t write(const char* src, size_t size) { 95 | size_t bytes_available = room(); 96 | size_t size_to_write = (size < bytes_available) ? size : bytes_available; 97 | size_t size_written = size_to_write; 98 | if((_end > _begin) && (size_to_write > (_bufend - _end))) { //mod by jack 99 | size_t top_size = _bufend - _end; 100 | if(top_size > 0) { 101 | memcpy(_end, src, top_size); 102 | } 103 | _end = _buf; 104 | size_to_write -= top_size; 105 | src += top_size; 106 | } 107 | if(size_to_write > 0) { 108 | memcpy(_end, src, size_to_write); 109 | _end += size_to_write; 110 | } 111 | if(_end == _bufend) _end = _buf; 112 | return size_written; 113 | } 114 | 115 | void flush() { 116 | _begin = _buf; 117 | _end = _buf; 118 | } 119 | 120 | private: 121 | size_t _size; 122 | char* _buf; 123 | char* _bufend; 124 | char* _begin; 125 | char* _end; 126 | }; 127 | 128 | #endif//__cbuf_h 129 | -------------------------------------------------------------------------------- /esp8266_arduino/cont.h: -------------------------------------------------------------------------------- 1 | /* 2 | cont.h - continuations support for Xtensa call0 ABI 3 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 4 | This file is part of the esp8266 core for Arduino environment. 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | You should have received a copy of the GNU Lesser General Public 14 | License along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | */ 17 | 18 | #ifndef CONT_H_ 19 | #define CONT_H_ 20 | 21 | #include 22 | 23 | #ifndef CONT_STACKSIZE 24 | #define CONT_STACKSIZE 4096 25 | #endif 26 | 27 | typedef struct cont_ { 28 | void (*pc_ret)(void); 29 | unsigned* sp_ret; 30 | 31 | void (*pc_yield)(void); 32 | unsigned* sp_yield; 33 | 34 | unsigned* stack_end; 35 | unsigned unused1; 36 | unsigned unused2; 37 | unsigned stack_guard1; 38 | 39 | unsigned stack[CONT_STACKSIZE / 4]; 40 | 41 | unsigned stack_guard2; 42 | unsigned* struct_start; 43 | } cont_t; 44 | 45 | // Initialize the cont_t structure before calling cont_run 46 | void cont_init(cont_t*); 47 | 48 | // Run function pfn in a separate stack, or continue execution 49 | // at the point where cont_yield was called 50 | void cont_run(cont_t*, void (*pfn)(void)); 51 | 52 | // Return to the point where cont_run was called, saving the 53 | // execution state (registers and stack) 54 | void cont_yield(cont_t*); 55 | 56 | // Check guard bytes around the stack. Return 0 in case everything is ok, 57 | // return 1 if guard bytes were overwritten. 58 | int cont_check(cont_t* cont); 59 | 60 | // Check if yield() may be called. Returns true if we are running inside 61 | // continuation stack 62 | bool cont_can_yield(cont_t* cont); 63 | 64 | #endif /* CONT_H_ */ 65 | -------------------------------------------------------------------------------- /esp8266_arduino/cont.s: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | cont.S - continuations support for Xtensa call0 ABI 4 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | .text 20 | .align 4 21 | .literal_position 22 | .global cont_yield 23 | .type cont_yield, @function 24 | cont_yield: 25 | /* a1: sp */ 26 | /* a2: void* cont_ctx */ 27 | /* adjust stack and save registers */ 28 | addi a1, a1, -24 29 | s32i a12, a1, 0 30 | s32i a13, a1, 4 31 | s32i a14, a1, 8 32 | s32i a15, a1, 12 33 | s32i a0, a1, 16 34 | s32i a2, a1, 20 35 | 36 | /* &cont_continue -> cont_ctx.pc_yield */ 37 | movi a3, cont_continue 38 | s32i a3, a2, 8 39 | /* sp -> cont_ctx.sp_yield */ 40 | s32i a1, a2, 12 41 | 42 | /* a0 <- cont_ctx.pc_ret */ 43 | l32i a0, a2, 0 44 | /* sp <- cont_ctx.sp_ret */ 45 | l32i a1, a2, 4 46 | jx a0 47 | 48 | cont_continue: 49 | l32i a12, a1, 0 50 | l32i a13, a1, 4 51 | l32i a14, a1, 8 52 | l32i a15, a1, 12 53 | l32i a0, a1, 16 54 | l32i a2, a1, 20 55 | addi a1, a1, 24 56 | ret 57 | .size cont_yield, . - cont_yield 58 | 59 | //////////////////////////////////////////////////// 60 | 61 | .text 62 | .align 4 63 | .literal_position 64 | .global cont_run 65 | .type cont_run, @function 66 | cont_run: 67 | /* a1: sp */ 68 | /* a2: void* cont_ctx */ 69 | /* a3: void (*pfn) */ 70 | 71 | /* adjust stack and save registers */ 72 | addi a1, a1, -20 73 | s32i a12, a1, 0 74 | s32i a13, a1, 4 75 | s32i a14, a1, 8 76 | s32i a15, a1, 12 77 | s32i a0, a1, 16 78 | 79 | /* cont_ret -> a4 -> cont_ctx.pc_ret*/ 80 | movi a4, cont_ret 81 | s32i a4, a2, 0 82 | /* sp -> cont_ctx.sp_ret */ 83 | s32i a1, a2, 4 84 | 85 | /* if cont_ctx.pc_yield != 0, goto cont_resume */ 86 | l32i a4, a2, 8 87 | bnez a4, cont_resume 88 | /* else */ 89 | /* set new stack*/ 90 | l32i a1, a2, 16; 91 | /* goto pfn */ 92 | movi a0, cont_norm 93 | jx a3 94 | 95 | cont_resume: 96 | /* a1 <- cont_ctx.sp_yield */ 97 | l32i a1, a2, 12 98 | /* reset yield flag, 0 -> cont_ctx.pc_yield */ 99 | movi a3, 0 100 | s32i a3, a2, 8 101 | /* jump to saved cont_ctx.pc_yield */ 102 | movi a0, cont_ret 103 | jx a4 104 | 105 | cont_norm: 106 | /* calculate pointer to cont_ctx.struct_start from sp */ 107 | l32i a2, a1, 4 108 | /* sp <- cont_ctx.sp_ret */ 109 | l32i a1, a2, 4 110 | /* 0 -> cont_ctx.pc_ret */ 111 | movi a4, 0 112 | s32i a4, a2, 0 113 | 114 | cont_ret: 115 | /* restore registers */ 116 | l32i a12, a1, 0 117 | l32i a13, a1, 4 118 | l32i a14, a1, 8 119 | l32i a15, a1, 12 120 | l32i a0, a1, 16 121 | /* adjust stack and return */ 122 | addi a1, a1, 20 123 | ret 124 | .size cont_run, . - cont_run 125 | -------------------------------------------------------------------------------- /esp8266_arduino/cont_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | cont_util.s - continuations support for Xtensa call0 ABI 3 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 4 | This file is part of the esp8266 core for Arduino environment. 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | You should have received a copy of the GNU Lesser General Public 14 | License along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | */ 17 | 18 | #include "cont.h" 19 | #include 20 | #include "ets_sys.h" 21 | 22 | 23 | #define CONT_STACKGUARD 0xfeefeffe 24 | 25 | void ICACHE_RAM_ATTR cont_init(cont_t* cont) { 26 | cont->stack_guard1 = CONT_STACKGUARD; 27 | cont->stack_guard2 = CONT_STACKGUARD; 28 | cont->stack_end = cont->stack + (sizeof(cont->stack) / 4); 29 | cont->struct_start = (unsigned*) cont; 30 | } 31 | 32 | int ICACHE_RAM_ATTR cont_check(cont_t* cont) { 33 | if(cont->stack_guard1 != CONT_STACKGUARD || cont->stack_guard2 != CONT_STACKGUARD) return 1; 34 | 35 | return 0; 36 | } 37 | 38 | bool ICACHE_RAM_ATTR cont_can_yield(cont_t* cont) { 39 | return !ETS_INTR_WITHINISR() && 40 | cont->pc_ret != 0 && cont->pc_yield == 0; 41 | } 42 | -------------------------------------------------------------------------------- /esp8266_arduino/core_esp8266_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | main.cpp - platform initialization and context switching 3 | emulation 4 | 5 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 6 | This file is part of the esp8266 core for Arduino environment. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | //This may be used to change user task stack size: 24 | //#define CONT_STACKSIZE 4096 25 | #include 26 | extern "C" { 27 | #include "ets_sys.h" 28 | #include "os_type.h" 29 | #include "osapi.h" 30 | #include "mem.h" 31 | #include "user_interface.h" 32 | #include "cont.h" 33 | } 34 | 35 | #define LOOP_TASK_PRIORITY 0 36 | #define LOOP_QUEUE_SIZE 1 37 | 38 | #define OPTIMISTIC_YIELD_TIME_US 16000 39 | 40 | int atexit(void (*func)()) { 41 | return 0; 42 | } 43 | 44 | extern "C" void ets_update_cpu_frequency(int freqmhz); 45 | void initVariant() __attribute__((weak)); 46 | void initVariant() { 47 | } 48 | 49 | void preloop_update_frequency() __attribute__((weak)); 50 | void preloop_update_frequency() { 51 | #if defined(F_CPU) && (F_CPU == 160000000L) 52 | REG_SET_BIT(0x3ff00014, BIT(0)); 53 | ets_update_cpu_frequency(160); 54 | #endif 55 | } 56 | 57 | /** 58 | * init cpp stuff 59 | */ 60 | extern void (*__init_array_start)(void); 61 | extern void (*__init_array_end)(void); 62 | void do_global_ctors(void) { 63 | void(**p)(void); 64 | for(p = &__init_array_start; p != &__init_array_end; ++p) (*p)(); 65 | } 66 | 67 | cont_t g_cont __attribute__ ((aligned (16))); 68 | static os_event_t g_loop_queue[LOOP_QUEUE_SIZE]; 69 | 70 | static uint32_t g_micros_at_task_start; 71 | 72 | extern "C" uint32_t esp_micros_at_task_start() { 73 | return g_micros_at_task_start; 74 | } 75 | 76 | extern "C" void abort() { 77 | do { 78 | *((int*)0) = 0; 79 | } while(true); 80 | } 81 | 82 | extern "C" void esp_yield() { 83 | if (cont_can_yield(&g_cont)) { 84 | cont_yield(&g_cont); 85 | } 86 | } 87 | 88 | extern "C" void esp_schedule() { 89 | system_os_post(LOOP_TASK_PRIORITY, 0, 0); 90 | } 91 | 92 | extern "C" void __yield() { 93 | if (cont_can_yield(&g_cont)) { 94 | esp_schedule(); 95 | esp_yield(); 96 | } 97 | else { 98 | abort(); 99 | } 100 | } 101 | 102 | extern "C" void yield(void) __attribute__ ((weak, alias("__yield"))); 103 | 104 | extern "C" void optimistic_yield(uint32_t interval_us) { 105 | if (cont_can_yield(&g_cont) && 106 | (system_get_time() - g_micros_at_task_start) > interval_us) 107 | { 108 | yield(); 109 | } 110 | } 111 | 112 | extern void wio_loop(); 113 | extern void wio_setup(); 114 | 115 | void loop_wrapper() { 116 | static bool setup_done = false; 117 | if(!setup_done) { 118 | wio_setup(); 119 | setup_done = true; 120 | } 121 | preloop_update_frequency(); 122 | wio_loop(); 123 | esp_schedule(); 124 | } 125 | 126 | void loop_task(os_event_t *events) { 127 | g_micros_at_task_start = system_get_time(); 128 | cont_run(&g_cont, &loop_wrapper); 129 | if(cont_check(&g_cont) != 0) { 130 | ets_printf("\r\nheap collided with sketch stack\r\n"); 131 | abort(); 132 | } 133 | } 134 | 135 | 136 | 137 | void init_done() { 138 | do_global_ctors(); 139 | esp_schedule(); 140 | } 141 | 142 | 143 | void arduino_init(void) { 144 | //uart_div_modify(0, UART_CLK_FREQ / (115200)); 145 | 146 | init(); //init wiring system: pins, timer1 147 | 148 | initVariant(); 149 | 150 | cont_init(&g_cont); 151 | 152 | system_os_task(loop_task, LOOP_TASK_PRIORITY, g_loop_queue, LOOP_QUEUE_SIZE); 153 | 154 | system_init_done_cb(&init_done); 155 | } 156 | 157 | 158 | -------------------------------------------------------------------------------- /esp8266_arduino/core_esp8266_timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | timer.c - Timer1 library for esp8266 3 | 4 | Copyright (c) 2015 Hristo Gochkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #include "wiring_private.h" 22 | #include "pins_arduino.h" 23 | 24 | #include "c_types.h" 25 | #include "ets_sys.h" 26 | 27 | // ------------------------------------------------------------------ - 28 | // timer 1 29 | 30 | static volatile timercallback timer1_user_cb = NULL; 31 | 32 | void ICACHE_RAM_ATTR timer1_isr_handler(void *para){ 33 | if ((T1C & ((1 << TCAR) | (1 << TCIT))) == 0) TEIE &= ~TEIE1;//edge int disable 34 | T1I = 0; 35 | if (timer1_user_cb) { 36 | // to make ISR compatible to Arduino AVR model where interrupts are disabled 37 | // we disable them before we call the client ISR 38 | uint32_t savedPS = xt_rsil(15); // stop other interrupts 39 | timer1_user_cb(); 40 | xt_wsr_ps(savedPS); 41 | } 42 | } 43 | 44 | void timer1_isr_init(){ 45 | ETS_FRC_TIMER1_INTR_ATTACH(timer1_isr_handler, NULL); 46 | } 47 | 48 | void timer1_attachInterrupt(timercallback userFunc) { 49 | timer1_user_cb = userFunc; 50 | ETS_FRC1_INTR_ENABLE(); 51 | } 52 | 53 | void timer1_detachInterrupt() { 54 | timer1_user_cb = 0; 55 | TEIE &= ~TEIE1;//edge int disable 56 | ETS_FRC1_INTR_DISABLE(); 57 | } 58 | 59 | void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload){ 60 | T1C = (1 << TCTE) | ((divider & 3) << TCPD) | ((int_type & 1) << TCIT) | ((reload & 1) << TCAR); 61 | T1I = 0; 62 | } 63 | 64 | void ICACHE_RAM_ATTR timer1_write(uint32_t ticks){ 65 | T1L = ((ticks)& 0x7FFFFF); 66 | if ((T1C & (1 << TCIT)) == 0) TEIE |= TEIE1;//edge int enable 67 | } 68 | 69 | void timer1_disable(){ 70 | T1C = 0; 71 | T1I = 0; 72 | } 73 | 74 | //------------------------------------------------------------------- 75 | // timer 0 76 | 77 | static volatile timercallback timer0_user_cb = NULL; 78 | 79 | void ICACHE_RAM_ATTR timer0_isr_handler(void* para){ 80 | if (timer0_user_cb) { 81 | // to make ISR compatible to Arduino AVR model where interrupts are disabled 82 | // we disable them before we call the client ISR 83 | uint32_t savedPS = xt_rsil(15); // stop other interrupts 84 | timer0_user_cb(); 85 | xt_wsr_ps(savedPS); 86 | } 87 | } 88 | 89 | void timer0_isr_init(){ 90 | ETS_CCOMPARE0_INTR_ATTACH(timer0_isr_handler, NULL); 91 | } 92 | 93 | void timer0_attachInterrupt(timercallback userFunc) { 94 | timer0_user_cb = userFunc; 95 | ETS_CCOMPARE0_ENABLE(); 96 | } 97 | 98 | void timer0_detachInterrupt() { 99 | timer0_user_cb = NULL; 100 | ETS_CCOMPARE0_DISABLE(); 101 | } 102 | 103 | -------------------------------------------------------------------------------- /esp8266_arduino/core_esp8266_wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | core_esp8266_wiring.c - implementation of Wiring API for esp8266 3 | 4 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "wiring_private.h" 23 | #include "ets_sys.h" 24 | #include "osapi.h" 25 | #include "user_interface.h" 26 | #include "cont.h" 27 | 28 | extern void esp_schedule(); 29 | extern void esp_yield(); 30 | 31 | static os_timer_t delay_timer; 32 | static os_timer_t micros_overflow_timer; 33 | static uint32_t micros_at_last_overflow_tick = 0; 34 | static uint32_t micros_overflow_count = 0; 35 | #define ONCE 0 36 | #define REPEAT 1 37 | 38 | void delay_end(void* arg) { 39 | esp_schedule(); 40 | } 41 | 42 | void delay(unsigned long ms) { 43 | if(ms) { 44 | os_timer_setfn(&delay_timer, (os_timer_func_t*) &delay_end, 0); 45 | os_timer_arm(&delay_timer, ms, ONCE); 46 | } else { 47 | esp_schedule(); 48 | } 49 | esp_yield(); 50 | if(ms) { 51 | os_timer_disarm(&delay_timer); 52 | } 53 | } 54 | 55 | void micros_overflow_tick(void* arg) { 56 | uint32_t m = system_get_time(); 57 | if(m < micros_at_last_overflow_tick) 58 | ++micros_overflow_count; 59 | micros_at_last_overflow_tick = m; 60 | } 61 | 62 | unsigned long ICACHE_RAM_ATTR millis() { 63 | uint32_t m = system_get_time(); 64 | uint32_t c = micros_overflow_count + ((m < micros_at_last_overflow_tick) ? 1 : 0); 65 | return c * 4294967 + m / 1000; 66 | } 67 | 68 | unsigned long ICACHE_RAM_ATTR micros() { 69 | return system_get_time(); 70 | } 71 | 72 | void ICACHE_RAM_ATTR delayMicroseconds(unsigned int us) { 73 | os_delay_us(us); 74 | } 75 | 76 | void init() { 77 | initPins(); 78 | timer1_isr_init(); 79 | os_timer_setfn(µs_overflow_timer, (os_timer_func_t*) µs_overflow_tick, 0); 80 | os_timer_arm(µs_overflow_timer, 60000, REPEAT); 81 | } 82 | -------------------------------------------------------------------------------- /esp8266_arduino/core_esp8266_wiring_analog.c: -------------------------------------------------------------------------------- 1 | /* 2 | analog.c - analogRead implementation for esp8266 3 | 4 | Copyright (c) 2015 Hristo Gochkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #include "wiring_private.h" 22 | #include "pins_arduino.h" 23 | 24 | extern uint16_t readvdd33(void); 25 | 26 | void analogReference(uint8_t mode) {} 27 | 28 | extern int __analogRead(uint8_t pin) { 29 | if(pin == 17){ 30 | return system_adc_read(); // readvdd33 is 12 bit 31 | } 32 | return digitalRead(pin) * 1023; 33 | } 34 | 35 | extern int analogRead(uint8_t pin) __attribute__ ((weak, alias("__analogRead"))); 36 | -------------------------------------------------------------------------------- /esp8266_arduino/core_esp8266_wiring_pulse.c: -------------------------------------------------------------------------------- 1 | /* 2 | pulse.c - wiring pulseIn implementation for esp8266 3 | 4 | Copyright (c) 2015 Hristo Gochkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #include "wiring_private.h" 22 | #include "pins_arduino.h" 23 | 24 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) { 25 | pinMode(pin, INPUT); 26 | uint32_t start = micros(); 27 | while(digitalRead(pin) == state && (micros() - start) < timeout); 28 | while(digitalRead(pin) != state && (micros() - start) < timeout); 29 | start = micros(); 30 | while(digitalRead(pin) == state && (micros() - start) < timeout); 31 | return micros() - start; 32 | } 33 | -------------------------------------------------------------------------------- /esp8266_arduino/core_esp8266_wiring_pwm.c: -------------------------------------------------------------------------------- 1 | /* 2 | pwm.c - analogWrite implementation for esp8266 3 | 4 | Copyright (c) 2015 Hristo Gochkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #include "wiring_private.h" 22 | #include "pins_arduino.h" 23 | #include "c_types.h" 24 | #include "eagle_soc.h" 25 | #include "ets_sys.h" 26 | 27 | uint32_t pwm_mask = 0; 28 | uint16_t pwm_values[17] = {0,}; 29 | uint32_t pwm_freq = 1000; 30 | 31 | uint32_t pwm_multiplier = 0; 32 | uint16_t pwm_steps[17]; 33 | uint8_t pwm_steps_len = 0; 34 | uint32_t pwm_steps_mask[17]; 35 | 36 | int pwm_sort_array(uint16_t a[], uint16_t al){ 37 | uint16_t i, j; 38 | for (i = 1; i < al; i++) { 39 | uint16_t tmp = a[i]; 40 | for (j = i; j >= 1 && tmp < a[j-1]; j--) 41 | a[j] = a[j-1]; 42 | a[j] = tmp; 43 | } 44 | int bl = 1; 45 | for(i = 1; i < al; i++){ 46 | if(a[i] != a[i-1]) a[bl++] = a[i]; 47 | } 48 | return bl; 49 | } 50 | 51 | uint32_t pwm_get_mask(uint16_t value){ 52 | uint32_t mask = 0; 53 | int i; 54 | for(i=0; i<17; i++){ 55 | if((pwm_mask & (1 << i)) != 0 && pwm_values[i] == value) mask |= (1 << i); 56 | } 57 | return mask; 58 | } 59 | 60 | void prep_pwm_steps(){ 61 | if(pwm_mask == 0){ 62 | pwm_steps_len = 0; 63 | return; 64 | } 65 | 66 | int pwm_temp_steps_len = 0; 67 | uint16_t pwm_temp_steps[17]; 68 | uint32_t pwm_temp_masks[17]; 69 | 70 | int i; 71 | for(i=0; i<17; i++){ 72 | if((pwm_mask & (1 << i)) != 0 && pwm_values[i] != 0) pwm_temp_steps[pwm_temp_steps_len++] = pwm_values[i]; 73 | } 74 | pwm_temp_steps[pwm_temp_steps_len++] = PWMRANGE; 75 | pwm_temp_steps_len = pwm_sort_array(pwm_temp_steps, pwm_temp_steps_len) - 1; 76 | for(i=0; i0; i--){ 80 | pwm_temp_steps[i] = pwm_temp_steps[i] - pwm_temp_steps[i-1]; 81 | } 82 | ETS_FRC1_INTR_DISABLE(); 83 | pwm_steps_len = pwm_temp_steps_len; 84 | os_memcpy(pwm_steps, pwm_temp_steps, (pwm_temp_steps_len + 1) * 2); 85 | os_memcpy(pwm_steps_mask, pwm_temp_masks, pwm_temp_steps_len * 4); 86 | pwm_multiplier = F_CPU/(PWMRANGE * pwm_freq); 87 | ETS_FRC1_INTR_ENABLE(); 88 | } 89 | 90 | void ICACHE_RAM_ATTR pwm_timer_isr(){ 91 | static uint8_t current_step = 0; 92 | static uint8_t stepcount = 0; 93 | static uint16_t steps[17]; 94 | static uint32_t masks[17]; 95 | if(current_step < stepcount){ 96 | GPOC = masks[current_step] & 0xFFFF; 97 | if(masks[current_step] & 0x10000) GP16O &= ~1; 98 | current_step++; 99 | timer1_write(pwm_steps[current_step] * pwm_multiplier); 100 | } else { 101 | 102 | current_step = 0; 103 | stepcount = 0; 104 | if(pwm_mask == 0) return; 105 | GPOS = pwm_mask & 0xFFFF; 106 | if(pwm_mask & 0x10000) GP16O |= 1; 107 | timer1_write(pwm_steps[0] * pwm_multiplier); 108 | stepcount = pwm_steps_len; 109 | memcpy(steps, pwm_steps, (stepcount + 1) * 2); 110 | memcpy(masks, pwm_steps_mask, stepcount * 4); 111 | } 112 | } 113 | 114 | void pwm_start_timer(){ 115 | timer1_disable(); 116 | timer1_attachInterrupt(pwm_timer_isr); 117 | timer1_enable(TIM_DIV1, TIM_EDGE, TIM_SINGLE); 118 | timer1_write(1); 119 | } 120 | 121 | extern void __analogWrite(uint8_t pin, int value) { 122 | bool start_timer = false; 123 | if(value == 0){ 124 | pwm_mask &= ~(1 << pin); 125 | prep_pwm_steps(); 126 | digitalWrite(pin, LOW); 127 | if(pwm_mask == 0) timer1_disable(); 128 | return; 129 | } 130 | if((pwm_mask & (1 << pin)) == 0){ 131 | if(pwm_mask == 0) start_timer = true; 132 | pwm_mask |= (1 << pin); 133 | pinMode(pin, OUTPUT); 134 | digitalWrite(pin, LOW); 135 | } 136 | pwm_values[pin] = value % (PWMRANGE + 1); 137 | prep_pwm_steps(); 138 | if(start_timer){ 139 | pwm_start_timer(); 140 | } 141 | } 142 | 143 | extern void __analogWriteFreq(uint32_t freq){ 144 | pwm_freq = freq; 145 | prep_pwm_steps(); 146 | } 147 | 148 | extern void analogWrite(uint8_t pin, int val) __attribute__ ((weak, alias("__analogWrite"))); 149 | extern void analogWriteFreq(uint32_t freq) __attribute__ ((weak, alias("__analogWriteFreq"))); 150 | -------------------------------------------------------------------------------- /esp8266_arduino/core_esp8266_wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | Note: file renamed with a core_esp8266_ prefix to simplify linker 8 | script rules for moving code into irom0_text section. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General 21 | Public License along with this library; if not, write to the 22 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 23 | Boston, MA 02111-1307 USA 24 | 25 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 26 | */ 27 | 28 | #include "wiring_private.h" 29 | 30 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { 31 | uint8_t value = 0; 32 | uint8_t i; 33 | 34 | for(i = 0; i < 8; ++i) { 35 | digitalWrite(clockPin, HIGH); 36 | if(bitOrder == LSBFIRST) 37 | value |= digitalRead(dataPin) << i; 38 | else 39 | value |= digitalRead(dataPin) << (7 - i); 40 | digitalWrite(clockPin, LOW); 41 | } 42 | return value; 43 | } 44 | 45 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) { 46 | uint8_t i; 47 | 48 | for(i = 0; i < 8; i++) { 49 | if(bitOrder == LSBFIRST) 50 | digitalWrite(dataPin, !!(val & (1 << i))); 51 | else 52 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 53 | 54 | digitalWrite(clockPin, HIGH); 55 | digitalWrite(clockPin, LOW); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /esp8266_arduino/debug.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | debug.cpp - debug helper functions 3 | Copyright (c) 2015 Markus Sattler. All rights reserved. 4 | This file is part of the esp8266 core for Arduino environment. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "Arduino.h" 22 | #include "debug.h" 23 | 24 | void ICACHE_RAM_ATTR hexdump(uint8_t *mem, uint32_t len, uint8_t cols) { 25 | Serial1.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (size_t)mem, len, len); 26 | for(uint32_t i = 0; i < len; i++) { 27 | if(i % cols == 0) { 28 | Serial1.printf("\n[0x%08X] 0x%08X: ", (size_t)mem, i); 29 | yield(); 30 | } 31 | Serial1.printf("%02X ", *mem); 32 | mem++; 33 | } 34 | Serial1.printf("\n"); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /esp8266_arduino/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef ARD_DEBUG_H 2 | #define ARD_DEBUG_H 3 | 4 | #include 5 | //#define DEBUGV(...) ets_printf(__VA_ARGS__) 6 | 7 | #ifndef DEBUGV 8 | #define DEBUGV(...) 9 | #endif 10 | 11 | #ifdef __cplusplus 12 | void hexdump(uint8_t *mem, uint32_t len, uint8_t cols = 16); 13 | #else 14 | void hexdump(uint8_t *mem, uint32_t len, uint8_t cols); 15 | #endif 16 | 17 | #endif//ARD_DEBUG_H 18 | -------------------------------------------------------------------------------- /esp8266_arduino/interrupts.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERRUPTS_H 2 | #define INTERRUPTS_H 3 | 4 | #include "Arduino.h" 5 | // these auto classes wrap up xt_rsil so your code can be simplier, but can only be 6 | // used in an ino or cpp files. 7 | 8 | // InterruptLock is used when you want to completely disable locks 9 | //{ 10 | // { 11 | // InterruptLock lock; 12 | // // do work within interrupt lock here 13 | // } 14 | // do work outside of interrupt lock here outside its scope 15 | //} 16 | // 17 | 18 | class InterruptLock { 19 | public: 20 | InterruptLock() { 21 | _state = xt_rsil(15); 22 | } 23 | 24 | ~InterruptLock() { 25 | xt_wsr_ps(_state); 26 | } 27 | 28 | protected: 29 | uint32_t _state; 30 | }; 31 | 32 | // AutoInterruptLock is when you need to set a specific level, A normal use pattern is like 33 | // 34 | //{ 35 | // { 36 | // AutoInterruptLock(1); // this routine will allow level 2 and above 37 | // // do work within interrupt lock here 38 | // } 39 | // do work outside of interrupt lock here outside its scope 40 | //} 41 | // 42 | #define AutoInterruptLock(intrLevel) \ 43 | class _AutoDisableIntr { \ 44 | public: \ 45 | _AutoDisableIntr() { _savedPS = xt_rsil(intrLevel); } \ 46 | ~_AutoDisableIntr() { xt_wsr_ps(_savedPS); } \ 47 | private: \ 48 | uint32_t _savedPS; \ 49 | }; \ 50 | _AutoDisableIntr _autoDisableIntr 51 | 52 | #endif //INTERRUPTS_H 53 | -------------------------------------------------------------------------------- /esp8266_arduino/pgmspace.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | pgmspace.cpp - string functions that support PROGMEM 3 | Copyright (c) 2015 Michael C. Miller. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include "pgmspace.h" 22 | 23 | size_t ICACHE_FLASH_ATTR strnlen_P(const char* s, size_t size) { 24 | const char* cp; 25 | for (cp = s; size != 0 && pgm_read_byte(cp) != '\0'; cp++, size--); 26 | return (size_t)(cp - s); 27 | } 28 | 29 | void* ICACHE_FLASH_ATTR memcpy_P(void* dest, const void* src, size_t count) { 30 | const uint8_t* read = reinterpret_cast(src); 31 | uint8_t* write = reinterpret_cast(dest); 32 | 33 | while (count) 34 | { 35 | *write++ = pgm_read_byte(read++); 36 | count--; 37 | } 38 | 39 | return dest; 40 | } 41 | 42 | char* ICACHE_FLASH_ATTR strncpy_P(char* dest, const char* src, size_t size) { 43 | const char* read = src; 44 | char* write = dest; 45 | char ch = '.'; 46 | while (size > 0 && ch != '\0') 47 | { 48 | ch = pgm_read_byte(read++); 49 | *write++ = ch; 50 | size--; 51 | } 52 | 53 | return dest; 54 | } 55 | 56 | char* ICACHE_FLASH_ATTR strncat_P(char* dest, const char* src, size_t size) { 57 | char* write = dest; 58 | 59 | while (*write != '\0') 60 | { 61 | write++; 62 | } 63 | 64 | const char* read = src; 65 | char ch = '.'; 66 | 67 | while (size > 0 && ch != '\0') 68 | { 69 | ch = pgm_read_byte(read++); 70 | *write++ = ch; 71 | 72 | size--; 73 | } 74 | 75 | if (ch != '\0') 76 | { 77 | *write = '\0'; 78 | } 79 | 80 | return dest; 81 | } 82 | 83 | int ICACHE_FLASH_ATTR strncmp_P(const char* str1, const char* str2P, size_t size) { 84 | int result = 0; 85 | 86 | while (size > 0) 87 | { 88 | char ch1 = *str1++; 89 | char ch2 = pgm_read_byte(str2P++); 90 | result = ch1 - ch2; 91 | if (result != 0 || ch2 == '\0') 92 | { 93 | break; 94 | } 95 | 96 | size--; 97 | } 98 | 99 | return result; 100 | } 101 | 102 | int ICACHE_FLASH_ATTR strncasecmp_P(const char* str1, const char* str2P, size_t size) { 103 | int result = 0; 104 | 105 | while (size > 0) 106 | { 107 | char ch1 = tolower(*str1++); 108 | char ch2 = tolower(pgm_read_byte(str2P++)); 109 | result = ch1 - ch2; 110 | if (result != 0 || ch2 == '\0') 111 | { 112 | break; 113 | } 114 | 115 | size--; 116 | } 117 | 118 | return result; 119 | } 120 | 121 | int ICACHE_FLASH_ATTR printf_P(const char* formatP, ...) { 122 | int ret; 123 | va_list arglist; 124 | va_start(arglist, formatP); 125 | 126 | size_t fmtLen = strlen_P(formatP); 127 | char* format = new char[fmtLen + 1]; 128 | strcpy_P(format, formatP); 129 | 130 | ret = os_printf(format, arglist); 131 | 132 | delete [] format; 133 | 134 | va_end(arglist); 135 | return ret; 136 | } 137 | 138 | int ICACHE_FLASH_ATTR snprintf_P(char* str, size_t strSize, const char* formatP, ...) { 139 | int ret; 140 | va_list arglist; 141 | va_start(arglist, formatP); 142 | 143 | ret = vsnprintf_P(str, strSize, formatP, arglist); 144 | 145 | va_end(arglist); 146 | return ret; 147 | } 148 | 149 | int ICACHE_FLASH_ATTR vsnprintf_P(char* str, size_t strSize, const char* formatP, va_list ap) { 150 | int ret; 151 | 152 | size_t fmtLen = strlen_P(formatP); 153 | char* format = new char[fmtLen + 1]; 154 | strcpy_P(format, formatP); 155 | 156 | ret = ets_vsnprintf(str, strSize, format, ap); 157 | 158 | delete [] format; 159 | 160 | return ret; 161 | } -------------------------------------------------------------------------------- /esp8266_arduino/pgmspace.h: -------------------------------------------------------------------------------- 1 | #ifndef __PGMSPACE_H_ 2 | #define __PGMSPACE_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | #include 8 | #include 9 | #include "ets_sys.h" 10 | #include "osapi.h" 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #define PROGMEM ICACHE_RODATA_ATTR 16 | #define PGM_P const char * 17 | #define PGM_VOID_P const void * 18 | #define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];})) 19 | 20 | 21 | #define _SFR_BYTE(n) (n) 22 | 23 | typedef void prog_void; 24 | typedef char prog_char; 25 | typedef unsigned char prog_uchar; 26 | typedef int8_t prog_int8_t; 27 | typedef uint8_t prog_uint8_t; 28 | typedef int16_t prog_int16_t; 29 | typedef uint16_t prog_uint16_t; 30 | typedef int32_t prog_int32_t; 31 | typedef uint32_t prog_uint32_t; 32 | 33 | #define SIZE_IRRELEVANT 0x7fffffff 34 | 35 | extern void* memcpy_P(void* dest, const void* src, size_t count); 36 | 37 | extern char* strncpy_P(char* dest, const char* src, size_t size); 38 | #define strcpy_P(dest, src) strncpy_P((dest), (src), SIZE_IRRELEVANT) 39 | 40 | extern char* strncat_P(char* dest, const char* src, size_t size); 41 | #define strcat_P(dest, src) strncat_P((dest), (src), SIZE_IRRELEVANT) 42 | 43 | extern int strncmp_P(const char* str1, const char* str2P, size_t size); 44 | #define strcmp_P(str1, str2P) strncmp_P((str1), (str2P), SIZE_IRRELEVANT) 45 | 46 | extern int strncasecmp_P(const char* str1, const char* str2P, size_t size); 47 | #define strcasecmp_P(str1, str2P) strncasecmp_P((str1), (str2P), SIZE_IRRELEVANT) 48 | 49 | extern size_t strnlen_P(const char *s, size_t size); 50 | #define strlen_P(strP) strnlen_P((strP), SIZE_IRRELEVANT) 51 | 52 | extern int printf_P(const char *formatP, ...); 53 | extern int snprintf_P(char *str, size_t strSize, const char *formatP, ...); 54 | extern int vsnprintf_P(char *str, size_t strSize, const char *formatP, va_list ap); 55 | 56 | // flash memory must be read using 32 bit aligned addresses else a processor 57 | // exception will be triggered 58 | // order within the 32 bit values are 59 | // -------------- 60 | // b3, b2, b1, b0 61 | // w1, w0 62 | 63 | #define pgm_read_byte(addr) \ 64 | (__extension__({ \ 65 | PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \ 66 | ptrdiff_t __offset = ((uint32_t)__local & 0x00000003); /* byte aligned mask */ \ 67 | const uint32_t* __addr32 = reinterpret_cast(reinterpret_cast(__local)-__offset); \ 68 | uint8_t __result = ((*__addr32) >> (__offset * 8)); \ 69 | __result; \ 70 | })) 71 | 72 | #define pgm_read_word(addr) \ 73 | (__extension__({ \ 74 | PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \ 75 | ptrdiff_t __offset = ((uint32_t)__local & 0x00000002); /* word aligned mask */ \ 76 | const uint32_t* __addr32 = reinterpret_cast(reinterpret_cast(__local) - __offset); \ 77 | uint16_t __result = ((*__addr32) >> (__offset * 8)); \ 78 | __result; \ 79 | })) 80 | 81 | #define pgm_read_dword(addr) (*reinterpret_cast(addr)) 82 | #define pgm_read_float(addr) (*reinterpret_cast(addr)) 83 | 84 | #define pgm_read_byte_near(addr) pgm_read_byte(addr) 85 | #define pgm_read_word_near(addr) pgm_read_word(addr) 86 | #define pgm_read_dword_near(addr) pgm_read_dword(addr) 87 | #define pgm_read_float_near(addr) pgm_read_float(addr) 88 | #define pgm_read_byte_far(addr) pgm_read_byte(addr) 89 | #define pgm_read_word_far(addr) pgm_read_word(addr) 90 | #define pgm_read_dword_far(addr) pgm_read_dword(addr) 91 | #define pgm_read_float_far(addr) pgm_read_float(addr) 92 | 93 | #endif //__PGMSPACE_H_ 94 | -------------------------------------------------------------------------------- /esp8266_arduino/pins_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.h - Pin definition functions for Arduino 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2007 David A. Mellis 6 | Modified for ESP8266 platform by Ivan Grokhotkov, 2014-2015. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ 24 | */ 25 | 26 | #ifndef Pins_Arduino_h 27 | #define Pins_Arduino_h 28 | 29 | #define EXTERNAL_NUM_INTERRUPTS 16 30 | #define NUM_DIGITAL_PINS 17 31 | #define NUM_ANALOG_INPUTS 1 32 | 33 | #define analogInputToDigitalPin(p) ((p > 0)?NOT_A_PIN:0) 34 | #define digitalPinToInterrupt(p) (((p) < EXTERNAL_NUM_INTERRUPTS)?p:NOT_A_PIN) 35 | #define digitalPinHasPWM(p) (((p) < NUM_DIGITAL_PINS)?p:NOT_A_PIN) 36 | 37 | static const uint8_t SDA = 4; 38 | static const uint8_t SCL = 5; 39 | 40 | static const uint8_t SS = 15; 41 | static const uint8_t MOSI = 13; 42 | static const uint8_t MISO = 12; 43 | static const uint8_t SCK = 14; 44 | 45 | static const uint8_t BUILTIN_LED = 1; 46 | 47 | static const uint8_t A0 = 17; 48 | 49 | // These serial port names are intended to allow libraries and architecture-neutral 50 | // sketches to automatically default to the correct port name for a particular type 51 | // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, 52 | // the first hardware serial port whose RX/TX pins are not dedicated to another use. 53 | // 54 | // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor 55 | // 56 | // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial 57 | // 58 | // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library 59 | // 60 | // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. 61 | // 62 | // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX 63 | // pins are NOT connected to anything by default. 64 | #define SERIAL_PORT_MONITOR Serial 65 | #define SERIAL_PORT_USBVIRTUAL Serial 66 | #define SERIAL_PORT_HARDWARE Serial 67 | #define SERIAL_PORT_HARDWARE_OPEN Serial 68 | 69 | #endif /* Pins_Arduino_h */ 70 | -------------------------------------------------------------------------------- /esp8266_arduino/stdlib_noniso.h: -------------------------------------------------------------------------------- 1 | /* 2 | stdlib_noniso.h - nonstandard (but usefull) conversion functions 3 | 4 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef STDLIB_NONISO_H 23 | #define STDLIB_NONISO_H 24 | 25 | #ifdef __cplusplus 26 | extern "C"{ 27 | #endif 28 | 29 | int atoi(const char *s); 30 | 31 | long atol(const char* s); 32 | 33 | double atof(const char* s); 34 | 35 | char* itoa (int val, char *s, int radix); 36 | 37 | char* ltoa (long val, char *s, int radix); 38 | 39 | char* utoa (unsigned int val, char *s, int radix); 40 | 41 | char* ultoa (unsigned long val, char *s, int radix); 42 | 43 | char* dtostrf (double val, signed char width, unsigned char prec, char *s); 44 | 45 | #ifdef __cplusplus 46 | } // extern "C" 47 | #endif 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /esp8266_arduino/twi.h: -------------------------------------------------------------------------------- 1 | /* 2 | twi.h - Software I2C library for esp8266 3 | 4 | Copyright (c) 2015 Hristo Gochkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #ifndef SI2C_h 22 | #define SI2C_h 23 | #include "Arduino.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void twi_init(unsigned char sda, unsigned char scl); 30 | void twi_stop(void); 31 | void twi_setClock(unsigned int freq); 32 | uint8_t twi_writeTo(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop); 33 | uint8_t twi_readFrom(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif -------------------------------------------------------------------------------- /esp8266_arduino/wiring_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_private.h - Internal header file. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $ 23 | */ 24 | 25 | #ifndef WiringPrivate_h 26 | #define WiringPrivate_h 27 | 28 | #include 29 | #include 30 | 31 | #include "Arduino.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | typedef void (*voidFuncPtr)(void); 38 | 39 | void initPins(); 40 | 41 | #ifdef __cplusplus 42 | } // extern "C" 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /esp8266_sdk/include/at_custom.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * custom_at.h 4 | * 5 | * This file is part of Espressif's AT+ command set program. 6 | * Copyright (C) 2013 - 2016, Espressif Systems 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of version 3 of the GNU General Public License as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program. If not, see . 19 | */ 20 | 21 | #ifndef CUSTOM_AT_H_ 22 | #define CUSTOM_AT_H_ 23 | 24 | #include "c_types.h" 25 | 26 | typedef struct 27 | { 28 | char *at_cmdName; 29 | int8_t at_cmdLen; 30 | void (*at_testCmd)(uint8_t id); 31 | void (*at_queryCmd)(uint8_t id); 32 | void (*at_setupCmd)(uint8_t id, char *pPara); 33 | void (*at_exeCmd)(uint8_t id); 34 | }at_funcationType; 35 | 36 | typedef void (*at_custom_uart_rx_intr)(uint8* data,int32 len); 37 | 38 | typedef void (*at_custom_response_func_type)(const char *str); 39 | 40 | extern uint8 at_customLinkMax; 41 | 42 | /** 43 | * @brief Response "OK" to uart. 44 | * @param None 45 | * @retval None 46 | */ 47 | void at_response_ok(void); 48 | /** 49 | * @brief Response "ERROR" to uart. 50 | * @param None 51 | * @retval None 52 | */ 53 | void at_response_error(void); 54 | /** 55 | * @brief Response string. 56 | * It is equivalent to at_port_print,if not call at_register_response_func or call at_register_response_func(NULL); 57 | * It will run custom response function,if call at_register_response_func and parameter is not NULL. 58 | * @param string 59 | * @retval None 60 | */ 61 | void at_response(const char *str); 62 | /** 63 | * @brief register custom response function. 64 | * @param response_func: the function that will run when call at_response 65 | * @retval None 66 | */ 67 | void at_register_response_func(at_custom_response_func_type response_func); 68 | /** 69 | * @brief Task of process command or txdata. 70 | * @param custom_at_cmd_array: the array of at cmd that custom defined 71 | * cmd_num : the num of at cmd that custom defined 72 | * @retval None 73 | */ 74 | void at_cmd_array_regist(at_funcationType *custom_at_cmd_array,uint32 cmd_num); 75 | /** 76 | * @brief get digit form at cmd line.the maybe alter pSrc 77 | * @param p_src: at cmd line string 78 | * result:the buffer to be placed result 79 | * err : err num 80 | * @retval TRUE: 81 | * FALSE: 82 | */ 83 | bool at_get_next_int_dec(char **p_src,int*result,int* err); 84 | /** 85 | * @brief get string form at cmd line.the maybe alter pSrc 86 | * @param p_dest: the buffer to be placed result 87 | * p_src: at cmd line string 88 | * max_len :max len of string excepted to get 89 | * @retval None 90 | */ 91 | int32 at_data_str_copy(char *p_dest, char **p_src, int32 max_len); 92 | 93 | /** 94 | * @brief initialize at module 95 | * @param None 96 | * @retval None 97 | */ 98 | void at_init(void); 99 | /** 100 | * @brief print string to at port 101 | * @param string 102 | * @retval None 103 | */ 104 | void at_port_print(const char *str); 105 | /** 106 | * @brief print custom information when AT+GMR 107 | * @param string 108 | * @retval None 109 | */ 110 | void at_set_custom_info(char* info); 111 | /** 112 | * @brief if current at command is processing,you can call at_enter_special_state, 113 | * then if other comamnd coming,it will return busy. 114 | * @param None 115 | * @retval None 116 | */ 117 | void at_enter_special_state(void); 118 | /** 119 | * @brief 120 | * @param None 121 | * @retval None 122 | */ 123 | void at_leave_special_state(void); 124 | /** 125 | * @brief get at version 126 | * @param None 127 | * @retval at version 128 | * bit24~31: at main version 129 | * bit23~16: at sub version 130 | * bit15~8 : at test version 131 | * bit7~0 : customized version 132 | */ 133 | uint32 at_get_version(void); 134 | 135 | /** 136 | * @brief register custom uart rx interrupt function 137 | * @param rx_func: custom uart rx interrupt function. 138 | * If rx_func is non-void,when rx interrupt comming,it will call rx_func(data,len), 139 | * data is the buffer of data,len is the length of data.Otherwise,it will run AT rx function. 140 | * @retval None 141 | */ 142 | void at_register_uart_rx_intr(at_custom_uart_rx_intr rx_func); 143 | #endif 144 | -------------------------------------------------------------------------------- /esp8266_sdk/include/c_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 - 2011 Espressif System 3 | * 4 | */ 5 | 6 | #ifndef _C_TYPES_H_ 7 | #define _C_TYPES_H_ 8 | #include 9 | #include 10 | #include 11 | 12 | typedef signed char sint8_t; 13 | typedef signed short sint16_t; 14 | typedef signed long sint32_t; 15 | typedef signed long long sint64_t; 16 | typedef unsigned long long u_int64_t; 17 | typedef float real32_t; 18 | typedef double real64_t; 19 | 20 | typedef unsigned char uint8; 21 | typedef unsigned char u8; 22 | typedef signed char sint8; 23 | typedef signed char int8; 24 | typedef signed char s8; 25 | typedef unsigned short uint16; 26 | typedef unsigned short u16; 27 | typedef signed short sint16; 28 | typedef signed short s16; 29 | typedef unsigned int uint32; 30 | typedef unsigned int u_int; 31 | typedef unsigned int u32; 32 | typedef signed int sint32; 33 | typedef signed int s32; 34 | typedef int int32; 35 | typedef signed long long sint64; 36 | typedef unsigned long long uint64; 37 | typedef unsigned long long u64; 38 | typedef float real32; 39 | typedef double real64; 40 | 41 | #define __le16 u16 42 | 43 | #define __packed __attribute__((packed)) 44 | 45 | #define LOCAL static 46 | 47 | #ifndef NULL 48 | #define NULL (void *)0 49 | #endif /* NULL */ 50 | 51 | /* probably should not put STATUS here */ 52 | typedef enum { 53 | OK = 0, 54 | FAIL, 55 | PENDING, 56 | BUSY, 57 | CANCEL, 58 | } STATUS; 59 | 60 | #define BIT(nr) (1UL << (nr)) 61 | 62 | #define REG_SET_BIT(_r, _b) (*(volatile uint32_t*)(_r) |= (_b)) 63 | #define REG_CLR_BIT(_r, _b) (*(volatile uint32_t*)(_r) &= ~(_b)) 64 | 65 | #define DMEM_ATTR __attribute__((section(".bss"))) 66 | #define SHMEM_ATTR 67 | 68 | #ifdef ICACHE_FLASH 69 | #define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text"))) 70 | #define ICACHE_RAM_ATTR __attribute__((section(".iram.text"))) 71 | #define ICACHE_RODATA_ATTR __attribute__((section(".irom.text"))) 72 | #else 73 | #define ICACHE_FLASH_ATTR 74 | #define ICACHE_RAM_ATTR 75 | #define ICACHE_RODATA_ATTR 76 | #endif /* ICACHE_FLASH */ 77 | 78 | #define STORE_ATTR __attribute__((aligned(4))) 79 | 80 | #ifndef __cplusplus 81 | #define BOOL bool 82 | #define TRUE true 83 | #define FALSE false 84 | 85 | 86 | #endif /* !__cplusplus */ 87 | 88 | #endif /* _C_TYPES_H_ */ 89 | 90 | -------------------------------------------------------------------------------- /esp8266_sdk/include/espnow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 -2018 Espressif System 3 | * 4 | */ 5 | 6 | #ifndef __ESPNOW_H__ 7 | #define __ESPNOW_H__ 8 | 9 | enum esp_now_role { 10 | ESP_NOW_ROLE_IDLE = 0, 11 | ESP_NOW_ROLE_CONTROLLER, 12 | ESP_NOW_ROLE_SLAVE, 13 | ESP_NOW_ROLE_MAX, 14 | }; 15 | 16 | typedef void (*esp_now_recv_cb_t)(u8 *mac_addr, u8 *data, u8 len); 17 | typedef void (*esp_now_send_cb_t)(u8 *mac_addr, u8 status); 18 | 19 | int esp_now_init(void); 20 | int esp_now_deinit(void); 21 | 22 | int esp_now_register_send_cb(esp_now_send_cb_t cb); 23 | int esp_now_unregister_send_cb(void); 24 | 25 | int esp_now_register_recv_cb(esp_now_recv_cb_t cb); 26 | int esp_now_unregister_recv_cb(void); 27 | 28 | int esp_now_send(u8 *da, u8 *data, int len); 29 | 30 | int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len); 31 | int esp_now_del_peer(u8 *mac_addr); 32 | 33 | int esp_now_set_self_role(u8 role); 34 | int esp_now_get_self_role(void); 35 | 36 | int esp_now_set_peer_role(u8 *mac_addr, u8 role); 37 | int esp_now_get_peer_role(u8 *mac_addr); 38 | 39 | int esp_now_set_peer_channel(u8 *mac_addr, u8 channel); 40 | int esp_now_get_peer_channel(u8 *mac_addr); 41 | 42 | int esp_now_set_peer_key(u8 *mac_addr, u8 *key, u8 key_len); 43 | int esp_now_get_peer_key(u8 *mac_addr, u8 *key, u8 *key_len); 44 | 45 | u8 *esp_now_fetch_peer(bool restart); 46 | 47 | int esp_now_is_peer_exist(u8 *mac_addr); 48 | 49 | int esp_now_get_cnt_info(u8 *all_cnt, u8 *encrypt_cnt); 50 | 51 | int esp_now_set_kok(u8 *key, u8 len); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /esp8266_sdk/include/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) Espressif System 2010 3 | * 4 | */ 5 | 6 | #ifndef _GPIO_H_ 7 | #define _GPIO_H_ 8 | 9 | #define GPIO_PIN_ADDR(i) (GPIO_PIN0_ADDRESS + i*4) 10 | 11 | #define GPIO_ID_IS_PIN_REGISTER(reg_id) \ 12 | ((reg_id >= GPIO_ID_PIN0) && (reg_id <= GPIO_ID_PIN(GPIO_PIN_COUNT-1))) 13 | 14 | #define GPIO_REGID_TO_PINIDX(reg_id) ((reg_id) - GPIO_ID_PIN0) 15 | 16 | typedef enum { 17 | GPIO_PIN_INTR_DISABLE = 0, 18 | GPIO_PIN_INTR_POSEDGE = 1, 19 | GPIO_PIN_INTR_NEGEDGE = 2, 20 | GPIO_PIN_INTR_ANYEDGE = 3, 21 | GPIO_PIN_INTR_LOLEVEL = 4, 22 | GPIO_PIN_INTR_HILEVEL = 5 23 | } GPIO_INT_TYPE; 24 | 25 | #define GPIO_OUTPUT_SET(gpio_no, bit_value) \ 26 | gpio_output_set((bit_value)<>gpio_no)&BIT0) 29 | 30 | /* GPIO interrupt handler, registered through gpio_intr_handler_register */ 31 | typedef void (* gpio_intr_handler_fn_t)(uint32 intr_mask, void *arg); 32 | 33 | 34 | /* 35 | * Initialize GPIO. This includes reading the GPIO Configuration DataSet 36 | * to initialize "output enables" and pin configurations for each gpio pin. 37 | * Must be called once during startup. 38 | */ 39 | void gpio_init(void); 40 | 41 | /* 42 | * Change GPIO pin output by setting, clearing, or disabling pins. 43 | * In general, it is expected that a bit will be set in at most one 44 | * of these masks. If a bit is clear in all masks, the output state 45 | * remains unchanged. 46 | * 47 | * There is no particular ordering guaranteed; so if the order of 48 | * writes is significant, calling code should divide a single call 49 | * into multiple calls. 50 | */ 51 | void gpio_output_set(uint32 set_mask, 52 | uint32 clear_mask, 53 | uint32 enable_mask, 54 | uint32 disable_mask); 55 | 56 | /* 57 | * Sample the value of GPIO input pins and returns a bitmask. 58 | */ 59 | uint32 gpio_input_get(void); 60 | 61 | /* 62 | * Set the specified GPIO register to the specified value. 63 | * This is a very general and powerful interface that is not 64 | * expected to be used during normal operation. It is intended 65 | * mainly for debug, or for unusual requirements. 66 | */ 67 | void gpio_register_set(uint32 reg_id, uint32 value); 68 | 69 | /* Get the current value of the specified GPIO register. */ 70 | uint32 gpio_register_get(uint32 reg_id); 71 | 72 | /* 73 | * Register an application-specific interrupt handler for GPIO pin 74 | * interrupts. Once the interrupt handler is called, it will not 75 | * be called again until after a call to gpio_intr_ack. Any GPIO 76 | * interrupts that occur during the interim are masked. 77 | * 78 | * The application-specific handler is called with a mask of 79 | * pending GPIO interrupts. After processing pin interrupts, the 80 | * application-specific handler may wish to use gpio_intr_pending 81 | * to check for any additional pending interrupts before it returns. 82 | */ 83 | void gpio_intr_handler_register(gpio_intr_handler_fn_t fn, void *arg); 84 | 85 | /* Determine which GPIO interrupts are pending. */ 86 | uint32 gpio_intr_pending(void); 87 | 88 | /* 89 | * Acknowledge GPIO interrupts. 90 | * Intended to be called from the gpio_intr_handler_fn. 91 | */ 92 | void gpio_intr_ack(uint32 ack_mask); 93 | 94 | void gpio_pin_wakeup_enable(uint32 i, GPIO_INT_TYPE intr_state); 95 | 96 | void gpio_pin_wakeup_disable(); 97 | 98 | void gpio_pin_intr_state_set(uint32 i, GPIO_INT_TYPE intr_state); 99 | 100 | #endif // _GPIO_H_ 101 | -------------------------------------------------------------------------------- /esp8266_sdk/include/ip_addr.h: -------------------------------------------------------------------------------- 1 | #ifndef __IP_ADDR_H__ 2 | #define __IP_ADDR_H__ 3 | 4 | #include "c_types.h" 5 | 6 | struct ip_addr { 7 | uint32 addr; 8 | }; 9 | 10 | typedef struct ip_addr ip_addr_t; 11 | 12 | struct ip_info { 13 | struct ip_addr ip; 14 | struct ip_addr netmask; 15 | struct ip_addr gw; 16 | }; 17 | 18 | /** 19 | * Determine if two address are on the same network. 20 | * 21 | * @arg addr1 IP address 1 22 | * @arg addr2 IP address 2 23 | * @arg mask network identifier mask 24 | * @return !0 if the network identifiers of both address match 25 | */ 26 | #define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \ 27 | (mask)->addr) == \ 28 | ((addr2)->addr & \ 29 | (mask)->addr)) 30 | 31 | /** Set an IP address given by the four byte-parts. 32 | Little-endian version that prevents the use of htonl. */ 33 | #define IP4_ADDR(ipaddr, a,b,c,d) \ 34 | (ipaddr)->addr = ((uint32)((d) & 0xff) << 24) | \ 35 | ((uint32)((c) & 0xff) << 16) | \ 36 | ((uint32)((b) & 0xff) << 8) | \ 37 | (uint32)((a) & 0xff) 38 | 39 | #define ip4_addr1(ipaddr) (((uint8*)(ipaddr))[0]) 40 | #define ip4_addr2(ipaddr) (((uint8*)(ipaddr))[1]) 41 | #define ip4_addr3(ipaddr) (((uint8*)(ipaddr))[2]) 42 | #define ip4_addr4(ipaddr) (((uint8*)(ipaddr))[3]) 43 | 44 | #define ip4_addr1_16(ipaddr) ((uint16)ip4_addr1(ipaddr)) 45 | #define ip4_addr2_16(ipaddr) ((uint16)ip4_addr2(ipaddr)) 46 | #define ip4_addr3_16(ipaddr) ((uint16)ip4_addr3(ipaddr)) 47 | #define ip4_addr4_16(ipaddr) ((uint16)ip4_addr4(ipaddr)) 48 | 49 | 50 | /** 255.255.255.255 */ 51 | #define IPADDR_NONE ((uint32)0xffffffffUL) 52 | /** 0.0.0.0 */ 53 | #define IPADDR_ANY ((uint32)0x00000000UL) 54 | uint32 ipaddr_addr(const char *cp); 55 | 56 | #define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \ 57 | ip4_addr2_16(ipaddr), \ 58 | ip4_addr3_16(ipaddr), \ 59 | ip4_addr4_16(ipaddr) 60 | 61 | #define IPSTR "%d.%d.%d.%d" 62 | 63 | #endif /* __IP_ADDR_H__ */ 64 | -------------------------------------------------------------------------------- /esp8266_sdk/include/json/json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2012, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the Contiki operating system. 30 | */ 31 | 32 | /** 33 | * \file 34 | * A few JSON defines used for parsing and generating JSON. 35 | * \author 36 | * Niclas Finne 37 | * Joakim Eriksson 38 | */ 39 | 40 | #ifndef __JSON_H__ 41 | #define __JSON_H__ 42 | 43 | #define JSON_TYPE_ARRAY '[' 44 | #define JSON_TYPE_OBJECT '{' 45 | #define JSON_TYPE_PAIR ':' 46 | #define JSON_TYPE_PAIR_NAME 'N' /* for N:V pairs */ 47 | #define JSON_TYPE_STRING '"' 48 | #define JSON_TYPE_INT 'I' 49 | #define JSON_TYPE_NUMBER '0' 50 | #define JSON_TYPE_ERROR 0 51 | 52 | /* how should we handle null vs false - both can be 0? */ 53 | #define JSON_TYPE_NULL 'n' 54 | #define JSON_TYPE_TRUE 't' 55 | #define JSON_TYPE_FALSE 'f' 56 | 57 | #define JSON_TYPE_CALLBACK 'C' 58 | 59 | enum { 60 | JSON_ERROR_OK, 61 | JSON_ERROR_SYNTAX, 62 | JSON_ERROR_UNEXPECTED_ARRAY, 63 | JSON_ERROR_UNEXPECTED_END_OF_ARRAY, 64 | JSON_ERROR_UNEXPECTED_OBJECT, 65 | JSON_ERROR_UNEXPECTED_STRING 66 | }; 67 | 68 | #define JSON_CONTENT_TYPE "application/json" 69 | 70 | #endif /* __JSON_H__ */ 71 | -------------------------------------------------------------------------------- /esp8266_sdk/include/json/jsonparse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2012, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the Contiki operating system. 30 | */ 31 | 32 | #ifndef __JSONPARSE_H__ 33 | #define __JSONPARSE_H__ 34 | 35 | #include "c_types.h" 36 | #include "json/json.h" 37 | 38 | #ifdef JSONPARSE_CONF_MAX_DEPTH 39 | #define JSONPARSE_MAX_DEPTH JSONPARSE_CONF_MAX_DEPTH 40 | #else 41 | #define JSONPARSE_MAX_DEPTH 10 42 | #endif 43 | 44 | struct jsonparse_state { 45 | const char *json; 46 | int pos; 47 | int len; 48 | int depth; 49 | /* for handling atomic values */ 50 | int vstart; 51 | int vlen; 52 | char vtype; 53 | char error; 54 | char stack[JSONPARSE_MAX_DEPTH]; 55 | }; 56 | 57 | /** 58 | * \brief Initialize a JSON parser state. 59 | * \param state A pointer to a JSON parser state 60 | * \param json The string to parse as JSON 61 | * \param len The length of the string to parse 62 | * 63 | * This function initializes a JSON parser state for 64 | * parsing a string as JSON. 65 | */ 66 | void jsonparse_setup(struct jsonparse_state *state, const char *json, 67 | int len); 68 | 69 | /* move to next JSON element */ 70 | int jsonparse_next(struct jsonparse_state *state); 71 | 72 | /* copy the current JSON value into the specified buffer */ 73 | int jsonparse_copy_value(struct jsonparse_state *state, char *buf, 74 | int buf_size); 75 | 76 | /* get the current JSON value parsed as an int */ 77 | int jsonparse_get_value_as_int(struct jsonparse_state *state); 78 | 79 | /* get the current JSON value parsed as a long */ 80 | long jsonparse_get_value_as_long(struct jsonparse_state *state); 81 | 82 | /* get the current JSON value parsed as a unsigned long */ 83 | unsigned long jsonparse_get_value_as_ulong(struct jsonparse_state *state); 84 | 85 | /* get the length of the current JSON value */ 86 | int jsonparse_get_len(struct jsonparse_state *state); 87 | 88 | /* get the type of the current JSON value */ 89 | int jsonparse_get_type(struct jsonparse_state *state); 90 | 91 | /* compare the JSON value with the specified string */ 92 | int jsonparse_strcmp_value(struct jsonparse_state *state, const char *str); 93 | 94 | #endif /* __JSONPARSE_H__ */ 95 | -------------------------------------------------------------------------------- /esp8266_sdk/include/mem.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEM_H__ 2 | #define __MEM_H__ 3 | 4 | /* Note: check_memleak_debug_enable is a weak function inside SDK. 5 | * please copy following codes to user_main.c. 6 | #include "mem.h" 7 | 8 | bool ICACHE_FLASH_ATTR check_memleak_debug_enable(void) 9 | { 10 | return MEMLEAK_DEBUG_ENABLE; 11 | } 12 | */ 13 | 14 | #ifndef MEMLEAK_DEBUG 15 | #define MEMLEAK_DEBUG_ENABLE 0 16 | #define os_free(s) vPortFree(s, "", 0) 17 | #define os_malloc(s) pvPortMalloc(s, "", 0) 18 | #define os_calloc(s) pvPortCalloc(s, "", 0); 19 | #define os_realloc(p, s) pvPortRealloc(p, s, "", 0) 20 | #define os_zalloc(s) pvPortZalloc(s, "", 0) 21 | #else 22 | #define MEMLEAK_DEBUG_ENABLE 1 23 | 24 | #define os_free(s) \ 25 | do{\ 26 | static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \ 27 | vPortFree(s, mem_debug_file, __LINE__);\ 28 | }while(0) 29 | 30 | #define os_malloc(s) \ 31 | ({ \ 32 | static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \ 33 | pvPortMalloc(s, mem_debug_file, __LINE__); \ 34 | }) 35 | 36 | #define os_calloc(s) \ 37 | ({ \ 38 | static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \ 39 | pvPortCalloc(s, mem_debug_file, __LINE__); \ 40 | }) 41 | 42 | #define os_realloc(p, s) \ 43 | ({ \ 44 | static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \ 45 | pvPortRealloc(p, s, mem_debug_file, __LINE__); \ 46 | }) 47 | 48 | #define os_zalloc(s) \ 49 | ({ \ 50 | static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \ 51 | pvPortZalloc(s, mem_debug_file, __LINE__); \ 52 | }) 53 | 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /esp8266_sdk/include/mesh.h: -------------------------------------------------------------------------------- 1 | #ifndef __LWIP_API_MESH_H__ 2 | #define __LWIP_API_MESH_H__ 3 | 4 | #include "ip_addr.h" 5 | #include "user_interface.h" 6 | #include "espconn.h" 7 | 8 | typedef void (* espconn_mesh_callback)(); 9 | 10 | enum mesh_type { 11 | MESH_CLOSE = 0, 12 | MESH_LOCAL, 13 | MESH_ONLINE, 14 | MESH_NONE = 0xFF 15 | }; 16 | 17 | enum mesh_status { 18 | MESH_DISABLE = 0, 19 | MESH_WIFI_CONN, 20 | MESH_NET_CONN, 21 | MESH_LOCAL_AVAIL, 22 | MESH_ONLINE_AVAIL 23 | }; 24 | 25 | enum mesh_node_type { 26 | MESH_NODE_PARENT = 0, 27 | MESH_NODE_CHILD, 28 | MESH_NODE_ALL 29 | }; 30 | 31 | bool espconn_mesh_local_addr(struct ip_addr *ip); 32 | bool espconn_mesh_get_node_info(enum mesh_node_type type, 33 | uint8_t **info, uint8_t *count); 34 | bool espconn_mesh_get_router(struct station_config *router); 35 | bool espconn_mesh_set_router(struct station_config *router); 36 | bool espconn_mesh_encrypt_init(AUTH_MODE mode, uint8_t *passwd, uint8_t passwd_len); 37 | bool espconn_mesh_set_ssid_prefix(uint8_t *prefix, uint8_t prefix_len); 38 | bool espconn_mesh_set_max_hops(uint8_t max_hops); 39 | 40 | char * espconn_json_find_section(const char *pbuf, u16 len, const char *section); 41 | 42 | sint8 espconn_mesh_connect(struct espconn *usr_esp); 43 | sint8 espconn_mesh_disconnect(struct espconn *usr_esp); 44 | sint8 espconn_mesh_get_status(); 45 | sint8 espconn_mesh_sent(struct espconn *usr_esp, uint8 *pdata, uint16 len); 46 | 47 | uint8 espconn_mesh_get_max_hops(); 48 | uint8 espconn_mesh_layer(struct ip_addr *ip); 49 | uint32_t user_json_get_value(const char *pbuffer, uint16_t buf_len, 50 | const uint8_t *json_key); 51 | 52 | void espconn_mesh_enable(espconn_mesh_callback enable_cb, enum mesh_type type); 53 | void espconn_mesh_disable(espconn_mesh_callback disable_cb); 54 | void espconn_mesh_init(); 55 | void espconn_mesh_init_group_list(uint8_t *dev_mac, uint16_t dev_count); 56 | void espconn_mesh_set_dev_type(uint8_t dev_type); 57 | void espconn_mesh_setup_timer(os_timer_t *timer, uint32_t time, 58 | os_timer_func_t cb, void *arg, bool repeat); 59 | 60 | #endif 61 | 62 | -------------------------------------------------------------------------------- /esp8266_sdk/include/os_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) Espressif System 2010 3 | * 4 | * mapping to ETS structures 5 | * 6 | */ 7 | #ifndef _OS_TYPES_H_ 8 | #define _OS_TYPES_H_ 9 | 10 | #include "ets_sys.h" 11 | 12 | #define os_signal_t ETSSignal 13 | #define os_param_t ETSParam 14 | #define os_event_t ETSEvent 15 | #define os_task_t ETSTask 16 | #define os_timer_t ETSTimer 17 | #define os_timer_func_t ETSTimerFunc 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /esp8266_sdk/include/osapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Espressif System 3 | */ 4 | 5 | #ifndef _OSAPI_H_ 6 | #define _OSAPI_H_ 7 | 8 | #include 9 | #include "user_config.h" 10 | 11 | #define os_bzero ets_bzero 12 | #define os_delay_us ets_delay_us 13 | #define os_install_putc1 ets_install_putc1 14 | #define os_install_putc2 ets_install_putc2 15 | #define os_intr_lock ets_intr_lock 16 | #define os_intr_unlock ets_intr_unlock 17 | #define os_isr_attach ets_isr_attach 18 | #define os_isr_mask ets_isr_mask 19 | #define os_isr_unmask ets_isr_unmask 20 | #define os_memcmp ets_memcmp 21 | #define os_memcpy ets_memcpy 22 | #define os_memmove ets_memmove 23 | #define os_memset ets_memset 24 | #define os_putc ets_putc 25 | #define os_str2macaddr ets_str2macaddr 26 | #define os_strcat strcat 27 | #define os_strchr strchr 28 | #define os_strcmp ets_strcmp 29 | #define os_strcpy ets_strcpy 30 | #define os_strlen ets_strlen 31 | #define os_strncmp ets_strncmp 32 | #define os_strncpy ets_strncpy 33 | #define os_strstr ets_strstr 34 | #ifdef USE_US_TIMER 35 | #define os_timer_arm_us(a, b, c) ets_timer_arm_new(a, b, c, 0) 36 | #endif 37 | #define os_timer_arm(a, b, c) ets_timer_arm_new(a, b, c, 1) 38 | #define os_timer_disarm ets_timer_disarm 39 | #define os_timer_done ets_timer_done 40 | #define os_timer_handler_isr ets_timer_handler_isr 41 | #define os_timer_init ets_timer_init 42 | #define os_timer_setfn ets_timer_setfn 43 | 44 | #define os_sprintf ets_sprintf 45 | #define os_update_cpu_frequency ets_update_cpu_frequency 46 | 47 | #ifdef USE_OPTIMIZE_PRINTF 48 | #define os_printf(fmt, ...) do { \ 49 | static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = fmt; \ 50 | os_printf_plus(flash_str, ##__VA_ARGS__); \ 51 | } while(0) 52 | #else 53 | extern int os_printf_plus(const char * format, ...) __attribute__ ((format (printf, 1, 2))); //added by shao 54 | #define os_printf os_printf_plus 55 | #endif 56 | 57 | unsigned long os_random(void); 58 | int os_get_random(unsigned char *buf, size_t len); 59 | 60 | #endif 61 | 62 | -------------------------------------------------------------------------------- /esp8266_sdk/include/ping.h: -------------------------------------------------------------------------------- 1 | #ifndef __PING_H__ 2 | #define __PING_H__ 3 | 4 | 5 | typedef void (* ping_recv_function)(void* arg, void *pdata); 6 | typedef void (* ping_sent_function)(void* arg, void *pdata); 7 | 8 | struct ping_option{ 9 | uint32 count; 10 | uint32 ip; 11 | uint32 coarse_time; 12 | ping_recv_function recv_function; 13 | ping_sent_function sent_function; 14 | void* reverse; 15 | }; 16 | 17 | struct ping_resp{ 18 | uint32 total_count; 19 | uint32 resp_time; 20 | uint32 seqno; 21 | uint32 timeout_count; 22 | uint32 bytes; 23 | uint32 total_bytes; 24 | uint32 total_time; 25 | sint8 ping_err; 26 | }; 27 | 28 | bool ping_start(struct ping_option *ping_opt); 29 | bool ping_regist_recv(struct ping_option *ping_opt, ping_recv_function ping_recv); 30 | bool ping_regist_sent(struct ping_option *ping_opt, ping_sent_function ping_sent); 31 | 32 | #endif /* __PING_H__ */ 33 | -------------------------------------------------------------------------------- /esp8266_sdk/include/pwm.h: -------------------------------------------------------------------------------- 1 | #ifndef __PWM_H__ 2 | #define __PWM_H__ 3 | 4 | /*pwm.h: function and macro definition of PWM API , driver level */ 5 | /*user_light.h: user interface for light API, user level*/ 6 | /*user_light_adj: API for color changing and lighting effects, user level*/ 7 | 8 | 9 | /*NOTE!! : DO NOT CHANGE THIS FILE*/ 10 | 11 | /*SUPPORT UP TO 8 PWM CHANNEL*/ 12 | #define PWM_CHANNEL_NUM_MAX 8 13 | 14 | struct pwm_param { 15 | uint32 period; 16 | uint32 freq; 17 | uint32 duty[PWM_CHANNEL_NUM_MAX]; //PWM_CHANNEL<=8 18 | }; 19 | 20 | 21 | /* pwm_init should be called only once, for now */ 22 | void pwm_init(uint32 period, uint32 *duty,uint32 pwm_channel_num,uint32 (*pin_info_list)[3]); 23 | void pwm_start(void); 24 | 25 | void pwm_set_duty(uint32 duty, uint8 channel); 26 | uint32 pwm_get_duty(uint8 channel); 27 | void pwm_set_period(uint32 period); 28 | uint32 pwm_get_period(void); 29 | 30 | uint32 get_pwm_version(void); 31 | void set_pwm_debug_en(uint8 print_en); 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /esp8266_sdk/include/smartconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 -2018 Espressif System 3 | * 4 | */ 5 | 6 | #ifndef __SMARTCONFIG_H__ 7 | #define __SMARTCONFIG_H__ 8 | 9 | typedef enum { 10 | SC_STATUS_WAIT = 0, 11 | SC_STATUS_FIND_CHANNEL, 12 | SC_STATUS_GETTING_SSID_PSWD, 13 | SC_STATUS_LINK, 14 | SC_STATUS_LINK_OVER, 15 | } sc_status; 16 | 17 | typedef enum { 18 | SC_TYPE_ESPTOUCH = 0, 19 | SC_TYPE_AIRKISS, 20 | SC_TYPE_ESPTOUCH_AIRKISS, 21 | } sc_type; 22 | 23 | typedef void (*sc_callback_t)(sc_status status, void *pdata); 24 | 25 | const char *smartconfig_get_version(void); 26 | bool smartconfig_start(sc_callback_t cb, ...); 27 | bool smartconfig_stop(void); 28 | bool esptouch_set_timeout(uint8 time_s); //15s~255s, offset:45s 29 | bool smartconfig_set_type(sc_type type); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /esp8266_sdk/include/sntp.h: -------------------------------------------------------------------------------- 1 | #ifndef __SNTP_H__ 2 | #define __SNTP_H__ 3 | 4 | #include "os_type.h" 5 | #ifdef LWIP_OPEN_SRC 6 | #include "lwip/ip_addr.h" 7 | #else 8 | #include "ip_addr.h" 9 | #endif 10 | /** 11 | * get the seconds since Jan 01, 1970, 00:00 (GMT + 8) 12 | */ 13 | uint32 sntp_get_current_timestamp(); 14 | /** 15 | * get real time (GTM + 8 time zone) 16 | */ 17 | char* sntp_get_real_time(long t); 18 | /** 19 | * SNTP get time_zone default GMT + 8 20 | */ 21 | sint8 sntp_get_timezone(void); 22 | /** 23 | * SNTP set time_zone (default GMT + 8) 24 | */ 25 | bool sntp_set_timezone(sint8 timezone); 26 | /** 27 | * Initialize this module. 28 | * Send out request instantly or after SNTP_STARTUP_DELAY(_FUNC). 29 | */ 30 | void sntp_init(void); 31 | /** 32 | * Stop this module. 33 | */ 34 | void sntp_stop(void); 35 | /** 36 | * Initialize one of the NTP servers by IP address 37 | * 38 | * @param numdns the index of the NTP server to set must be < SNTP_MAX_SERVERS 39 | * @param dnsserver IP address of the NTP server to set 40 | */ 41 | void sntp_setserver(unsigned char idx, ip_addr_t *addr); 42 | /** 43 | * Obtain one of the currently configured by IP address (or DHCP) NTP servers 44 | * 45 | * @param numdns the index of the NTP server 46 | * @return IP address of the indexed NTP server or "ip_addr_any" if the NTP 47 | * server has not been configured by address (or at all). 48 | */ 49 | ip_addr_t sntp_getserver(unsigned char idx); 50 | /** 51 | * Initialize one of the NTP servers by name 52 | * 53 | * @param numdns the index of the NTP server to set must be < SNTP_MAX_SERVERS,now sdk support SNTP_MAX_SERVERS = 3 54 | * @param dnsserver DNS name of the NTP server to set, to be resolved at contact time 55 | */ 56 | void sntp_setservername(unsigned char idx, char *server); 57 | /** 58 | * Obtain one of the currently configured by name NTP servers. 59 | * 60 | * @param numdns the index of the NTP server 61 | * @return IP address of the indexed NTP server or NULL if the NTP 62 | * server has not been configured by name (or at all) 63 | */ 64 | char *sntp_getservername(unsigned char idx); 65 | 66 | #define sntp_servermode_dhcp(x) 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /esp8266_sdk/include/spi_flash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) Espressif System 2010 3 | * 4 | */ 5 | 6 | #ifndef SPI_FLASH_H 7 | #define SPI_FLASH_H 8 | 9 | typedef enum { 10 | SPI_FLASH_RESULT_OK, 11 | SPI_FLASH_RESULT_ERR, 12 | SPI_FLASH_RESULT_TIMEOUT 13 | } SpiFlashOpResult; 14 | 15 | typedef struct{ 16 | uint32 deviceId; 17 | uint32 chip_size; // chip size in byte 18 | uint32 block_size; 19 | uint32 sector_size; 20 | uint32 page_size; 21 | uint32 status_mask; 22 | } SpiFlashChip; 23 | 24 | #define SPI_FLASH_SEC_SIZE 4096 25 | 26 | /* Hacked by community */ 27 | extern SpiFlashChip * flashchip; // in ram ROM-BIOS 28 | 29 | uint32 spi_flash_get_id(void); 30 | SpiFlashOpResult spi_flash_erase_sector(uint16 sec); 31 | SpiFlashOpResult spi_flash_write(uint32 des_addr, uint32 *src_addr, uint32 size); 32 | SpiFlashOpResult spi_flash_read(uint32 src_addr, uint32 *des_addr, uint32 size); 33 | 34 | typedef SpiFlashOpResult (* user_spi_flash_read)( 35 | SpiFlashChip *spi, 36 | uint32 src_addr, 37 | uint32 *des_addr, 38 | uint32 size); 39 | 40 | void spi_flash_set_read_func(user_spi_flash_read read); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /esp8266_sdk/include/upgrade.h: -------------------------------------------------------------------------------- 1 | #ifndef __UPGRADE_H__ 2 | #define __UPGRADE_H__ 3 | 4 | #define SPI_FLASH_SEC_SIZE 4096 5 | #define LIMIT_ERASE_SIZE 0x10000 6 | 7 | #define USER_BIN1 0x00 8 | #define USER_BIN2 0x01 9 | 10 | #define UPGRADE_FLAG_IDLE 0x00 11 | #define UPGRADE_FLAG_START 0x01 12 | #define UPGRADE_FLAG_FINISH 0x02 13 | 14 | #define UPGRADE_FW_BIN1 0x00 15 | #define UPGRADE_FW_BIN2 0x01 16 | 17 | typedef void (*upgrade_states_check_callback)(void * arg); 18 | 19 | //#define UPGRADE_SSL_ENABLE 20 | 21 | struct upgrade_server_info { 22 | uint8 ip[4]; 23 | uint16 port; 24 | 25 | uint8 upgrade_flag; 26 | 27 | uint8 pre_version[16]; 28 | uint8 upgrade_version[16]; 29 | 30 | uint32 check_times; 31 | uint8 *url; 32 | 33 | upgrade_states_check_callback check_cb; 34 | struct espconn *pespconn; 35 | }; 36 | 37 | #define UPGRADE_FLAG_IDLE 0x00 38 | #define UPGRADE_FLAG_START 0x01 39 | #define UPGRADE_FLAG_FINISH 0x02 40 | 41 | void system_upgrade_init(); 42 | void system_upgrade_deinit(); 43 | bool system_upgrade(uint8 *data, uint16 len); 44 | 45 | #ifdef UPGRADE_SSL_ENABLE 46 | bool system_upgrade_start_ssl(struct upgrade_server_info *server); // not supported now 47 | #else 48 | bool system_upgrade_start(struct upgrade_server_info *server); 49 | #endif 50 | #endif 51 | -------------------------------------------------------------------------------- /esp8266_sdk/ld/eagle.app.v6.new.1024.app1.ld: -------------------------------------------------------------------------------- 1 | /* This linker script generated from xt-genldscripts.tpp for LSP . */ 2 | /* Linker Script for ld -N */ 3 | MEMORY 4 | { 5 | dport0_0_seg : org = 0x3FF00000, len = 0x10 6 | dram0_0_seg : org = 0x3FFE8000, len = 0x14000 7 | iram1_0_seg : org = 0x40100000, len = 0x8000 8 | irom0_0_seg : org = 0x40201010, len = 0x6B000 9 | } 10 | PHDRS 11 | { 12 | dport0_0_phdr PT_LOAD; 13 | dram0_0_phdr PT_LOAD; 14 | dram0_0_bss_phdr PT_LOAD; 15 | iram1_0_phdr PT_LOAD; 16 | irom0_0_phdr PT_LOAD; 17 | } 18 | 19 | INCLUDE "../ld/eagle.app.v6.new.sections.ld" 20 | 21 | -------------------------------------------------------------------------------- /esp8266_sdk/ld/eagle.app.v6.new.1024.app2.ld: -------------------------------------------------------------------------------- 1 | /* This linker script generated from xt-genldscripts.tpp for LSP . */ 2 | /* Linker Script for ld -N */ 3 | MEMORY 4 | { 5 | dport0_0_seg : org = 0x3FF00000, len = 0x10 6 | dram0_0_seg : org = 0x3FFE8000, len = 0x14000 7 | iram1_0_seg : org = 0x40100000, len = 0x8000 8 | irom0_0_seg : org = 0x40281010, len = 0x6B000 9 | } 10 | 11 | PHDRS 12 | { 13 | dport0_0_phdr PT_LOAD; 14 | dram0_0_phdr PT_LOAD; 15 | dram0_0_bss_phdr PT_LOAD; 16 | iram1_0_phdr PT_LOAD; 17 | irom0_0_phdr PT_LOAD; 18 | } 19 | 20 | INCLUDE "../ld/eagle.app.v6.new.sections.ld" 21 | 22 | -------------------------------------------------------------------------------- /esp8266_sdk/ld/eagle.app.v6.new.2048.ld: -------------------------------------------------------------------------------- 1 | /* flash address starts from 0x40200000 */ 2 | /* 0x1000 reserved for boot, and 0x10 reserved for rom flags */ 3 | 4 | MEMORY 5 | { 6 | dport0_0_seg : org = 0x3FF00000, len = 0x10 7 | dram0_0_seg : org = 0x3FFE8000, len = 0x14000 8 | iram1_0_seg : org = 0x40100000, len = 0x8000 9 | irom0_0_seg : org = 0x40201010, len = 0xE0000 10 | } 11 | 12 | PHDRS 13 | { 14 | dport0_0_phdr PT_LOAD; 15 | dram0_0_phdr PT_LOAD; 16 | dram0_0_bss_phdr PT_LOAD; 17 | iram1_0_phdr PT_LOAD; 18 | irom0_0_phdr PT_LOAD; 19 | } 20 | 21 | INCLUDE "../ld/eagle.app.v6.new.sections.ld" 22 | 23 | 24 | /* For 4MByte Flash */ 25 | /* user1.bin user2.bin spiffs eep system para */ 26 | /* |------------------+--------------------|-----------------|----|----| */ 27 | /* 1024k 1024k 2028k 4k 16k */ 28 | PROVIDE ( _SPIFFS_start = 0x40400000 ); 29 | PROVIDE ( _SPIFFS_end = 0x405FB000 ); 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /esp8266_sdk/ld/eagle.app.v6.new.512.app1.ld: -------------------------------------------------------------------------------- 1 | /* This linker script generated from xt-genldscripts.tpp for LSP . */ 2 | /* Linker Script for ld -N */ 3 | MEMORY 4 | { 5 | dport0_0_seg : org = 0x3FF00000, len = 0x10 6 | dram0_0_seg : org = 0x3FFE8000, len = 0x14000 7 | iram1_0_seg : org = 0x40100000, len = 0x8000 8 | irom0_0_seg : org = 0x40201010, len = 0x2B000 9 | } 10 | 11 | PHDRS 12 | { 13 | dport0_0_phdr PT_LOAD; 14 | dram0_0_phdr PT_LOAD; 15 | dram0_0_bss_phdr PT_LOAD; 16 | iram1_0_phdr PT_LOAD; 17 | irom0_0_phdr PT_LOAD; 18 | } 19 | 20 | INCLUDE "../ld/eagle.app.v6.new.sections.ld" 21 | 22 | -------------------------------------------------------------------------------- /esp8266_sdk/ld/eagle.app.v6.new.512.app2.ld: -------------------------------------------------------------------------------- 1 | /* This linker script generated from xt-genldscripts.tpp for LSP . */ 2 | /* Linker Script for ld -N */ 3 | MEMORY 4 | { 5 | dport0_0_seg : org = 0x3FF00000, len = 0x10 6 | dram0_0_seg : org = 0x3FFE8000, len = 0x14000 7 | iram1_0_seg : org = 0x40100000, len = 0x8000 8 | irom0_0_seg : org = 0x40241010, len = 0x2B000 9 | } 10 | 11 | PHDRS 12 | { 13 | dport0_0_phdr PT_LOAD; 14 | dram0_0_phdr PT_LOAD; 15 | dram0_0_bss_phdr PT_LOAD; 16 | iram1_0_phdr PT_LOAD; 17 | irom0_0_phdr PT_LOAD; 18 | } 19 | 20 | INCLUDE "../ld/eagle.app.v6.new.sections.ld" 21 | 22 | -------------------------------------------------------------------------------- /esp8266_sdk/ld/spiffs.ld.tobedelete: -------------------------------------------------------------------------------- 1 | 2 | /* For 4MByte Flash */ 3 | /* 1MB user1 + 1MB user2 */ 4 | /* spiffs 2028KB */ 5 | /* eeprom 4K + system para 16K = 20KB */ 6 | PROVIDE ( _SPIFFS_start = 0x40400000 ); 7 | PROVIDE ( _SPIFFS_end = 0x405FB000 ); 8 | 9 | 10 | /* For 2MByte Flash */ 11 | /* 1MB user1 + 1MB user2 */ 12 | /* spiffs 492KB at the end of user2 before 20K eeprom+syspara*/ 13 | /* eeprom 4K + system para 16K = 20KB 14 | PROVIDE ( _SPIFFS_start = 0x40380000 ); 15 | PROVIDE ( _SPIFFS_end = 0x403F0000 );*/ 16 | -------------------------------------------------------------------------------- /esp8266_sdk/lib/libat.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libat.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libcrypto.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libespnow.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libespnow.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libhal.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libhal.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libjson.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libjson.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/liblwip.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/liblwip.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libmain.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libmain.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libmesh.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libmesh.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libnet80211.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libnet80211.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libphy.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libphy.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libpp.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libpp.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libpwm.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libpwm.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libsmartconfig.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libsmartconfig.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libssl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libssl.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libupgrade.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libupgrade.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libwpa.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libwpa.a -------------------------------------------------------------------------------- /esp8266_sdk/lib/libwps.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/esp8266_sdk/lib/libwps.a -------------------------------------------------------------------------------- /esp8266_sdk/tools/make_cert.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | class Cert(object): 5 | def __init__(self, name, buff): 6 | self.name = name 7 | self.len = len(buff) 8 | self.buff = buff 9 | pass 10 | 11 | def __str__(self): 12 | out_str = ['\0']*32 13 | for i in range(len(self.name)): 14 | out_str[i] = self.name[i] 15 | out_str = "".join(out_str) 16 | out_str += str(chr(self.len & 0xFF)) 17 | out_str += str(chr((self.len & 0xFF00) >> 8)) 18 | out_str += self.buff 19 | return out_str 20 | pass 21 | 22 | 23 | def main(): 24 | cert_list = [] 25 | file_list = os.listdir(os.getcwd()) 26 | cert_file_list = [] 27 | for _file in file_list: 28 | pos = _file.find(".cer") 29 | if pos != -1: 30 | cert_file_list.append(_file[:pos]) 31 | 32 | for cert_file in cert_file_list: 33 | with open(cert_file+".cer", 'rb') as f: 34 | buff = f.read() 35 | cert_list.append(Cert(cert_file, buff)) 36 | with open('esp_ca_cert.bin', 'wb+') as f: 37 | for _cert in cert_list: 38 | f.write("%s" % _cert) 39 | pass 40 | if __name__ == '__main__': 41 | main() 42 | 43 | -------------------------------------------------------------------------------- /esp8266_sdk/tools/makefile.sh: -------------------------------------------------------------------------------- 1 | # * Redistributions in binary form must reproduce the above copyright 2 | # notice, this list of conditions and the following disclaimer in the 3 | # documentation and/or other materials provided with the distribution. 4 | # * Neither the name of the axTLS project nor the names of its 5 | # contributors may be used to endorse or promote products derived 6 | # from this software without specific prior written permission. 7 | # 8 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 9 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 10 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 11 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 12 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 13 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 14 | # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 15 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 16 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 17 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 18 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 19 | # 20 | 21 | # 22 | # Generate the certificates and keys for testing. 23 | # 24 | 25 | PROJECT_NAME="TLS Project" 26 | 27 | # Generate the openssl configuration files. 28 | cat > ca_cert.conf << EOF 29 | [ req ] 30 | distinguished_name = req_distinguished_name 31 | prompt = no 32 | 33 | [ req_distinguished_name ] 34 | O = $PROJECT_NAME Dodgy Certificate Authority 35 | EOF 36 | 37 | cat > certs.conf << EOF 38 | [ req ] 39 | distinguished_name = req_distinguished_name 40 | prompt = no 41 | 42 | [ req_distinguished_name ] 43 | O = $PROJECT_NAME 44 | CN = 127.0.0.1 45 | EOF 46 | 47 | cat > device_cert.conf << EOF 48 | [ req ] 49 | distinguished_name = req_distinguished_name 50 | prompt = no 51 | 52 | [ req_distinguished_name ] 53 | O = $PROJECT_NAME Device Certificate 54 | EOF 55 | 56 | # private key generation 57 | openssl genrsa -out TLS.ca_key.pem 1024 58 | openssl genrsa -out TLS.key_1024.pem 1024 59 | 60 | # convert private keys into DER format 61 | openssl rsa -in TLS.key_1024.pem -out TLS.key_1024 -outform DER 62 | 63 | # cert requests 64 | openssl req -out TLS.ca_x509.req -key TLS.ca_key.pem -new \ 65 | -config ./ca_cert.conf 66 | openssl req -out TLS.x509_1024.req -key TLS.key_1024.pem -new \ 67 | -config ./certs.conf 68 | 69 | # generate the actual certs. 70 | openssl x509 -req -in TLS.ca_x509.req -out TLS.ca_x509.pem \ 71 | -sha1 -days 5000 -signkey TLS.ca_key.pem 72 | openssl x509 -req -in TLS.x509_1024.req -out TLS.x509_1024.pem \ 73 | -sha1 -CAcreateserial -days 5000 \ 74 | -CA TLS.ca_x509.pem -CAkey TLS.ca_key.pem 75 | 76 | # some cleanup 77 | rm TLS*.req 78 | rm *.conf 79 | 80 | openssl x509 -in TLS.ca_x509.pem -outform DER -out TLS.ca_x509.cer 81 | openssl x509 -in TLS.x509_1024.pem -outform DER -out TLS.x509_1024.cer 82 | 83 | # 84 | # Generate the certificates and keys for encrypt. 85 | # 86 | 87 | # set default cert for use in the client 88 | xxd -i TLS.x509_1024.cer | sed -e \ 89 | "s/TLS_x509_1024_cer/default_certificate/" > cert.h 90 | # set default key for use in the server 91 | xxd -i TLS.key_1024 | sed -e \ 92 | "s/TLS_key_1024/default_private_key/" > private_key.h 93 | -------------------------------------------------------------------------------- /node_main/circular_buffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * circular_buffer.cpp 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | 23 | #include "circular_buffer.h" 24 | 25 | 26 | CircularBuffer::CircularBuffer(size_t capacity) 27 | : beg_index_(0) 28 | , end_index_(0) 29 | , size_(0) 30 | , capacity_(capacity) 31 | { 32 | data_ = new char[capacity]; 33 | } 34 | 35 | CircularBuffer::~CircularBuffer() 36 | { 37 | delete[] data_; 38 | } 39 | 40 | size_t CircularBuffer::write(const char *data, size_t bytes) 41 | { 42 | if (bytes == 0) return 0; 43 | 44 | size_t capacity = capacity_; 45 | size_t bytes_to_write = bytes < (capacity - size_) ? bytes : (capacity - size_); 46 | 47 | // Write in a single step 48 | if (bytes_to_write <= capacity - end_index_) 49 | { 50 | memcpy(data_ + end_index_, data, bytes_to_write); 51 | end_index_ += bytes_to_write; 52 | if (end_index_ == capacity) end_index_ = 0; 53 | } 54 | // Write in two steps 55 | else 56 | { 57 | size_t size_1 = capacity - end_index_; 58 | memcpy(data_ + end_index_, data, size_1); 59 | size_t size_2 = bytes_to_write - size_1; 60 | memcpy(data_, data + size_1, size_2); 61 | end_index_ = size_2; 62 | } 63 | 64 | size_ += bytes_to_write; 65 | return bytes_to_write; 66 | } 67 | 68 | size_t CircularBuffer::read(char *data, size_t bytes) 69 | { 70 | if (bytes == 0) return 0; 71 | 72 | size_t capacity = capacity_; 73 | size_t bytes_to_read = bytes < size_ ? bytes : size_; 74 | 75 | // Read in a single step 76 | if (bytes_to_read <= capacity - beg_index_) 77 | { 78 | memcpy(data, data_ + beg_index_, bytes_to_read); 79 | beg_index_ += bytes_to_read; 80 | if (beg_index_ == capacity) beg_index_ = 0; 81 | } 82 | // Read in two steps 83 | else 84 | { 85 | size_t size_1 = capacity - beg_index_; 86 | memcpy(data, data_ + beg_index_, size_1); 87 | size_t size_2 = bytes_to_read - size_1; 88 | memcpy(data + size_1, data_, size_2); 89 | beg_index_ = size_2; 90 | } 91 | 92 | size_ -= bytes_to_read; 93 | return bytes_to_read; 94 | } 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /node_main/circular_buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * circular_buffer.h 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | 23 | #ifndef __CIRCULAR_BUFFER_H__ 24 | #define __CIRCULAR_BUFFER_H__ 25 | 26 | #include "Arduino.h" 27 | 28 | class CircularBuffer 29 | { 30 | public: 31 | CircularBuffer(size_t capacity); 32 | ~CircularBuffer(); 33 | 34 | size_t size() const { return size_; } 35 | size_t capacity() const { return capacity_; } 36 | // Return number of bytes written. 37 | size_t write(const char *data, size_t bytes); 38 | // Return number of bytes read. 39 | size_t read(char *data, size_t bytes); 40 | 41 | private: 42 | size_t beg_index_, end_index_, size_, capacity_; 43 | char *data_; 44 | }; 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /node_main/eeprom.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | EEPROM.cpp - esp8266 EEPROM emulation 3 | 4 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "Arduino.h" 23 | #include "eeprom.h" 24 | 25 | extern "C" { 26 | #include "c_types.h" 27 | #include "ets_sys.h" 28 | #include "os_type.h" 29 | #include "osapi.h" 30 | #include "spi_flash.h" 31 | } 32 | 33 | #include "esp8266.h" 34 | 35 | EEPROMClass::EEPROMClass(uint32_t sector) 36 | : _sector(sector) 37 | , _data(0) 38 | , _size(0) 39 | , _dirty(false) 40 | { 41 | } 42 | 43 | void EEPROMClass::begin(size_t size) { 44 | if (size <= 0) 45 | return; 46 | if (size > SPI_FLASH_SEC_SIZE) 47 | size = SPI_FLASH_SEC_SIZE; 48 | 49 | if (_data) { 50 | delete[] _data; 51 | } 52 | 53 | _data = new uint8_t[size]; 54 | _size = size; 55 | 56 | noInterrupts(); 57 | spi_flash_read(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast(_data), _size); 58 | interrupts(); 59 | } 60 | 61 | void EEPROMClass::end() { 62 | if (!_size) 63 | return; 64 | 65 | commit(); 66 | if(_data) { 67 | delete[] _data; 68 | } 69 | _data = 0; 70 | _size = 0; 71 | } 72 | 73 | 74 | uint8_t EEPROMClass::read(int address) { 75 | if (address < 0 || (size_t)address >= _size) 76 | return 0; 77 | if(!_data) 78 | return 0; 79 | 80 | return _data[address]; 81 | } 82 | 83 | void EEPROMClass::write(int address, uint8_t value) { 84 | if (address < 0 || (size_t)address >= _size) 85 | return; 86 | if(!_data) 87 | return; 88 | 89 | _data[address] = value; 90 | _dirty = true; 91 | } 92 | 93 | bool EEPROMClass::commit() { 94 | bool ret = false; 95 | if (!_size) 96 | return false; 97 | if(!_dirty) 98 | return true; 99 | if(!_data) 100 | return false; 101 | 102 | noInterrupts(); 103 | if(spi_flash_erase_sector(_sector) == SPI_FLASH_RESULT_OK) { 104 | if(spi_flash_write(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast(_data), _size) == SPI_FLASH_RESULT_OK) { 105 | _dirty = false; 106 | ret = true; 107 | } 108 | } 109 | interrupts(); 110 | 111 | return ret; 112 | } 113 | 114 | uint8_t * EEPROMClass::getDataPtr() { 115 | _dirty = true; 116 | return &_data[0]; 117 | } 118 | 119 | extern "C" uint32_t _SPIFFS_end; 120 | EEPROMClass EEPROM((((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE)); 121 | -------------------------------------------------------------------------------- /node_main/eeprom.h: -------------------------------------------------------------------------------- 1 | /* 2 | EEPROM.cpp - esp8266 EEPROM emulation 3 | 4 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef EEPROM_h 23 | #define EEPROM_h 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | class EEPROMClass { 30 | public: 31 | EEPROMClass(uint32_t sector); 32 | 33 | void begin(size_t size); 34 | uint8_t read(int address); 35 | void write(int address, uint8_t val); 36 | bool commit(); 37 | void end(); 38 | 39 | uint8_t * getDataPtr(); 40 | 41 | template 42 | T &get(int address, T &t) { 43 | if (address < 0 || address + sizeof(T) > _size) 44 | return t; 45 | 46 | memcpy((uint8_t*) &t, _data + address, sizeof(T)); 47 | return t; 48 | } 49 | 50 | template 51 | const T &put(int address, const T &t) { 52 | if (address < 0 || address + sizeof(T) > _size) 53 | return t; 54 | 55 | memcpy(_data + address, (const uint8_t*) &t, sizeof(T)); 56 | _dirty = true; 57 | return t; 58 | } 59 | 60 | protected: 61 | uint32_t _sector; 62 | uint8_t* _data; 63 | size_t _size; 64 | bool _dirty; 65 | }; 66 | 67 | extern EEPROMClass EEPROM; 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /node_main/esp8266.h: -------------------------------------------------------------------------------- 1 | /* 2 | * esp8266.h 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | #ifndef __ESP8266_H_HASHCODE__ 22 | #define __ESP8266_H_HASHCODE__ 23 | 24 | #ifdef __cplusplus 25 | extern "C"{ 26 | #endif 27 | 28 | #include 29 | #include 30 | #include "c_types.h" 31 | #include "ip_addr.h" 32 | #include "eagle_soc.h" 33 | #include "espconn.h" 34 | #include "ets_sys.h" 35 | #include "gpio.h" 36 | #include "mem.h" 37 | #include "os_type.h" 38 | #include "osapi.h" 39 | #include "ping.h" 40 | #include "queue.h" 41 | #include "smartconfig.h" 42 | #include "spi_flash.h" 43 | #include "upgrade.h" 44 | #include "user_interface.h" 45 | 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /node_main/network.h: -------------------------------------------------------------------------------- 1 | /* 2 | * network.h 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | 23 | #ifndef __NETWORK111_H__ 24 | #define __NETWORK111_H__ 25 | 26 | #include "esp8266.h" 27 | #include "Arduino.h" 28 | #include "circular_buffer.h" 29 | 30 | enum 31 | { 32 | WAIT_CONFIG, WAIT_GET_IP, DIED_IN_GET_IP, WAIT_RESOLVE, DIED_IN_RESOLVE, WAIT_CONN_DONE, DIED_IN_CONN, CONNECTED, WAIT_HELLO_DONE, KEEP_ALIVE, DIED_IN_HELLO 33 | }; 34 | 35 | enum 36 | { 37 | E_OK, E_FULL, E_NOT_READY 38 | }; 39 | extern uint8_t conn_status[2]; 40 | extern struct espconn tcp_conn[2]; 41 | extern bool should_enter_user_loop; 42 | extern bool debug_enabled; 43 | 44 | void network_setup(); 45 | void network_normal_mode(int config_flag); 46 | void network_config_mode(); 47 | int network_putc(CircularBuffer *tx_buffer, char c); 48 | int network_puts(CircularBuffer *tx_buffer, char *data, int len); 49 | 50 | extern CircularBuffer *data_stream_rx_buffer; 51 | extern CircularBuffer *data_stream_tx_buffer; 52 | extern CircularBuffer *ota_stream_rx_buffer ; 53 | extern CircularBuffer *ota_stream_tx_buffer ; 54 | 55 | extern uint32_t keepalive_last_recv_time[2]; 56 | 57 | bool extract_ip(uint8_t *input, uint8_t *output); 58 | void format_server_address(uint8_t *input, uint8_t *output); 59 | void fire_reboot(void *arg); 60 | 61 | /// 62 | void start_resolving(void *arg); 63 | void dns_resolved_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /node_main/ota.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ota.cpp 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | 23 | #include "esp8266.h" 24 | #include "Arduino.h" 25 | #include "rpc_stream.h" 26 | #include "base64.h" 27 | #include "eeprom.h" 28 | #include "network.h" 29 | 30 | #define pheadbuffer "Connection: keep-alive\r\n\ 31 | Cache-Control: no-cache\r\n\ 32 | User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 \r\n\ 33 | Accept: */*\r\n\ 34 | Accept-Encoding: gzip,deflate\r\n\ 35 | Accept-Language: zh-CN,eb-US;q=0.8\r\n\r\n" 36 | 37 | bool ota_fini = false; 38 | bool ota_succ = false; 39 | 40 | os_timer_t timer_reboot; 41 | 42 | static void timer_reboot_proc(void *arg) 43 | { 44 | bool res = *(bool *)arg; 45 | wifi_station_disconnect(); 46 | if (res) 47 | { 48 | system_upgrade_reboot(); 49 | } else 50 | { 51 | system_restart(); 52 | } 53 | } 54 | 55 | void ota_response(void *arg) 56 | { 57 | struct upgrade_server_info *server = arg; 58 | 59 | if(server->upgrade_flag == true) 60 | { 61 | Serial1.println("device_upgrade_success\r\n"); 62 | ota_succ = true; 63 | 64 | memset(EEPROM.getDataPtr() + EEP_OTA_RESULT_FLAG, 1, 1); 65 | 66 | 67 | } else 68 | { 69 | Serial1.println("device_upgrade_failed\r\n"); 70 | ota_succ = false; 71 | 72 | memset(EEPROM.getDataPtr() + EEP_OTA_RESULT_FLAG, 2, 1); 73 | } 74 | 75 | EEPROM.commit(); 76 | 77 | os_free(server->url); 78 | server->url = NULL; 79 | os_free(server); 80 | server = NULL; 81 | 82 | ota_fini = true; 83 | 84 | os_timer_setfn(&timer_reboot, timer_reboot_proc, &ota_succ); 85 | os_timer_arm(&timer_reboot, 1000, false); 86 | } 87 | 88 | void ota_start() 89 | { 90 | ota_fini = false; 91 | 92 | //uint8_t user_bin[12] = { 0 }; 93 | int bin_num = 1; 94 | 95 | struct upgrade_server_info *upServer = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info)); 96 | 97 | upServer->pespconn = NULL; 98 | char *esp_server_ip = (EEPROM.getDataPtr() + EEP_OTA_SERVER_IP); 99 | os_memcpy(upServer->ip, esp_server_ip, 4); 100 | 101 | upServer->port = OTA_DOWNLOAD_PORT; 102 | 103 | upServer->check_cb = ota_response; 104 | upServer->check_times = 180000; 105 | 106 | if(upServer->url == NULL) 107 | { 108 | upServer->url = (uint8 *)os_zalloc(1024); 109 | } 110 | 111 | if(system_upgrade_userbin_check() == UPGRADE_FW_BIN1) 112 | { 113 | Serial1.printf("Running user1.bin \r\n\r\n"); 114 | //os_memcpy(user_bin, "user2.bin", 10); 115 | bin_num = 2; 116 | } else if(system_upgrade_userbin_check() == UPGRADE_FW_BIN2) 117 | { 118 | Serial1.printf("Running user2.bin \r\n\r\n"); 119 | //os_memcpy(user_bin, "user1.bin", 10); 120 | bin_num = 1; 121 | } 122 | 123 | char sn[64]; 124 | int len=64; 125 | if(base64_encode(sn, &len, EEPROM.getDataPtr()+EEP_OFFSET_SN, 32) != 0) 126 | { 127 | Serial1.println("base64 encode failed"); 128 | ota_fini = true; 129 | return; 130 | } 131 | os_strcpy(sn + len, "NiNz"); 132 | os_sprintf(upServer->url, 133 | "GET %s/ota/bin?app=%d&sn=%s HTTP/1.1\r\nHost: " IPSTR ":%d\r\n" pheadbuffer "", 134 | OTA_SERVER_URL_PREFIX, bin_num, sn, IP2STR(upServer->ip), OTA_DOWNLOAD_PORT); 135 | 136 | Serial1.println("Upgrade started"); 137 | 138 | response_msg_open(STREAM_CMD,"ota_status"); 139 | stream_print(STREAM_CMD,TYPE_STRING, "\"started\""); 140 | response_msg_close(STREAM_CMD); 141 | 142 | __suli_timer_disable_interrupt(); 143 | 144 | delay(200); 145 | 146 | espconn_disconnect(&tcp_conn[0]); 147 | espconn_disconnect(&tcp_conn[1]); 148 | 149 | 150 | if(system_upgrade_start(upServer) == false) 151 | { 152 | Serial1.println("Upgrade already started."); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /node_main/ota.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ota.h 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | 23 | #ifndef __OTA_H__ 24 | #define __OTA_H__ 25 | 26 | #include "esp8266.h" 27 | 28 | extern bool ota_fini; 29 | extern bool ota_succ; 30 | extern os_timer_t timer_reboot; 31 | 32 | void ota_start(); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /node_main/polarssl/aesni.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file aesni.h 3 | * 4 | * \brief AES-NI for hardware AES acceleration on some Intel processors 5 | * 6 | * Copyright (C) 2013, ARM Limited, All Rights Reserved 7 | * 8 | * This file is part of mbed TLS (https://tls.mbed.org) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with this program; if not, write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | #ifndef POLARSSL_AESNI_H 25 | #define POLARSSL_AESNI_H 26 | 27 | #include "aes.h" 28 | 29 | #define POLARSSL_AESNI_AES 0x02000000u 30 | #define POLARSSL_AESNI_CLMUL 0x00000002u 31 | 32 | #if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && \ 33 | ( defined(__amd64__) || defined(__x86_64__) ) && \ 34 | ! defined(POLARSSL_HAVE_X86_64) 35 | #define POLARSSL_HAVE_X86_64 36 | #endif 37 | 38 | #if defined(POLARSSL_HAVE_X86_64) 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /** 45 | * \brief AES-NI features detection routine 46 | * 47 | * \param what The feature to detect 48 | * (POLARSSL_AESNI_AES or POLARSSL_AESNI_CLMUL) 49 | * 50 | * \return 1 if CPU has support for the feature, 0 otherwise 51 | */ 52 | int aesni_supports( unsigned int what ); 53 | 54 | /** 55 | * \brief AES-NI AES-ECB block en(de)cryption 56 | * 57 | * \param ctx AES context 58 | * \param mode AES_ENCRYPT or AES_DECRYPT 59 | * \param input 16-byte input block 60 | * \param output 16-byte output block 61 | * 62 | * \return 0 on success (cannot fail) 63 | */ 64 | int aesni_crypt_ecb( aes_context *ctx, 65 | int mode, 66 | const unsigned char input[16], 67 | unsigned char output[16] ); 68 | 69 | /** 70 | * \brief GCM multiplication: c = a * b in GF(2^128) 71 | * 72 | * \param c Result 73 | * \param a First operand 74 | * \param b Second operand 75 | * 76 | * \note Both operands and result are bit strings interpreted as 77 | * elements of GF(2^128) as per the GCM spec. 78 | */ 79 | void aesni_gcm_mult( unsigned char c[16], 80 | const unsigned char a[16], 81 | const unsigned char b[16] ); 82 | 83 | /** 84 | * \brief Compute decryption round keys from encryption round keys 85 | * 86 | * \param invkey Round keys for the equivalent inverse cipher 87 | * \param fwdkey Original round keys (for encryption) 88 | * \param nr Number of rounds (that is, number of round keys minus one) 89 | */ 90 | void aesni_inverse_key( unsigned char *invkey, 91 | const unsigned char *fwdkey, int nr ); 92 | 93 | /** 94 | * \brief Perform key expansion (for encryption) 95 | * 96 | * \param rk Destination buffer where the round keys are written 97 | * \param key Encryption key 98 | * \param bits Key size in bits (must be 128, 192 or 256) 99 | * 100 | * \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH 101 | */ 102 | int aesni_setkey_enc( unsigned char *rk, 103 | const unsigned char *key, 104 | size_t bits ); 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /* POLARSSL_HAVE_X86_64 */ 111 | 112 | #endif /* POLARSSL_AESNI_H */ 113 | -------------------------------------------------------------------------------- /node_main/polarssl/base64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file base64.h 3 | * 4 | * \brief RFC 1521 base64 encoding/decoding 5 | * 6 | * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved 7 | * 8 | * This file is part of mbed TLS (https://tls.mbed.org) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with this program; if not, write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | #ifndef POLARSSL_BASE64_H 25 | #define POLARSSL_BASE64_H 26 | 27 | #include 28 | 29 | #define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */ 30 | #define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */ 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /** 37 | * \brief Encode a buffer into base64 format 38 | * 39 | * \param dst destination buffer 40 | * \param dlen size of the buffer 41 | * \param src source buffer 42 | * \param slen amount of data to be encoded 43 | * 44 | * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL. 45 | * *dlen is always updated to reflect the amount 46 | * of data that has (or would have) been written. 47 | * 48 | * \note Call this function with *dlen = 0 to obtain the 49 | * required buffer size in *dlen 50 | */ 51 | int base64_encode( unsigned char *dst, size_t *dlen, 52 | const unsigned char *src, size_t slen ); 53 | 54 | /** 55 | * \brief Decode a base64-formatted buffer 56 | * 57 | * \param dst destination buffer (can be NULL for checking size) 58 | * \param dlen size of the buffer 59 | * \param src source buffer 60 | * \param slen amount of data to be decoded 61 | * 62 | * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or 63 | * POLARSSL_ERR_BASE64_INVALID_CHARACTER if the input data is 64 | * not correct. *dlen is always updated to reflect the amount 65 | * of data that has (or would have) been written. 66 | * 67 | * \note Call this function with *dst = NULL or *dlen = 0 to obtain 68 | * the required buffer size in *dlen 69 | */ 70 | int base64_decode( unsigned char *dst, size_t *dlen, 71 | const unsigned char *src, size_t slen ); 72 | 73 | /** 74 | * \brief Checkup routine 75 | * 76 | * \return 0 if successful, or 1 if the test failed 77 | */ 78 | int base64_self_test( int verbose ); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* base64.h */ 85 | -------------------------------------------------------------------------------- /node_main/polarssl/md5.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file md5.h 3 | * 4 | * \brief MD5 message digest algorithm (hash function) 5 | * 6 | * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved 7 | * 8 | * This file is part of mbed TLS (https://tls.mbed.org) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with this program; if not, write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | #ifndef POLARSSL_MD5_H 25 | #define POLARSSL_MD5_H 26 | 27 | #if !defined(POLARSSL_CONFIG_FILE) 28 | #include "config.h" 29 | #else 30 | #include POLARSSL_CONFIG_FILE 31 | #endif 32 | 33 | #include 34 | 35 | #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) 36 | #include 37 | typedef UINT32 uint32_t; 38 | #else 39 | #include 40 | #endif 41 | 42 | #define POLARSSL_ERR_MD5_FILE_IO_ERROR -0x0074 /**< Read/write error in file. */ 43 | 44 | #if !defined(POLARSSL_MD5_ALT) 45 | // Regular implementation 46 | // 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | /** 53 | * \brief MD5 context structure 54 | */ 55 | typedef struct 56 | { 57 | uint32_t total[2]; /*!< number of bytes processed */ 58 | uint32_t state[4]; /*!< intermediate digest state */ 59 | unsigned char buffer[64]; /*!< data block being processed */ 60 | 61 | unsigned char ipad[64]; /*!< HMAC: inner padding */ 62 | unsigned char opad[64]; /*!< HMAC: outer padding */ 63 | } 64 | md5_context; 65 | 66 | /** 67 | * \brief Initialize MD5 context 68 | * 69 | * \param ctx MD5 context to be initialized 70 | */ 71 | void md5_init( md5_context *ctx ); 72 | 73 | /** 74 | * \brief Clear MD5 context 75 | * 76 | * \param ctx MD5 context to be cleared 77 | */ 78 | void md5_free( md5_context *ctx ); 79 | 80 | /** 81 | * \brief MD5 context setup 82 | * 83 | * \param ctx context to be initialized 84 | */ 85 | void md5_starts( md5_context *ctx ); 86 | 87 | /** 88 | * \brief MD5 process buffer 89 | * 90 | * \param ctx MD5 context 91 | * \param input buffer holding the data 92 | * \param ilen length of the input data 93 | */ 94 | void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen ); 95 | 96 | /** 97 | * \brief MD5 final digest 98 | * 99 | * \param ctx MD5 context 100 | * \param output MD5 checksum result 101 | */ 102 | void md5_finish( md5_context *ctx, unsigned char output[16] ); 103 | 104 | /* Internal use */ 105 | void md5_process( md5_context *ctx, const unsigned char data[64] ); 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #else /* POLARSSL_MD5_ALT */ 112 | #include "md5_alt.h" 113 | #endif /* POLARSSL_MD5_ALT */ 114 | 115 | #ifdef __cplusplus 116 | extern "C" { 117 | #endif 118 | 119 | /** 120 | * \brief Output = MD5( input buffer ) 121 | * 122 | * \param input buffer holding the data 123 | * \param ilen length of the input data 124 | * \param output MD5 checksum result 125 | */ 126 | void md5( const unsigned char *input, size_t ilen, unsigned char output[16] ); 127 | 128 | /** 129 | * \brief Output = MD5( file contents ) 130 | * 131 | * \param path input file name 132 | * \param output MD5 checksum result 133 | * 134 | * \return 0 if successful, or POLARSSL_ERR_MD5_FILE_IO_ERROR 135 | */ 136 | int md5_file( const char *path, unsigned char output[16] ); 137 | 138 | /** 139 | * \brief MD5 HMAC context setup 140 | * 141 | * \param ctx HMAC context to be initialized 142 | * \param key HMAC secret key 143 | * \param keylen length of the HMAC key 144 | */ 145 | void md5_hmac_starts( md5_context *ctx, 146 | const unsigned char *key, size_t keylen ); 147 | 148 | /** 149 | * \brief MD5 HMAC process buffer 150 | * 151 | * \param ctx HMAC context 152 | * \param input buffer holding the data 153 | * \param ilen length of the input data 154 | */ 155 | void md5_hmac_update( md5_context *ctx, 156 | const unsigned char *input, size_t ilen ); 157 | 158 | /** 159 | * \brief MD5 HMAC final digest 160 | * 161 | * \param ctx HMAC context 162 | * \param output MD5 HMAC checksum result 163 | */ 164 | void md5_hmac_finish( md5_context *ctx, unsigned char output[16] ); 165 | 166 | /** 167 | * \brief MD5 HMAC context reset 168 | * 169 | * \param ctx HMAC context to be reset 170 | */ 171 | void md5_hmac_reset( md5_context *ctx ); 172 | 173 | /** 174 | * \brief Output = HMAC-MD5( hmac key, input buffer ) 175 | * 176 | * \param key HMAC secret key 177 | * \param keylen length of the HMAC key 178 | * \param input buffer holding the data 179 | * \param ilen length of the input data 180 | * \param output HMAC-MD5 result 181 | */ 182 | void md5_hmac( const unsigned char *key, size_t keylen, 183 | const unsigned char *input, size_t ilen, 184 | unsigned char output[16] ); 185 | 186 | /** 187 | * \brief Checkup routine 188 | * 189 | * \return 0 if successful, or 1 if the test failed 190 | */ 191 | int md5_self_test( int verbose ); 192 | 193 | #ifdef __cplusplus 194 | } 195 | #endif 196 | 197 | #endif /* md5.h */ 198 | -------------------------------------------------------------------------------- /node_main/polarssl/padlock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file padlock.h 3 | * 4 | * \brief VIA PadLock ACE for HW encryption/decryption supported by some 5 | * processors 6 | * 7 | * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved 8 | * 9 | * This file is part of mbed TLS (https://tls.mbed.org) 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with this program; if not, write to the Free Software Foundation, Inc., 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 | */ 25 | #ifndef POLARSSL_PADLOCK_H 26 | #define POLARSSL_PADLOCK_H 27 | 28 | #include "aes.h" 29 | 30 | #define POLARSSL_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */ 31 | 32 | #if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) 33 | 34 | #ifndef POLARSSL_HAVE_X86 35 | #define POLARSSL_HAVE_X86 36 | #endif 37 | 38 | #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) 39 | #include 40 | typedef INT32 int32_t; 41 | #else 42 | #include 43 | #endif 44 | 45 | #define PADLOCK_RNG 0x000C 46 | #define PADLOCK_ACE 0x00C0 47 | #define PADLOCK_PHE 0x0C00 48 | #define PADLOCK_PMM 0x3000 49 | 50 | #define PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15)) 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /** 57 | * \brief PadLock detection routine 58 | * 59 | * \param feature The feature to detect 60 | * 61 | * \return 1 if CPU has support for the feature, 0 otherwise 62 | */ 63 | int padlock_supports( int feature ); 64 | 65 | /** 66 | * \brief PadLock AES-ECB block en(de)cryption 67 | * 68 | * \param ctx AES context 69 | * \param mode AES_ENCRYPT or AES_DECRYPT 70 | * \param input 16-byte input block 71 | * \param output 16-byte output block 72 | * 73 | * \return 0 if success, 1 if operation failed 74 | */ 75 | int padlock_xcryptecb( aes_context *ctx, 76 | int mode, 77 | const unsigned char input[16], 78 | unsigned char output[16] ); 79 | 80 | /** 81 | * \brief PadLock AES-CBC buffer en(de)cryption 82 | * 83 | * \param ctx AES context 84 | * \param mode AES_ENCRYPT or AES_DECRYPT 85 | * \param length length of the input data 86 | * \param iv initialization vector (updated after use) 87 | * \param input buffer holding the input data 88 | * \param output buffer holding the output data 89 | * 90 | * \return 0 if success, 1 if operation failed 91 | */ 92 | int padlock_xcryptcbc( aes_context *ctx, 93 | int mode, 94 | size_t length, 95 | unsigned char iv[16], 96 | const unsigned char *input, 97 | unsigned char *output ); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* HAVE_X86 */ 104 | 105 | #endif /* padlock.h */ 106 | -------------------------------------------------------------------------------- /node_main/user_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_CONFIG_H__ 2 | #define __USER_CONFIG_H__ 3 | 4 | #define MASS_PRODUCT_FW 0 5 | 6 | #define FW_VERSION "1.2" 7 | 8 | #ifndef FUNCTION_KEY 9 | #define FUNCTION_KEY 0 10 | #endif 11 | #ifndef STATUS_LED 12 | #define STATUS_LED 2 13 | #endif 14 | #ifndef SWITCH_GROVE_POWER 15 | #define SWITCH_GROVE_POWER 15 16 | #endif 17 | 18 | 19 | #ifndef NODE_NAME 20 | #define NODE_NAME "Wio001" 21 | #endif 22 | 23 | #define DATA_SERVER_PORT 8000 24 | #define OTA_SERVER_PORT 8001 25 | #define OTA_DOWNLOAD_PORT 8081 26 | #ifndef OTA_SERVER_URL_PREFIX 27 | #define OTA_SERVER_URL_PREFIX "/v1" 28 | #endif 29 | 30 | /* eeprom slots */ 31 | #define EEP_OFFSET_KEY 0 32 | #define EEP_OFFSET_SN 100 33 | #define EEP_OFFSET_CFG_FLAG 200 34 | #define EEP_OFFSET_SSID 204 35 | #define EEP_OFFSET_PASSWORD 300 36 | #define EEP_DATA_SERVER_IP 400 37 | #define EEP_OTA_SERVER_IP 432 38 | #define EEP_OTA_RESULT_FLAG 464 39 | #define EEP_DATA_SERVER_ADDR 500 40 | #define EEP_OTA_SERVER_ADDR 700 41 | #define EEP_DEBUG_FLAG 900 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /node_main/user_main.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: user_main.c 5 | * 6 | * Description: entry file of user application 7 | * 8 | * Modification history: 9 | * 2015/1/23, v1.0 create this file. 10 | *******************************************************************************/ 11 | 12 | #include "esp8266.h" 13 | #include "Arduino.h" 14 | #include "network.h" 15 | #include "rpc_server.h" 16 | #include "eeprom.h" 17 | 18 | extern void arduino_init(void); 19 | 20 | extern void loop(); 21 | extern void setup(); 22 | 23 | extern "C" 24 | { 25 | void system_phy_set_rfoption(uint8 option); 26 | bool system_os_post(uint8 prio, os_signal_t sig, os_param_t par); 27 | } 28 | 29 | 30 | /** 31 | * This function is needed by new SDK 1.1.0 when linking stage 32 | * 33 | * @param 34 | */ 35 | extern "C" 36 | void user_rf_pre_init() 37 | { 38 | system_phy_set_rfoption(1); //recalibrate the rf when power up 39 | } 40 | 41 | /** 42 | * this function will be linked by core_esp8266_main.cpp - 43 | * loop_wrapper 44 | * 45 | * @param 46 | */ 47 | void wio_setup() 48 | { 49 | //Serial.end(); //ensure the uart0 is idle 50 | EEPROM.begin(4096); 51 | pinMode(FUNCTION_KEY, INPUT); 52 | pinMode(STATUS_LED, OUTPUT); 53 | pinMode(SWITCH_GROVE_POWER, OUTPUT); 54 | digitalWrite(SWITCH_GROVE_POWER, 1); 55 | 56 | //failsafe 57 | struct rst_info *reason = system_get_rst_info(); 58 | uint32_t reason_code = reason->reason; 59 | if (reason_code == REASON_EXCEPTION_RST || reason_code == REASON_WDT_RST || reason_code == REASON_SOFT_WDT_RST) 60 | { 61 | uint8_t v = digitalRead(FUNCTION_KEY); 62 | bool should_failsafe = false; 63 | if (v == 0) 64 | { 65 | delay(1); 66 | v = digitalRead(FUNCTION_KEY); 67 | if (v == 0) 68 | { 69 | should_failsafe = true; 70 | } 71 | } 72 | 73 | if (should_failsafe) 74 | { 75 | digitalWrite(STATUS_LED, 0); 76 | system_upgrade_flag_set(UPGRADE_FLAG_FINISH); 77 | delay(1000); 78 | Serial1.begin(74880); 79 | Serial1.println("will fall back to previous firmware."); 80 | system_upgrade_reboot(); 81 | system_restart(); 82 | } 83 | } 84 | 85 | network_setup(); 86 | 87 | //fix: watch dog caused reboot when Serial1 is enabled for printing debug messages 88 | //Serial1.begin() might affect UART0, which causes UART0's pins can't be used as GPIO again, 89 | //Here we clear the configuration for UART0, if any Grove uses UART0, the rpc_server_init will initialize UART0 then. 90 | U0IE = 0; 91 | 92 | rpc_server_init(); 93 | } 94 | 95 | /** 96 | * this function will be linked by core_esp8266_main.cpp - loop_wrapper 97 | * 98 | * @author Jack (5/23/2015) 99 | * @param 100 | */ 101 | void wio_loop() 102 | { 103 | static bool user_setup_done = false; 104 | static bool smartconfig_pressed = false; 105 | static uint32_t smartconfig_pressed_time = 0; 106 | 107 | uint8_t v = digitalRead(FUNCTION_KEY); 108 | 109 | if(v == 0 && !smartconfig_pressed) 110 | { 111 | smartconfig_pressed_time = system_get_time(); 112 | smartconfig_pressed = true; 113 | } else if(v == 0 && smartconfig_pressed) 114 | { 115 | if(system_get_time() - smartconfig_pressed_time > 2500000) 116 | { 117 | memset(EEPROM.getDataPtr() + EEP_OFFSET_CFG_FLAG, 1, 1); //set the smart config flag 118 | EEPROM.commit(); 119 | Serial1.println("will reboot to config mode"); 120 | digitalWrite(STATUS_LED, 1); 121 | delay(100); 122 | digitalWrite(STATUS_LED, 0); 123 | delay(500); 124 | digitalWrite(STATUS_LED, 1); 125 | system_restart(); 126 | smartconfig_pressed = false; 127 | } 128 | } else 129 | { 130 | smartconfig_pressed = false; 131 | } 132 | 133 | if(conn_status[0] == KEEP_ALIVE || conn_status[1] == KEEP_ALIVE) 134 | { 135 | rpc_server_loop(); 136 | } 137 | 138 | // user loop 139 | if (should_enter_user_loop) 140 | { 141 | if (!user_setup_done) 142 | { 143 | setup(); 144 | user_setup_done = true; 145 | } 146 | suli_soft_timer_loop(); 147 | loop(); 148 | } 149 | } 150 | 151 | /** 152 | * Global function needed by libmain.a when linking 153 | * 154 | * @author Jack (5/23/2015) 155 | * @param 156 | */ 157 | extern "C" 158 | void user_init(void) 159 | { 160 | #if MASS_PRODUCT_FW 161 | //for mass production requirement 162 | os_printf("user_fw_version:%s\n",FW_VERSION); 163 | os_printf("----\n"); 164 | #endif 165 | system_set_os_print(0); 166 | 167 | arduino_init(); 168 | } 169 | 170 | -------------------------------------------------------------------------------- /node_main/wio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wio.h 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | #ifndef __WIO_H_HASHCODE__ 22 | #define __WIO_H_HASHCODE__ 23 | 24 | #include "esp8266.h" 25 | #include "suli2.h" 26 | 27 | #include "rpc_server.h" 28 | #include "rpc_stream.h" 29 | 30 | 31 | 32 | typedef struct variable_s 33 | { 34 | char *var_name; 35 | void *var_ptr; 36 | uint8_t var_type; 37 | struct variable_s *next; 38 | }variable_t; 39 | 40 | typedef void (*rpc_function_t) (String); 41 | typedef struct function_s 42 | { 43 | char *func_name; 44 | rpc_function_t func_ptr; 45 | struct function_s *next; 46 | }function_t; 47 | 48 | 49 | bool __plugin_variable_read(void *class_ptr, char *method_name, void *input_pack); 50 | bool __plugin_variable_write(void *class_ptr, char *method_name, void *input_pack); 51 | 52 | bool __plugin_function_write(void *class_ptr, char *method_name, void *input_pack); 53 | 54 | 55 | 56 | class Wio 57 | { 58 | public: 59 | Wio(); 60 | 61 | // event 62 | static void postEvent(char *event_name); 63 | static void postEvent(char *event_name, bool event_data); 64 | static void postEvent(char *event_name, uint8_t event_data); 65 | static void postEvent(char *event_name, int8_t event_data); 66 | static void postEvent(char *event_name, uint16_t event_data); 67 | static void postEvent(char *event_name, int16_t event_data); 68 | static void postEvent(char *event_name, uint32_t event_data); 69 | static void postEvent(char *event_name, int32_t event_data); 70 | static void postEvent(char *event_name, float event_data); 71 | static void postEvent(char *event_name, char *event_data); 72 | static void postEvent(char *event_name, String &event_data); 73 | 74 | static inline int eventAvailable() 75 | { 76 | return rpc_server_event_queue_size(POP_FROM_INTERNAL_Q); 77 | } 78 | 79 | static bool getEvent(event_t *p_event); 80 | 81 | // variable 82 | variable_t* findVariable(char *var_name); 83 | 84 | void registerVar(char *var_name, bool &var); 85 | void registerVar(char *var_name, uint8_t &var); 86 | void registerVar(char *var_name, int8_t &var); 87 | void registerVar(char *var_name, uint16_t &var); 88 | void registerVar(char *var_name, int16_t &var); 89 | void registerVar(char *var_name, uint32_t &var); 90 | void registerVar(char *var_name, int32_t &var); 91 | void registerVar(char *var_name, float &var); 92 | void registerVar(char *var_name, char *var); 93 | void registerVar(char *var_name, String &event_data); 94 | 95 | // function 96 | function_t* findFunction(char *func_name); 97 | 98 | void registerFunc(char *func_name, rpc_function_t func); 99 | 100 | 101 | 102 | private: 103 | variable_t *p_var_head; 104 | variable_t *p_var_cur; 105 | function_t *p_func_head; 106 | function_t *p_func_cur; 107 | 108 | void _registerVar(char *var_name, void *var_ptr, int var_type); 109 | 110 | 111 | }; 112 | 113 | extern Wio wio; 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /pre_build.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (C) 2015 by seeedstudio 4 | # Author: Jack Shao (jacky.shaoxg@gmail.com) 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import config as server_config 20 | from build_firmware import * 21 | 22 | if __name__ == '__main__': 23 | 24 | build_phase = [1] 25 | app_num = 'ALL' if len(sys.argv) < 2 else sys.argv[1] 26 | user_id = "local_user" if len(sys.argv) < 3 else sys.argv[2] 27 | node_sn = "00000000000000000000" if len(sys.argv) < 4 else sys.argv[3] 28 | node_name = "esp8266_node" if len(sys.argv) < 5 else sys.argv[4] 29 | server_ip = "" if len(sys.argv) < 6 else sys.argv[5] 30 | 31 | server_config.ALWAYS_BUILD_FROM_SRC = True 32 | 33 | if not gen_and_build(build_phase, app_num, user_id, node_sn, node_name, server_ip, None, None): 34 | print get_error_msg() 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /repair/README.md: -------------------------------------------------------------------------------- 1 | # Repair files for Wio Link 2 | 3 | |File Name|Source| 4 | |:--|:--| 5 | |boot_v1.7.bin|[ESP8266_NONOS_SDK](https://github.com/espressif/ESP8266_NONOS_SDK/tree/43dfa5a7f919c3537929c1e36822118414da7d7f/bin)| 6 | |user1.bin|I built it.| 7 | |user2.bin|I built it.| 8 | |esp_init_data_default_v08.bin|[ESP8266_NONOS_SDK](https://github.com/espressif/ESP8266_NONOS_SDK/tree/43dfa5a7f919c3537929c1e36822118414da7d7f/bin)| 9 | |blank.bin|[ESP8266_NONOS_SDK](https://github.com/espressif/ESP8266_NONOS_SDK/tree/43dfa5a7f919c3537929c1e36822118414da7d7f/bin)| 10 | -------------------------------------------------------------------------------- /repair/blank.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/repair/blank.bin -------------------------------------------------------------------------------- /repair/boot_v1.7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/repair/boot_v1.7.bin -------------------------------------------------------------------------------- /repair/esp_init_data_default_v08.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/repair/esp_init_data_default_v08.bin -------------------------------------------------------------------------------- /repair/user1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/repair/user1.bin -------------------------------------------------------------------------------- /repair/user2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/repair/user2.bin -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | psutil==5.9.5 2 | pycrypto==2.6.1 3 | PyJWT==1.7.1 4 | PyYAML==5.4.1 5 | tornado==4.5.3 6 | tornado-cors==0.6.0 7 | -------------------------------------------------------------------------------- /rpc_server/rpc_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rpc_queue.h 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | 23 | #ifndef __RPC_Q_H__ 24 | #define __RPC_Q_H__ 25 | 26 | template class QueueItem; 27 | 28 | template 29 | class Queue 30 | { 31 | public: 32 | Queue() : front(0), back(0), _max_size(100) { } 33 | Queue(int max_size) : front(0), back(0), _max_size(max_size) { } 34 | ~Queue() { } 35 | 36 | bool push(Type); 37 | bool pop(Type *); 38 | bool is_empty() const 39 | { 40 | return front == 0; 41 | } 42 | int get_size() const 43 | { 44 | return _size; 45 | } 46 | 47 | private: 48 | QueueItem *front; 49 | QueueItem *back; 50 | 51 | int _size; 52 | int _max_size; 53 | }; 54 | 55 | template 56 | class QueueItem 57 | { 58 | public: 59 | QueueItem(Type val) { item = val; next = 0;} 60 | friend class Queue; 61 | 62 | private: 63 | Type item; 64 | QueueItem *next; 65 | }; 66 | 67 | template 68 | bool Queue::push(Type val) 69 | { 70 | if (_size >= _max_size) 71 | { 72 | return false; 73 | } 74 | QueueItem *pt = new QueueItem(val); 75 | if (is_empty()) front = back = pt; 76 | else 77 | { 78 | back->next = pt; 79 | back = pt; 80 | } 81 | _size++; 82 | 83 | return true; 84 | } 85 | 86 | template 87 | bool Queue::pop(Type *p_val) 88 | { 89 | if (is_empty()) 90 | { 91 | return false; 92 | } 93 | QueueItem *pt = front; 94 | front = front->next; 95 | *p_val = pt->item; 96 | delete pt; 97 | _size--; 98 | 99 | return true; 100 | } 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /rpc_server/rpc_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rpc_server.h 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef __RPC_SERVER_H__ 23 | #define __RPC_SERVER_H__ 24 | 25 | #include "suli2.h" 26 | 27 | typedef enum 28 | { 29 | TYPE_NONE, TYPE_BOOL, TYPE_UINT8, TYPE_INT8, TYPE_UINT16, TYPE_INT16, TYPE_INT, TYPE_UINT32, TYPE_INT32, TYPE_FLOAT, TYPE_STRING 30 | }type_t; 31 | 32 | typedef enum 33 | { 34 | METHOD_READ, METHOD_WRITE, METHOD_INTERNAL 35 | }method_dir_t; 36 | 37 | enum 38 | { 39 | PARSE_REQ_TYPE, PARSE_GROVE_NAME, PARSE_METHOD, CHECK_ARGS, PRE_PARSE_ARGS, PARSE_ARGS, PARSE_CALL, DIVE_INTO_OTA, WAIT_OTA_DONE, GET_APP_NUM 40 | }; 41 | 42 | enum 43 | { 44 | REQ_GET, REQ_POST, REQ_OTA, REQ_APP_NUM 45 | }; 46 | 47 | enum 48 | { 49 | FROM_DRIVER, FROM_USER_SPACE 50 | }; 51 | 52 | enum 53 | { 54 | POP_FROM_EXTERNAL_Q, POP_FROM_INTERNAL_Q 55 | }; 56 | 57 | typedef bool (*method_ptr_t)(void *class_ptr, char *method_name, void *input); 58 | 59 | #define MAX_INPUT_ARG_LEN 4 60 | typedef struct resource_s 61 | { 62 | char *grove_name; 63 | char *method_name; 64 | method_dir_t rw; 65 | method_ptr_t method_ptr; 66 | void *class_ptr; 67 | uint8_t arg_types[MAX_INPUT_ARG_LEN]; 68 | struct resource_s *next; 69 | }resource_t; 70 | 71 | typedef struct event_s 72 | { 73 | struct event_s *prev; 74 | struct event_s *next; 75 | char *event_name; 76 | //void *event_data; 77 | union 78 | { 79 | uint8_t raw[4]; 80 | uint8_t u8; 81 | uint16_t u16; 82 | uint32_t u32; 83 | bool boolean; 84 | int8_t s8; 85 | int16_t s16; 86 | int32_t s32; 87 | int integer; 88 | float f; 89 | char *p_str; 90 | void *ptr; 91 | }event_data; 92 | int event_data_type; 93 | }event_t; 94 | 95 | void rpc_server_init(); 96 | 97 | void rpc_server_register_method(char *grove_name, char *method_name, method_dir_t rw, method_ptr_t ptr, void *class_ptr, uint8_t *arg_types); 98 | 99 | void rpc_server_register_resources(); 100 | 101 | void rpc_server_register_plugins(); 102 | 103 | void rpc_server_unregister_all(); 104 | 105 | void rpc_server_loop(); 106 | 107 | int rpc_server_event_put_data(event_t *event, void *p_data, int event_data_type); 108 | 109 | void rpc_server_event_report(char *event_name, void *event_data, int event_data_type); 110 | void rpc_server_event_report_from_user(char *event_name, void *event_data, int event_data_type); 111 | 112 | bool rpc_server_event_queue_pop(event_t *event); 113 | bool rpc_server_event_queue_pop_from_internal(event_t *event); 114 | 115 | int rpc_server_event_queue_size(int target = POP_FROM_EXTERNAL_Q); 116 | 117 | 118 | #define ARG_BUFFER_LEN 256 119 | #define NAME_LEN 33 120 | #define CMD_ARG_BUFFER_LEN 64 121 | 122 | 123 | class RPCStreamProcessor 124 | { 125 | public: 126 | RPCStreamProcessor(int buff_len, int stream_id); 127 | 128 | void process_stream(); 129 | 130 | private: 131 | int stream_id; 132 | int req_type; 133 | int parse_stage; 134 | 135 | char *buff; 136 | int offset = 0; 137 | int arg_index = 0; 138 | char grove_name[NAME_LEN]; 139 | char method_name[NAME_LEN]; 140 | char ch; 141 | uint8_t arg_buff[4 * MAX_INPUT_ARG_LEN]; 142 | int arg_offset; 143 | resource_t *p_resource; 144 | 145 | }; 146 | 147 | #endif 148 | 149 | -------------------------------------------------------------------------------- /rpc_server/rpc_stream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * rpc_stream.cpp 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | #include "Arduino.h" 22 | #include "rpc_stream.h" 23 | #include "network.h" 24 | #include "esp8266.h" 25 | 26 | //extern Serial pc; 27 | 28 | void stream_init(int stream_num) 29 | { 30 | 31 | } 32 | 33 | char stream_read(int stream_num) 34 | { 35 | CircularBuffer *rx_buffer = (stream_num == STREAM_DATA) ? data_stream_rx_buffer : ota_stream_rx_buffer; 36 | 37 | if (rx_buffer->size() > 0) 38 | { 39 | InterruptLock lock; 40 | char c; 41 | rx_buffer->read(&c,1); 42 | return c; 43 | } else return NULL; 44 | } 45 | 46 | int stream_write(int stream_num, char c) 47 | { 48 | CircularBuffer *tx_buffer = (stream_num == STREAM_DATA) ? data_stream_tx_buffer : ota_stream_tx_buffer; 49 | return network_putc(tx_buffer, c); 50 | } 51 | 52 | int stream_available(int stream_num) 53 | { 54 | CircularBuffer *rx_buffer = (stream_num == STREAM_DATA) ? data_stream_rx_buffer : ota_stream_rx_buffer; 55 | 56 | size_t sz; 57 | { 58 | InterruptLock lock; 59 | sz = rx_buffer->size(); 60 | } 61 | return sz; 62 | } 63 | 64 | int stream_write_string(int stream_num, char *str, int len) 65 | { 66 | CircularBuffer *tx_buffer = (stream_num == STREAM_DATA) ? data_stream_tx_buffer : ota_stream_tx_buffer; 67 | return network_puts(tx_buffer, str, len); 68 | } 69 | 70 | int stream_print(int stream_num, type_t type, const void *data) 71 | { 72 | char buff[32]; 73 | int len; 74 | 75 | if (data == NULL || type == TYPE_NONE) 76 | { 77 | return E_NOT_READY; 78 | } 79 | 80 | switch (type) 81 | { 82 | case TYPE_BOOL: 83 | case TYPE_UINT8: 84 | sprintf(buff, "%u", *(uint8_t *)data); 85 | break; 86 | case TYPE_UINT16: 87 | sprintf(buff, "%u", *(uint16_t *)data); 88 | break; 89 | case TYPE_UINT32: 90 | sprintf(buff, "%lu", *(uint32_t *)data); 91 | break; 92 | case TYPE_INT8: 93 | sprintf(buff, "%d", *(int8_t *)data); 94 | break; 95 | case TYPE_INT: 96 | sprintf(buff, "%d", *(int *)data); 97 | break; 98 | case TYPE_INT16: 99 | sprintf(buff, "%d", *(int16_t *)data); 100 | break; 101 | case TYPE_INT32: 102 | sprintf(buff, "%ld", *(int32_t *)data); 103 | break; 104 | case TYPE_FLOAT: 105 | //sprintf(buff, "%f", *(float *)data); 106 | dtostrf((*(float *)data), NULL, 2, buff); 107 | break; 108 | case TYPE_STRING: 109 | len = strlen(data); 110 | return stream_write_string(stream_num, (char *)data, len); 111 | default: 112 | break; 113 | } 114 | len = strlen(buff); 115 | return stream_write_string(stream_num, buff, len); 116 | } 117 | 118 | int writer_print(type_t type, const void *data) 119 | { 120 | return stream_print(STREAM_DATA, type, data); 121 | } 122 | 123 | int writer_block_print(type_t type, const void *data) 124 | { 125 | while (stream_print(STREAM_DATA, type, data) == E_FULL) 126 | { 127 | delay(1); 128 | } 129 | return E_OK; 130 | } 131 | 132 | void response_msg_open(int stream_num, char *msg_type) 133 | { 134 | char *msg1 = "{\"msg_type\":\""; 135 | char *msg2 = "\", \"msg\":"; 136 | 137 | stream_write_string(stream_num, msg1, strlen(msg1)); 138 | stream_write_string(stream_num, msg_type, strlen(msg_type)); 139 | stream_write_string(stream_num, msg2, strlen(msg2)); 140 | } 141 | 142 | void response_msg_append_400(int stream_num) 143 | { 144 | char *msg = ", \"status\": 400"; 145 | stream_write_string(stream_num, msg, strlen(msg)); 146 | } 147 | 148 | void response_msg_append_404(int stream_num) 149 | { 150 | char *msg = ", \"status\": 404"; 151 | stream_write_string(stream_num, msg, strlen(msg)); 152 | } 153 | 154 | 155 | void response_msg_close(int stream_num) 156 | { 157 | char *msg3 = "}\r\n"; 158 | 159 | stream_write_string(stream_num, msg3, strlen(msg3)); 160 | } 161 | 162 | -------------------------------------------------------------------------------- /rpc_server/rpc_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rpc_stream.h 3 | * 4 | * Copyright (c) 2012 seeed technology inc. 5 | * Website : www.seeed.cc 6 | * Author : Jack Shao (jacky.shaoxg@gmail.com) 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | 23 | #ifndef __STREAMxxx_H__ 24 | #define __STREAMxxx_H__ 25 | 26 | #include "suli2.h" 27 | #include "rpc_server.h" 28 | 29 | enum 30 | { 31 | STREAM_DATA, STREAM_CMD 32 | }; 33 | 34 | void stream_init(int stream_num); 35 | 36 | char stream_read(int stream_num); 37 | 38 | int stream_write(int stream_num, char c); 39 | int stream_write_string(int stream_num, char *str, int len); 40 | 41 | int stream_available(int stream_num); 42 | 43 | int stream_print(int stream_num, type_t type, const void *data); 44 | //data stream print 45 | int writer_print(type_t type, const void *data); 46 | //data stream print, blocking model, this function can not be call in an ISR 47 | int writer_block_print(type_t type, const void *data); 48 | 49 | void response_msg_open(int stream_num, char *msg_type); 50 | void response_msg_append_400(int stream_num); 51 | void response_msg_append_404(int stream_num); 52 | void response_msg_close(int stream_num); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /templates/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 |

Hey there,

12 |

You're from IP address {{ip}}

13 | 14 | 15 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -e ./wio_link_git_clone ] 4 | then 5 | echo "Already cloned" 6 | cd ./wio_link_git_clone/ 7 | else 8 | echo "Now clone the repo..." 9 | git clone https://github.com/Seeed-Studio/Wio_Link.git wio_link_git_clone 10 | cd ./wio_link_git_clone/ 11 | git submodule init 12 | fi 13 | 14 | #git checkout dev 15 | git pull 16 | git submodule update 17 | supervisorctl stop esp8266 18 | 19 | if [ ! -d ../esp8266_iot_node ] 20 | then 21 | mkdir -p ../esp8266_iot_node 22 | cd ../esp8266_iot_node 23 | cp -rf ../wio_link_git_clone/* ./ 24 | rm -rf ./grove_drivers/grove_example 25 | else 26 | cd ../esp8266_iot_node 27 | mv database.db database.db.bak 28 | mv config.py config.py.bak 29 | cp -rf ../wio_link_git_clone/* ./ 30 | mv database.db.bak database.db 31 | mv config.py.bak config.py 32 | rm -rf ./grove_drivers/grove_example 33 | fi 34 | 35 | python ./scan_drivers.py 36 | supervisorctl start esp8266 -------------------------------------------------------------------------------- /users_build/local_user_00000000000000000000/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "wio.h" 2 | #include "suli2.h" 3 | #include "Main.h" 4 | #include "grove_oled_12864.h" 5 | 6 | int pinsda = 4; 7 | int pinscl = 5; 8 | GroveOLED12864 *oled; 9 | 10 | float celsius_degree = 0.0f; 11 | 12 | uint32_t last_time; 13 | 14 | 15 | void setup() 16 | { 17 | oled = new GroveOLED12864(pinsda, pinscl); 18 | oled->write_clear(); 19 | oled->write_string(0,0,"Temp: "); 20 | last_time = millis(); 21 | Serial1.println("setup done"); 22 | } 23 | 24 | void loop() 25 | { 26 | uint32_t t = millis(); 27 | if (t - last_time > 2000) 28 | { 29 | last_time = t; 30 | GroveTempHumD1_ins->read_temperature(&celsius_degree); 31 | oled->write_float(0, 6, celsius_degree, 2); 32 | Serial1.print("celsius_degree: "); 33 | Serial1.println(celsius_degree); 34 | } 35 | } 36 | 37 | 38 | /* The following is an exmaple for ULB */ 39 | /*int var1 = 10; 40 | float f = 123.45; 41 | String s; 42 | uint32_t time; 43 | 44 | void setup() 45 | { 46 | s = "this is a string..."; 47 | wio.registerVar("var1", var1); 48 | wio.registerVar("var2", f); 49 | wio.registerVar("var3", s); 50 | time = millis(); 51 | } 52 | 53 | void loop() 54 | { 55 | if (millis() - time > 1000) 56 | { 57 | time = millis(); 58 | Serial1.println(var1); 59 | } 60 | }*/ 61 | -------------------------------------------------------------------------------- /users_build/local_user_00000000000000000000/connection_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "board_name": "Wio Link v1.0", 3 | "connections": [ 4 | {"sku": "101020019-ffff", "port": "D1"} 5 | ] 6 | } -------------------------------------------------------------------------------- /users_build/local_user_00000000000000000000/user1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/users_build/local_user_00000000000000000000/user1.bin -------------------------------------------------------------------------------- /users_build/local_user_00000000000000000000/user2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_Link/f6e2bf32d680a31c80859fad32b43251cd592efb/users_build/local_user_00000000000000000000/user2.bin -------------------------------------------------------------------------------- /wio_server.conf: -------------------------------------------------------------------------------- 1 | [program:wio] 2 | directory=/root/wio/ 3 | command=python /root/wio/server.py 4 | autorestart=true 5 | user=root 6 | redirect_stderr=true 7 | stdout_logfile=/root/supervisor_log/log.txt 8 | stderr_logfile=/root/supervisor_log/err.txt 9 | environment=PATH="/opt/xtensa-lx106-elf/bin:%(ENV_PATH)s" 10 | --------------------------------------------------------------------------------