├── .github └── workflows │ └── sync_issues.yml ├── .gitlab-ci.yml ├── .travis.yml ├── License.txt ├── README.md ├── UART_Interface.cpp ├── UART_Interface.h ├── WS2812 └── WS2812.ino ├── board_config.h ├── ethernet.cpp ├── ethernet.h ├── examples ├── AT_bypass │ └── AT_bypass.ino ├── CallUp │ └── CallUp.ino ├── Check_battery │ └── Check_battery.ino ├── GNSS │ ├── GNSS_DataFlowMode │ │ └── GNSS_DataFlowMode.ino │ ├── GNSS_NMEA │ │ └── GNSS_NMEA.ino │ └── GNSS_Show_Coordinate │ │ └── GNSS_Show_Coordinate.ino ├── GroveUART │ └── GroveUART.ino ├── RSSI │ └── RSSI.ino ├── SDCard │ ├── CardInfo │ │ └── CardInfo.ino │ ├── Datalogger │ │ └── Datalogger.ino │ ├── DumpFile │ │ └── DumpFile.ino │ ├── Files │ │ └── Files.ino │ ├── ReadWrite │ │ └── ReadWrite.ino │ └── listfiles │ │ └── listfiles.ino ├── SMSRead │ └── SMSRead.ino ├── SMSSend │ └── SMSSend.ino ├── TCPConnect │ └── TCPConnect.ino ├── TimerInterrupt │ └── TimerInterrupt.ino └── sleepWakeupControl │ └── sleepWakeupControl.ino ├── gnss.cpp ├── gnss.h ├── img ├── boardManager.png └── zadig.png ├── keywords.txt ├── library.properties ├── stm32f4_ws2812.cpp ├── stm32f4_ws2812.h ├── wio_tracker.cpp └── wio_tracker.h /.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 -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | build: 2 | tags: 3 | - nas 4 | script: 5 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh 6 | - chmod +x seeed-arduino-ci.sh 7 | - bash $PWD/seeed-arduino-ci.sh test 8 | 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: generic 3 | dist: bionic 4 | sudo: false 5 | cache: 6 | directories: 7 | - ~/arduino_ide 8 | - ~/.arduino15/packages/ 9 | 10 | before_install: 11 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh 12 | 13 | script: 14 | - chmod +x seeed-arduino-ci.sh 15 | - cat $PWD/seeed-arduino-ci.sh 16 | - bash $PWD/seeed-arduino-ci.sh test 17 | 18 | notifications: 19 | email: 20 | on_success: change 21 | on_failure: change 22 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Seeed Technology Co., Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Wio_Tracker_LTE [![Build Status](https://travis-ci.com/Seeed-Studio/Wio_LTE_Arduino_Library.svg?branch=master)](https://travis-ci.com/Seeed-Studio/Wio_LTE_Arduino_Library) 2 | Wio Tracker LTE is boards combined with STM32F405RGT6 and quectel EC21(4G/3G/GPS) module. 3 | 4 | ![](https://statics3.seeedstudio.com/seeed/file/2017-12/bazaar649820_img_2639a.jpg) 5 | 6 | [Wio LTE AU Version][1] 7 | 8 | [Wio LTE EU Version][2] 9 | 10 | [Wio LTE US Version][3] 11 | 12 | [Wio LTE JP Version][4] 13 | 14 | 15 | Install USB drive 16 | === 17 | 18 | **Windows Users**: Most versions of Windows won't automatically load the built-in driver for USB com ports. You'll have to download ST's USB driver: 19 | 20 | Non-Windows XP [Users download version 1.4.0 drivers](http://www.espruino.com/files/stm32_vcp_1.4.0.zip). Unzip the file, run the executable, and then go to ```C:\Program Files (x86)\STMicroelectronics\Software\Virtual comport driver``` in Windows Explorer and double-click either ```dpinst_amd64.exe``` for 64 bit systems, or ```dpinst_x86.exe``` for 32 bit. 21 | 22 | Windows XP [Users download version 1.3.1 drivers](http://www.espruino.com/files/stm32_vcp_1.3.1.zip). Unzip the file, run ```VCP_V1.3.1_Setup.exe```, and then go to ```C:\Program Files\STMicroelectronics\Software\Virtual comport driver``` in Windows Explorer and double-click the executable. 23 | 24 | **Linux users** to ensure that you have the correct permissions to connect as a normal user you'll need to copy the file [45-espruino.rules](https://github.com/espruino/Espruino/blob/master/misc/45-espruino.rules) to ```/etc/udev/rules.d```, reload rules with ```udevadm control --reload-rules```, and ensure your user is in the plugdev group (you can check by typing ```groups```). You add it by typing ```sudo adduser $USER plugdev``` and then logging out and back in. Arch Linux users need to add their user to ```uucp``` and ```lock``` groups instead. 25 | 26 | **Mac OS X and Chromebook Users**: The board will just plug in and work, without drivers! 27 | 28 | Change dfu driver 29 | === 30 | 31 | **For windows users**: Press and hold BOOT button and connect to computer you will see ***STM32 Device in DFU Mode*** at device manager, this say that you need to use [zadig_xx.exe](http://zadig.akeo.ie/) to change DFU driver from ***STTub30*** to ***WinUSB*** see bellow.
32 | 33 | ![zadig](img/zadig.png "zadig") 34 | 35 | Usage 36 | === 37 | 1.Install Arduino IDE.
38 | 2.[Install Wio LTE library](https://github.com/Seeed-Studio/Seeed_Platform)
39 | Copy and paste the json URL to Arduino preference 40 | 41 | ``` 42 | https://raw.githubusercontent.com/Seeed-Studio/Seeed_Platform/master/package_seeeduino_boards_index.json 43 | ``` 44 | 45 | ![](img/boardManager.png) 46 | 47 | 3.Download this repo to your Arduino libraries' path.
48 | 4.Choose a example to compile.
49 | 5.Before connect USB cable to Computer press and hold BOOT button, in order to access ***STM BOOLARDER*** mode.
50 | 6.Verify and upload Arduino sketch.
51 | 52 | ## Go to [**Seeed WiKi**](http://wiki.seeed.cc/Wio_LTE_Cat.1/#play-with-arduino) for getting started. 53 | 54 | 55 | 56 | ---- 57 | This software is written by Lambor for seeed studio and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.
58 | 59 | Contributing to this software is warmly welcomed. You can do this basically by
60 | [forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
61 | for operating guide). Adding change log and your contact into file header is encouraged.
62 | Thanks for your contribution. 63 | 64 | Seeed is a hardware innovation platform for makers to grow inspirations into differentiating products. By working closely with technology providers of all scale, Seeed provides accessible technologies with quality, speed and supply chain knowledge. When prototypes are ready to iterate, Seeed helps productize 1 to 1,000 pcs using in-house engineering, supply chain management and agile manufacture forces. Seeed also team up with incubators, Chinese tech ecosystem, investors and distribution channels to portal Maker startups beyond. 65 | 66 | 67 | 68 | 69 | [![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/Wio_LTE_Arduino_Library)](https://github.com/igrigorik/ga-beacon) 70 | 71 | 72 | [1]:https://www.seeedstudio.com/Wio-LTE-AU-Version--4G%2C-Cat.1%2C-GNSS%2C-Espruino-Compatible-p-2999.html 73 | [2]:https://www.seeedstudio.com/Wio-LTE-EU-Version-4G%2C-Cat.1%2C-GNSS%2C-Espruino-Compatible-p-2998.html 74 | [3]:https://www.seeedstudio.com/Wio-LTE-US-Version-4G%2C-Cat.1%2C-GNSS%2C-JavaScript%28Espruino%29-Compatible-p-2957.html 75 | [4]:https://www.seeedstudio.com/Wio-LTE-JP-Version-4G%2C-Cat.1%2C-Espruino-Compatible-p-3018.html 76 | -------------------------------------------------------------------------------- /UART_Interface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | UART_Interface.cpp 3 | A library for Arduino UART Interface 4 | 5 | Copyright (c) 2017 Seeed Technology Co., Ltd. 6 | Website : www.seeed.cc 7 | Author : lawliet zou, lambor 8 | Create Time: April 2017 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #include "UART_Interface.h" 33 | 34 | 35 | void serialPort_init() { 36 | MODULE_PORT.begin(115200); 37 | } 38 | 39 | void AT_bypass() { 40 | while (MODULE_PORT.available()) { 41 | serialDebug.write(MODULE_PORT.read()); 42 | } 43 | while (SerialUSB.available()) { 44 | MODULE_PORT.write(SerialUSB.read()); 45 | } 46 | } 47 | 48 | int check_readable() { 49 | return MODULE_PORT.available(); 50 | } 51 | 52 | int wait_readable(int wait_time) { 53 | unsigned long timerStart; 54 | int dataLen = 0; 55 | timerStart = millis(); 56 | while ((unsigned long)(millis() - timerStart) > wait_time * 1000UL) { 57 | delay(500); 58 | dataLen = check_readable(); 59 | if (dataLen > 0) { 60 | break; 61 | } 62 | } 63 | return dataLen; 64 | } 65 | 66 | void flush_serial() { 67 | while (check_readable()) { 68 | MODULE_PORT.read(); 69 | } 70 | } 71 | 72 | uint16_t read_string_line(char* buffer, int count, unsigned int timeout, unsigned int chartimeout) { 73 | uint16_t i = 0; 74 | bool is_timeout = false; 75 | unsigned long timerStart, prevChar; 76 | timerStart = millis(); 77 | prevChar = 0; 78 | while (1) { 79 | while (check_readable()) { 80 | char c = MODULE_PORT.read(); 81 | prevChar = millis(); 82 | buffer[i++] = c; 83 | if ((i >= count) || ('\n' == c) || ('\0' == c)) { 84 | break; 85 | } 86 | } 87 | if (i >= count) { 88 | break; 89 | } 90 | if ((unsigned long)(millis() - timerStart) > timeout * 1000UL) { 91 | break; 92 | } 93 | //If interchar Timeout => return FALSE. So we can return sooner from this function. Not DO it if we dont recieve at least one char (prevChar <> 0) 94 | if (((unsigned long)(millis() - prevChar) > chartimeout) && (prevChar != 0)) { 95 | break; 96 | } 97 | } 98 | return (uint16_t)(i - 1); 99 | } 100 | 101 | uint16_t read_string_until(char* buffer, int count, char* pattern, unsigned int timeout, unsigned int chartimeout) { 102 | uint16_t i = 0; 103 | uint8_t sum = 0; 104 | uint8_t len = strlen(pattern); 105 | bool is_timeout = false; 106 | unsigned long timerStart, prevChar; 107 | 108 | timerStart = millis(); 109 | prevChar = 0; 110 | while (1) { 111 | if (check_readable()) { 112 | char c = MODULE_PORT.read(); 113 | prevChar = millis(); 114 | buffer[i++] = c; 115 | if (i >= count) { 116 | break; 117 | } 118 | sum = (c == pattern[sum]) ? sum + 1 : 0; 119 | if (sum == len) { 120 | break; 121 | } 122 | } 123 | if (i >= count) { 124 | break; 125 | } 126 | if ((unsigned long)(millis() - timerStart) > timeout * 1000UL) { 127 | break; 128 | } 129 | //If interchar Timeout => return FALSE. So we can return sooner from this function. Not DO it if we dont recieve at least one char (prevChar <> 0) 130 | if (((unsigned long)(millis() - prevChar) > chartimeout) && (prevChar != 0)) { 131 | break; 132 | } 133 | } 134 | return (uint16_t)(i - 1); 135 | } 136 | 137 | uint16_t read_buffer(char* buffer, int count, unsigned int timeout, unsigned int chartimeout) { 138 | uint16_t i = 0; 139 | bool is_timeout = false; 140 | unsigned long timerStart, prevChar; 141 | timerStart = millis(); 142 | prevChar = 0; 143 | while (1) { 144 | if (check_readable()) { 145 | char c = MODULE_PORT.read(); 146 | prevChar = millis(); 147 | buffer[i++] = c; 148 | if (i >= count) { 149 | break; 150 | } 151 | } 152 | if (i >= count) { 153 | break; 154 | } 155 | if ((unsigned long)(millis() - timerStart) > timeout * 1000UL) { 156 | break; 157 | } 158 | //If interchar Timeout => return FALSE. So we can return sooner from this function. Not DO it if we dont recieve at least one char (prevChar <> 0) 159 | if (((unsigned long)(millis() - prevChar) > chartimeout) && (prevChar != 0)) { 160 | break; 161 | } 162 | } 163 | return (uint16_t)(i - 1); 164 | } 165 | 166 | void clean_buffer(char* buffer, int count) { 167 | for (int i = 0; i < count; i++) { 168 | buffer[i] = '\0'; 169 | } 170 | } 171 | 172 | //HACERR quitar esta funcion ? 173 | void send_byte(uint8_t data) { 174 | MODULE_PORT.write(data); 175 | } 176 | 177 | void send_char(const char c) { 178 | MODULE_PORT.write(c); 179 | } 180 | 181 | void send_cmd(const char* cmd) { 182 | for (uint16_t i = 0; i < strlen(cmd); i++) { 183 | send_byte(cmd[i]); 184 | } 185 | } 186 | 187 | void send_cmd(const __FlashStringHelper* cmd) { 188 | int i = 0; 189 | const char* ptr = (const char*) cmd; 190 | while (pgm_read_byte(ptr + i) != 0x00) { 191 | send_byte(pgm_read_byte(ptr + i++)); 192 | } 193 | } 194 | 195 | void send_cmd_P(const char* cmd) { 196 | while (pgm_read_byte(cmd) != 0x00) { 197 | send_byte(pgm_read_byte(cmd++)); 198 | } 199 | } 200 | 201 | boolean Test_AT(void) { 202 | return check_with_cmd("AT\r\n", "OK", CMD); 203 | } 204 | 205 | void send_End_Mark(void) { 206 | send_byte((char)26); 207 | } 208 | 209 | boolean wait_for_resp(const char* resp, DataType type, unsigned int timeout, unsigned int chartimeout, bool debug) { 210 | int len = strlen(resp); 211 | int sum = 0; 212 | unsigned long timerStart, prevChar; //prevChar is the time when the previous Char has been read. 213 | timerStart = millis(); 214 | prevChar = 0; 215 | while (1) { 216 | if (check_readable()) { 217 | char c = MODULE_PORT.read(); 218 | 219 | if (debug) { 220 | SerialUSB.print(c); 221 | } 222 | 223 | prevChar = millis(); 224 | sum = (c == resp[sum]) ? sum + 1 : 0; 225 | if (sum == len) { 226 | break; 227 | } 228 | } 229 | if ((unsigned long)(millis() - timerStart) > timeout * 1000UL) { 230 | return false; 231 | } 232 | //If interchar Timeout => return FALSE. So we can return sooner from this function. 233 | if (((unsigned long)(millis() - prevChar) > chartimeout) && (prevChar != 0)) { 234 | return false; 235 | } 236 | 237 | } 238 | #ifdef UART_DEBUG 239 | serialDebug.println(); 240 | #endif 241 | //If is a CMD, we will finish to read buffer. 242 | if (type == CMD) { 243 | flush_serial(); 244 | } 245 | return true; 246 | } 247 | 248 | 249 | boolean check_with_cmd(const char* cmd, const char* resp, DataType type, unsigned int timeout, unsigned int chartimeout, 250 | bool debug) { 251 | send_cmd(cmd); 252 | return wait_for_resp(resp, type, timeout, chartimeout, debug); 253 | } 254 | 255 | //HACERR que tambien la respuesta pueda ser FLASH STRING 256 | boolean check_with_cmd(const __FlashStringHelper* cmd, const char* resp, DataType type, unsigned int timeout, 257 | unsigned int chartimeout, bool debug) { 258 | send_cmd(cmd); 259 | return wait_for_resp(resp, type, timeout, chartimeout, debug); 260 | } 261 | -------------------------------------------------------------------------------- /UART_Interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | EC21_Common.h 3 | A library for SeeedStudio Wio Tracker 4 | 5 | Copyright (c) 2017 Seeed Technology Co., Ltd. 6 | Website : www.seeed.cc 7 | Author : lawliet zou, lambor 8 | Create Time: April 2017 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #ifndef __UART_INTERFACE_H__ 33 | #define __UART_INTERFACE_H__ 34 | 35 | #include 36 | #include 37 | 38 | #define MODULE_PORT Serial1 // UART2 39 | #define serialDebug SerialUSB 40 | 41 | #define DEFAULT_TIMEOUT 5 //seconds 42 | #define DEFAULT_INTERCHAR_TIMEOUT 3000 //miliseconds 43 | 44 | 45 | 46 | #if(1==UART_DEBUG) 47 | #define ERROR(x) SerialUSB.println(x) 48 | #define DEBUG(x) SerialUSB.println(x) 49 | #define DEBUG_BYTE(x) SerialUSB.write(x) 50 | #else 51 | #define ERROR(x) 52 | #define DEBUG(x) 53 | #define DEBUG_BYTE(x) 54 | #endif 55 | 56 | enum DataType { 57 | CMD = 0, 58 | DATA = 1, 59 | }; 60 | 61 | void serialPort_init(); 62 | void AT_bypass(); 63 | int check_readable(); 64 | int wait_readable(int wait_time); 65 | void flush_serial(); 66 | uint16_t read_string_line(char* buffer, int count, unsigned int timeout = DEFAULT_TIMEOUT, 67 | unsigned int chartimeout = DEFAULT_INTERCHAR_TIMEOUT); 68 | uint16_t read_string_until(char* buffer, int count, char* pattern, unsigned int timeout = DEFAULT_TIMEOUT, 69 | unsigned int chartimeout = DEFAULT_INTERCHAR_TIMEOUT); 70 | uint16_t read_buffer(char* buffer, int count, unsigned int timeout = DEFAULT_TIMEOUT, 71 | unsigned int chartimeout = DEFAULT_INTERCHAR_TIMEOUT); 72 | void clean_buffer(char* buffer, int count); 73 | void send_byte(uint8_t data); 74 | void send_char(const char c); 75 | void send_cmd(const char* cmd); 76 | void send_cmd(const __FlashStringHelper* cmd); 77 | void send_cmd_P(const char* cmd); 78 | boolean Test_AT(void); 79 | void send_End_Mark(void); 80 | boolean wait_for_resp(const char* resp, DataType type, unsigned int timeout = DEFAULT_TIMEOUT, 81 | unsigned int chartimeout = DEFAULT_INTERCHAR_TIMEOUT, bool debug = false); 82 | boolean check_with_cmd(const char* cmd, const char* resp, DataType type, unsigned int timeout = DEFAULT_TIMEOUT, 83 | unsigned int chartimeout = DEFAULT_INTERCHAR_TIMEOUT * 5, bool debug = false); 84 | boolean check_with_cmd(const __FlashStringHelper* cmd, const char* resp, DataType type, 85 | unsigned int timeout = DEFAULT_TIMEOUT, unsigned int chartimeout = DEFAULT_INTERCHAR_TIMEOUT, bool debug = false); 86 | #endif 87 | -------------------------------------------------------------------------------- /WS2812/WS2812.ino: -------------------------------------------------------------------------------- 1 | #include "stm32f4_ws2812.h" 2 | #include "wio_tracker.h" 3 | 4 | #define LEN_NUM 1 5 | 6 | WioTracker wio = WioTracker(); 7 | WS2812 strip = WS2812(LEN_NUM, wio.RGB_LED_PIN); 8 | 9 | void setup() { 10 | // Set RGB LED power pin high 11 | #if defined(WIO_TRACKER_LTE_V12) 12 | pinMode(wio.RGB_LED_PWR_PIN, OUTPUT); 13 | digitalWrite(wio.RGB_LED_PWR_PIN, HIGH); 14 | #endif 15 | strip.begin(); 16 | strip.brightness = 20; 17 | } 18 | 19 | void loop() { 20 | strip.RGBCycle(1000); 21 | strip.rainbowCycle(20); 22 | } 23 | -------------------------------------------------------------------------------- /board_config.h: -------------------------------------------------------------------------------- 1 | #ifndef BOARD_CONFIG_H_ 2 | #define BOARD_CONFIG_H_ 3 | 4 | #define UART_DEBUG (false) 5 | #define WIO_TRACKER_LTE_V11 (0) 6 | #define WIO_TRACKER_LTE_V12 (1) 7 | 8 | // Module power switch 9 | #define MODULE_PWR_ON (1) 10 | #define GROVE_PWR_ON (1) 11 | #define CODEC_PWR_ON (1) 12 | #define GNSS_ON (1) 13 | #define ANTENNA_PWR_ON (1) 14 | #define RGB_LED_ON (1) 15 | 16 | #endif -------------------------------------------------------------------------------- /ethernet.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ethernet.cpp 3 | 4 | Copyright (c) 2017 Seeed Technology Co., Ltd. 5 | Website : www.seeed.cc 6 | Author : lambor 7 | Create Time: July 2017 8 | Change Log : 9 | 10 | The MIT License (MIT) 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy 13 | of this software and associated documentation files (the "Software"), to deal 14 | in the Software without restriction, including without limitation the rights 15 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 | copies of the Software, and to permit persons to whom the Software is 17 | furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in 20 | all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 | THE SOFTWARE. 29 | */ 30 | 31 | #include "ethernet.h" 32 | 33 | bool Ethernet::init(void) { 34 | bool ret = false; 35 | uint32_t timeStart = 0; 36 | 37 | //AT+CPIN? 38 | timeStart = millis(); 39 | while (!check_with_cmd("AT+CPIN?\r\n", "+CPIN: READY", CMD, 1)) { 40 | if (millis() - timeStart > 10000) { 41 | return false; 42 | } 43 | delay(1000); 44 | } 45 | 46 | //AT+CREG? 47 | timeStart = millis(); 48 | while (!check_with_cmd("AT+CREG?\r\n", "+CREG: 0,1", CMD, 1) && 49 | !check_with_cmd("AT+CREG?\r\n", "+CREG: 0,5", CMD, 1)) { 50 | if ((millis() - timeStart) > 15000) { 51 | return false; 52 | } 53 | delay(1000); 54 | } 55 | 56 | //AT+CGREG? 57 | timeStart = millis(); 58 | while (!check_with_cmd("AT+CGREG?\r\n", "+CGREG: 0,1", CMD, 1) && 59 | !check_with_cmd("AT+CGREG?\r\n", "+CGREG: 0,5", CMD, 1)) { 60 | if ((millis() - timeStart) > 15000) { 61 | return false; 62 | } 63 | delay(1000); 64 | } 65 | return true; 66 | } 67 | 68 | bool Ethernet::join(const char* apn, const char* username, const char* passwd) { 69 | char sendBuffer[64]; 70 | int errCount = 0; 71 | uint32_t timeStart = 0; 72 | 73 | // Setting APN, AT+QICSGP=1,1,APN 74 | clean_buffer(sendBuffer, 64); 75 | sprintf(sendBuffer, "AT+QICSGP=1,1,\"%s\",\"%s\",\"%s\",1\r\n", apn, username, passwd); 76 | if (!check_with_cmd(sendBuffer, "OK", CMD, DEFAULT_TIMEOUT, 2000, UART_DEBUG)) { 77 | return false; 78 | } 79 | 80 | // Activate PDP context AT+QIACT=1 81 | timeStart = millis(); 82 | while (!check_with_cmd("AT+QIACT?\r\n", "+QIACT:", CMD, 2, 2000, UART_DEBUG)) { 83 | if (!check_with_cmd("AT+QIACT=1\r\n", "OK", CMD, 10, 2000, UART_DEBUG)) { 84 | check_with_cmd("AT+QIDEACT=1\r\n", "OK", CMD, 10, 2000, UART_DEBUG); 85 | } 86 | if ((millis() - timeStart) > 30000) { 87 | return false; 88 | } 89 | } 90 | DEBUG("PDP context activating..."); 91 | // Get ip address 92 | if (!getIP()) { 93 | return false; 94 | } 95 | 96 | return true; 97 | } 98 | 99 | bool Ethernet::getIP(void) { 100 | char* p; 101 | int i = 0; 102 | int errCount = 0; 103 | char ipAddr[32]; 104 | char sendBuffer[32]; 105 | char recvBuffer[64]; 106 | 107 | // Get IP address, AT+QICAT 108 | clean_buffer(ipAddr, 32); 109 | clean_buffer(recvBuffer, 64); 110 | send_cmd("AT+QIACT?\r\n"); 111 | read_buffer(recvBuffer, 64); 112 | DEBUG(recvBuffer); 113 | 114 | errCount = 0; 115 | while (NULL == (p = strstr(recvBuffer, "+QIACT:"))) { 116 | clean_buffer(recvBuffer, 64); 117 | send_cmd("AT+QIACT?\r\n"); 118 | read_buffer(recvBuffer, 64); 119 | if (errCount > 5) { 120 | return false; 121 | } 122 | errCount++; 123 | } 124 | 125 | p = strtok(recvBuffer, ","); // +QIACT: 1,1,1,"10.72.134.66" 126 | p = strtok(NULL, ","); // 1,1,"10.72.134.66" 127 | p = strtok(NULL, ","); // 1,"10.72.134.66" 128 | p = strtok(NULL, ","); // "10.72.134.66" 129 | p += 1; 130 | 131 | clean_buffer(ip_string, 20); 132 | while ((*(p + i) != '\"') && (*(p + i) != '\0')) { 133 | ip_string[i] = *(p + i); 134 | i++; 135 | } 136 | 137 | ip_string[i] = '\0'; 138 | _ip = str_to_ip(p); 139 | if (_ip != 0) { 140 | return true; 141 | } 142 | 143 | return false; 144 | } 145 | 146 | uint32_t Ethernet::str_to_ip(const char* str) { 147 | uint32_t ip = 0; 148 | char* p = (char*)str; 149 | 150 | for (int i = 0; i < 4; i++) { 151 | ip |= atoi(p); 152 | p = strchr(p, '.'); 153 | if (p == NULL) { 154 | break; 155 | } 156 | if (i < 3) { 157 | ip <<= 8; 158 | } 159 | p++; 160 | } 161 | return ip; 162 | } 163 | 164 | char* Ethernet::recoverIP() { 165 | uint8_t a = (_ip >> 24) & 0xff; 166 | uint8_t b = (_ip >> 16) & 0xff; 167 | uint8_t c = (_ip >> 8) & 0xff; 168 | uint8_t d = _ip & 0xff; 169 | 170 | snprintf(ip_string, sizeof(ip_string), "%d.%d.%d.%d", a, b, c, d); 171 | return ip_string; 172 | } 173 | 174 | // int Ethernet::networkCheck(void) 175 | // { 176 | // delay(1000); 177 | // if(0 != check_with_cmd("AT+CREG?\r\n","+CREG: 0,1",CMD, DEFAULT_TIMEOUT*3)) { 178 | // ERROR("ERROR:CGREG"); 179 | // return -1; 180 | // } 181 | // delay(1000); 182 | // if(0 != check_with_cmd("AT+CGATT?\r\n","+CGATT: 1",CMD, DEFAULT_TIMEOUT)) { 183 | // ERROR("ERROR:CGATT"); 184 | // return -1; 185 | // } 186 | // return 0; 187 | // } 188 | 189 | bool Ethernet::connect(const char* ip, int port, int connectType, uint8_t dataAccessMode) { 190 | /** 191 | @breif EC21 has 12 socketid can be used, in this function we always use socketid NO.0. 192 | @dataAccessMode: 193 | 194 | 0.In SOCKET_BUFFER_MODE 195 | - Use "AT+QISEND=0,len" to send data. 196 | - Use "AT+QIRD=0,0" to check buffer size and read out data. 197 | 198 | 1.In SOCKET_DIRECT_PUSH_MODE 199 | - Use "AT+QISEND=0,len" to send data 200 | - Received data will push out directly. 201 | 202 | 2.In SOCKET_TRANSPARANT_MODE 203 | - After connect 204 | - Write data to Module Serial directly. 205 | - Any received data will push out directly. 206 | */ 207 | uint8_t errCount = 0; 208 | char cipstart[64]; 209 | 210 | 211 | if (connectType == TCP) { 212 | sprintf(cipstart, "AT+QIOPEN=1,0,\"TCP\",\"%s\",%d,0,%d\r\n", ip, port, dataAccessMode); 213 | } else if (connectType == UDP) { 214 | sprintf(cipstart, "AT+QIOPEN=1,0,\"UDP\",\"%s\",%d,0,%d\r\n", ip, port, dataAccessMode); 215 | } else { 216 | return false; 217 | } 218 | 219 | while (!check_with_cmd(cipstart, "+QIOPEN: 0", CMD, 2 * DEFAULT_TIMEOUT, 2000)) { // connect tcp 220 | ERROR("ERROR:QIOPEN"); 221 | if (errCount > 3) { 222 | return false; 223 | } 224 | errCount++; 225 | } 226 | 227 | return true; 228 | } 229 | 230 | 231 | bool Ethernet::write(char* data) { 232 | /** Socket client write process 233 | 1.Open 234 | AT+QIOPEN=1,0,"TCP","mbed.org",80,0,1 235 | 2 Set data lenght 236 | AT+QISEND=0,53 237 | 3.Put in data 238 | GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n 239 | 4.Close socket 240 | AT+QICLOSE=0 241 | */ 242 | 243 | char cmd[32]; 244 | int len = strlen(data); 245 | snprintf(cmd, sizeof(cmd), "AT+QISEND=0,%d\r\n", len); 246 | if (!check_with_cmd(cmd, ">", CMD, 2 * DEFAULT_TIMEOUT)) { 247 | ERROR("ERROR:QISEND\r\n" 248 | "Data length: "); 249 | ERROR(len); 250 | return false; 251 | } 252 | 253 | send_cmd(data); 254 | send_cmd("\r\n"); 255 | // if(!check_with_cmd("\r\n","SEND OK", DATA, 2*DEFAULT_TIMEOUT)) { 256 | // ERROR("ERROR:SendData"); 257 | // return false; 258 | // } 259 | return true; 260 | } 261 | 262 | /** 263 | \brief Read data from buffer 264 | \return bool 265 | */ 266 | bool Ethernet::read() { 267 | char cmd[32]; 268 | snprintf(cmd, sizeof(cmd), "AT+QIRD=0,1500\r\n"); 269 | if (!check_with_cmd(cmd, "+QIURC: \"closed\"", CMD, 2 * DEFAULT_TIMEOUT, true)) { 270 | ERROR("ERROR:QIRD"); 271 | return false; 272 | } 273 | 274 | return true; 275 | } 276 | 277 | int Ethernet::getSocketStatus() { 278 | /* 279 | AT+QISTATE=1,0 280 | 281 | +QISTATE: 0,"TCP","xx.xx.xx.xx",xxxx,26824,2,1,0,0,"uart1" 282 | 283 | OK 284 | */ 285 | 286 | char* p; 287 | int i = 0; 288 | int errCount = 0; 289 | char connect_status[8]; 290 | char recvBuffer[64]; 291 | 292 | // Get IP address, AT+QICAT 293 | clean_buffer(recvBuffer, 64); 294 | send_cmd("AT+QISTATE=1,0\r\n"); 295 | read_buffer(recvBuffer, 64); 296 | DEBUG(recvBuffer); 297 | 298 | errCount = 0; 299 | while (NULL == (p = strstr(recvBuffer, "+QISTATE:"))) { 300 | clean_buffer(recvBuffer, 64); 301 | send_cmd("AT+QISTATE=1,0\r\n"); 302 | read_buffer(recvBuffer, 64); 303 | if (errCount > 5) { 304 | return -1; 305 | } 306 | errCount++; 307 | } 308 | 309 | p = strtok(recvBuffer, ","); 310 | p = strtok(NULL, ","); 311 | p = strtok(NULL, ","); 312 | p = strtok(NULL, ","); 313 | p = strtok(NULL, ","); 314 | p = strtok(NULL, ","); 315 | p = strtok(NULL, ","); 316 | 317 | clean_buffer(connect_status, 20); 318 | while ((*(p + i) != '\"') && (*(p + i) != '\0')) { 319 | connect_status[i] = *(p + i); 320 | i++; 321 | } 322 | 323 | connect_status[i] = '\0'; 324 | return atoi(connect_status); 325 | } 326 | 327 | bool Ethernet::is_connected(void) { 328 | return (2 == getSocketStatus()) ? true : false; 329 | } 330 | 331 | bool Ethernet::close(uint8_t connectid) { 332 | bool ret; 333 | char sendBuffer[16]; 334 | sprintf(sendBuffer, "AT+QICLOSE=%d\r\n", connectid); 335 | ret = check_with_cmd(sendBuffer, "OK", CMD, 2); 336 | 337 | return ret; 338 | } 339 | 340 | 341 | -------------------------------------------------------------------------------- /ethernet.h: -------------------------------------------------------------------------------- 1 | /* 2 | internet.h 3 | 4 | Copyright (c) 2017 Seeed Technology Co., Ltd. 5 | Website : www.seeed.cc 6 | Author : lambor 7 | Create Time: July 2017 8 | Change Log : 9 | 10 | The MIT License (MIT) 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy 13 | of this software and associated documentation files (the "Software"), to deal 14 | in the Software without restriction, including without limitation the rights 15 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 | copies of the Software, and to permit persons to whom the Software is 17 | furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in 20 | all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 | THE SOFTWARE. 29 | */ 30 | 31 | #ifndef __ETHERNET_H__ 32 | #define __ETHERNET_H__ 33 | 34 | #include "stdio.h" 35 | #include "wio_tracker.h" 36 | #include "UART_Interface.h" 37 | 38 | 39 | enum Protocol { 40 | CLOSED = 0, 41 | TCP = 1, 42 | UDP = 2 43 | }; 44 | 45 | enum SocketAccessMode { 46 | SOCKET_BUFFER_MODE = 0, 47 | SOCKET_DIRECT_PUSH_MODE, 48 | SOCKET_TRANSPARANT_MODE 49 | }; 50 | 51 | class Ethernet : public WioTracker { 52 | public: 53 | uint32_t _ip; 54 | char ip_string[20]; 55 | char last_URL[128]; 56 | 57 | /** Create Ethernet instance 58 | @param number default phone number during mobile communication 59 | */ 60 | // Ethernet(); 61 | 62 | /** Check network registration status 63 | @returns 64 | 0 on success 65 | -1 on error 66 | */ 67 | bool init(void); 68 | 69 | /** Join APN 70 | @param apn name 71 | @param apn user name 72 | @param apn passwd 73 | @return 74 | true Jion APN successfully 75 | false failed to join APN 76 | */ 77 | bool join(const char* apn, const char* username = "", const char* passwd = ""); 78 | 79 | /** Get IP address 80 | @return 81 | true on successfully 82 | flase on failed 83 | */ 84 | bool getIP(void); 85 | 86 | /** parse IP string 87 | @return 88 | ip in hex 89 | */ 90 | uint32_t str_to_ip(const char* str); 91 | 92 | /** Recover Ip address 93 | @return 94 | IP string 95 | */ 96 | char* recoverIP(); 97 | 98 | /** check network is OK or not 99 | @returns 100 | 0 on success 101 | -1 on error 102 | */ 103 | int networkCheck(void); 104 | 105 | /** build TCP connect 106 | @param ip ip address which will connect to 107 | @param port TCP server' port number 108 | @returns 109 | -1 on error 110 | 0 on success 111 | */ 112 | bool connect(const char* ip, int port, int connectType = TCP, uint8_t dataAccessMode = SOCKET_DIRECT_PUSH_MODE); 113 | 114 | /** Write data to socket server 115 | @param data data that will be send to socket server 116 | @returns 117 | 0 on success 118 | -1 on error 119 | */ 120 | bool write(char* data); 121 | 122 | /** Read data from 123 | 124 | 125 | 126 | */ 127 | bool read(); 128 | 129 | /** Get socket status 130 | @returns 131 | -1 on error 132 | 0 "Initial" connection has not been established 133 | 1 "Openning" client is connecting ro server is trying to listen 134 | 2 "Connected" client/incoming connection has been establish 135 | 3 "Listening" server is listening 136 | 4 "Closing" connection is closing 137 | */ 138 | int getSocketStatus(); 139 | 140 | /** Check if socket connected 141 | @returns 142 | true on connected 143 | false on disconnect 144 | */ 145 | bool is_connected(void); 146 | 147 | /** close TCP connection 148 | @returns 149 | 0 on success 150 | -1 on error 151 | */ 152 | bool httpGET(char* url); 153 | 154 | /** close TCP connection 155 | @returns 156 | 0 on success 157 | -1 on error 158 | */ 159 | bool httpPUT(char* url); 160 | 161 | /** close TCP connection 162 | @returns 163 | 0 on success 164 | -1 on error 165 | */ 166 | 167 | 168 | /** close connection 169 | @param connectid, socket id to close 170 | @returns 171 | 0 on success 172 | -1 on error 173 | */ 174 | bool close(uint8_t connectid = 0); 175 | 176 | 177 | 178 | }; 179 | 180 | #endif 181 | /* End of file */ 182 | 183 | 184 | -------------------------------------------------------------------------------- /examples/AT_bypass/AT_bypass.ino: -------------------------------------------------------------------------------- 1 | #include "wio_tracker.h" 2 | 3 | 4 | WioTracker wio = WioTracker(); 5 | 6 | void setup() { 7 | SerialUSB.println("Begin..."); 8 | wio.Power_On(); 9 | while (false == wio.Check_If_Power_On()) { 10 | SerialUSB.println("Waitting for module to alvie..."); 11 | delay(1000); 12 | } 13 | SerialUSB.println("Power On O.K!"); 14 | } 15 | 16 | void loop() { 17 | /* Debug */ 18 | AT_bypass(); 19 | } 20 | -------------------------------------------------------------------------------- /examples/CallUp/CallUp.ino: -------------------------------------------------------------------------------- 1 | #include "wio_tracker.h" 2 | 3 | WioTracker wio = WioTracker(); 4 | 5 | void setup() { 6 | SerialUSB.println("Wait for power on..."); 7 | wio.Power_On(); 8 | SerialUSB.println("Power On O.K!"); 9 | 10 | while (!wio.init()) { 11 | delay(1000); 12 | SerialUSB.println("Accessing network..."); 13 | } 14 | SerialUSB.println("Initialize done..."); 15 | 16 | bool ret = wio.waitForNetworkRegister(); 17 | if (true == ret) { 18 | SerialUSB.println("Network accessed!"); 19 | } else { 20 | SerialUSB.println("Network failed!"); 21 | return; 22 | } 23 | 24 | // Make a phone call 25 | wio.callUp("xxxxxxxx"); 26 | SerialUSB.println("Calling..."); 27 | 28 | } 29 | 30 | void loop() { 31 | /* Debug */ 32 | AT_bypass(); 33 | } 34 | -------------------------------------------------------------------------------- /examples/Check_battery/Check_battery.ino: -------------------------------------------------------------------------------- 1 | 2 | #include "UART_Interface.h" 3 | 4 | const int battery_adc_Pin = 16; // PB0 5 | 6 | void setup() { 7 | 8 | } 9 | 10 | void loop() { 11 | float a = analogRead(battery_adc_Pin); 12 | float v = a * 3300 / 2048; 13 | SerialUSB.print("The voltage of battery is "); 14 | SerialUSB.print(v, 2); 15 | SerialUSB.println(" mV"); 16 | delay(1000); 17 | } -------------------------------------------------------------------------------- /examples/GNSS/GNSS_DataFlowMode/GNSS_DataFlowMode.ino: -------------------------------------------------------------------------------- 1 | #include "gnss.h" 2 | 3 | // Instance of GNSS class 4 | GNSS gnss = GNSS(); 5 | 6 | void setup() { 7 | // Module power on 8 | gnss.Power_On(); 9 | while (false == gnss.Check_If_Power_On()) { 10 | SerialUSB.println("Waitting for module to alvie..."); 11 | delay(1000); 12 | } 13 | SerialUSB.println("\n\rPower On!"); 14 | 15 | if (!(gnss.open_GNSS())) { 16 | SerialUSB.println("\n\rGNSS init failed!"); 17 | return; 18 | } 19 | 20 | SerialUSB.println("Open GNSS OK."); 21 | delay(2000); 22 | } 23 | 24 | void loop() { 25 | gnss.dataFlowMode(); 26 | delay(2000); 27 | } 28 | -------------------------------------------------------------------------------- /examples/GNSS/GNSS_NMEA/GNSS_NMEA.ino: -------------------------------------------------------------------------------- 1 | #include "gnss.h" 2 | 3 | 4 | char nmea_sentence[192]; 5 | char nmea_GSV_sentence[512]; 6 | GNSS gnss = GNSS(); 7 | 8 | void setup() { 9 | gnss.Power_On(); 10 | while (false == gnss.Check_If_Power_On()) { 11 | SerialUSB.println("Waitting for module to alvie..."); 12 | delay(1000); 13 | } 14 | SerialUSB.println("\n\rPower On!"); 15 | 16 | if (!(gnss.open_GNSS())) { 17 | SerialUSB.println("\n\rGNSS init failed!"); 18 | return; 19 | } 20 | SerialUSB.println("Open GNSS OK."); 21 | gnss.enable_NMEA_mode(); // Set output sentence in NMEA mode 22 | } 23 | 24 | void loop() { 25 | clean_buffer(nmea_sentence, 192); 26 | gnss.read_NMEA(GGA, nmea_sentence); 27 | SerialUSB.print(nmea_sentence); 28 | 29 | clean_buffer(nmea_sentence, 192); 30 | gnss.read_NMEA(RMC, nmea_sentence); 31 | SerialUSB.print(nmea_sentence); 32 | 33 | clean_buffer(nmea_sentence, 192); 34 | gnss.read_NMEA(GSA, nmea_sentence); 35 | SerialUSB.print(nmea_sentence); 36 | 37 | clean_buffer(nmea_sentence, 192); 38 | gnss.read_NMEA(VTG, nmea_sentence); 39 | SerialUSB.print(nmea_sentence); 40 | 41 | clean_buffer(nmea_GSV_sentence, 512); 42 | gnss.read_NMEA_GSV(nmea_sentence); 43 | SerialUSB.print(nmea_sentence); 44 | 45 | SerialUSB.println("\r\n"); 46 | 47 | delay(1000); 48 | } 49 | -------------------------------------------------------------------------------- /examples/GNSS/GNSS_Show_Coordinate/GNSS_Show_Coordinate.ino: -------------------------------------------------------------------------------- 1 | #include "gnss.h" 2 | 3 | 4 | GNSS gnss = GNSS(); 5 | 6 | void setup() { 7 | gnss.Power_On(); 8 | while (false == gnss.Check_If_Power_On()) { 9 | SerialUSB.println("Waitting for module to alvie..."); 10 | delay(1000); 11 | } 12 | SerialUSB.println("\n\rPower On!"); 13 | 14 | if (!(gnss.open_GNSS())) { 15 | SerialUSB.println("\n\rGNSS init failed!"); 16 | return; 17 | } 18 | 19 | SerialUSB.println("Open GNSS OK."); 20 | delay(2000); 21 | } 22 | 23 | void loop() { 24 | if (gnss.getCoordinate()) { 25 | SerialUSB.println(); 26 | SerialUSB.print("GNSS: \r\n"); 27 | 28 | // Output double type 29 | SerialUSB.print("Data type in double: "); 30 | SerialUSB.print(gnss.longitude, 6); 31 | SerialUSB.print(","); 32 | SerialUSB.println(gnss.latitude, 6); 33 | 34 | // Output char* type 35 | SerialUSB.print("Data type in string: "); 36 | SerialUSB.print(gnss.str_longitude); 37 | SerialUSB.print(","); 38 | SerialUSB.println(gnss.str_latitude); 39 | } else { 40 | SerialUSB.print("..."); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /examples/GroveUART/GroveUART.ino: -------------------------------------------------------------------------------- 1 | #include "wio_tracker.h" 2 | 3 | 4 | WioTracker wio = WioTracker(); 5 | 6 | void setup() { 7 | // Turn on Grove socket power 8 | pinMode(wio.ENABLE_VCCB_PIN, OUTPUT); 9 | digitalWrite(wio.ENABLE_VCCB_PIN, HIGH); 10 | 11 | SerialUSB.println("Begin..."); 12 | Serial.begin(115200); 13 | 14 | } 15 | 16 | void loop() { 17 | SerialUSB.println("Grove UART is sending message."); 18 | Serial.println("From Grove UART."); 19 | delay(1000); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /examples/RSSI/RSSI.ino: -------------------------------------------------------------------------------- 1 | #include "wio_tracker.h" 2 | 3 | WioTracker wio = WioTracker(); 4 | 5 | void setup() { 6 | wio.Power_On(); 7 | SerialUSB.println("Power On!"); 8 | while (!wio.init()) { 9 | delay(1000); 10 | SerialUSB.println("Accessing network..."); 11 | } 12 | SerialUSB.println("Initialize done..."); 13 | 14 | bool ret = wio.waitForNetworkRegister(); 15 | if (true == ret) { 16 | SerialUSB.println("Network accessed!"); 17 | } else { 18 | SerialUSB.println("Network failed!"); 19 | return; 20 | } 21 | 22 | } 23 | void loop() { 24 | int rssi; 25 | wio.getSignalStrength(&rssi); 26 | SerialUSB.print("RSSI: "); 27 | SerialUSB.print(rssi); 28 | SerialUSB.print(" "); 29 | 30 | if (rssi == 99) { 31 | rssi = 9999; 32 | } else if (rssi == 0) { 33 | rssi = -113; 34 | } else if (rssi == 1) { 35 | rssi = -111; 36 | } else if (rssi >= 2 && rssi <= 30) { 37 | rssi = -109 + 2 * (rssi - 2); 38 | } else if (rssi > 30) { 39 | rssi = -51 + (rssi - 30) / 2; // approximate 40 | } 41 | 42 | SerialUSB.print(rssi); 43 | SerialUSB.println("dBm"); 44 | delay(1000); 45 | } 46 | -------------------------------------------------------------------------------- /examples/SDCard/CardInfo/CardInfo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card test 3 | 4 | This example shows how use the utility libraries on which the' 5 | SD library is based in order to get info about your SD card. 6 | Very useful for testing a card when you're not sure whether its working or not. 7 | 8 | The circuit: 9 | SD card attached to SPI bus as follows: 10 | ** UNO: MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed) 11 | and pin #10 (SS) must be an output 12 | ** Mega: MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed) 13 | and pin #52 (SS) must be an output 14 | ** Leonardo: Connect to hardware SPI via the ICSP header 15 | Pin 4 used here for consistency with other Arduino examples 16 | 17 | 18 | created 28 Mar 2011 by Limor Fried 19 | modified 9 Apr 2012 by Tom Igoe 20 | modified 16 Aug 2017 by Lambor Fang 21 | 22 | */ 23 | // include the SD library: 24 | #include 25 | 26 | // set up variables using the SD utility library functions: 27 | Sd2Card card; 28 | SdVolume volume; 29 | SdFile root; 30 | 31 | // change this to match your SD shield or module; 32 | // Arduino Ethernet shield: pin 4 33 | // Adafruit SD shields and modules: pin 10 34 | // Sparkfun SD shield: pin 8 35 | const int chipSelect = 43; 36 | 37 | void setup() { 38 | // Open serial communications and wait for port to open: 39 | // SerialUSB.begin(115200); 40 | // while (!Serial) { 41 | // ; // wait for serial port to connect. Needed for Leonardo only 42 | // } 43 | 44 | 45 | SerialUSB.print("\nInitializing SD card..."); 46 | // On the Ethernet Shield, CS is pin 4. It's set as an output by default. 47 | // Note that even if it's not used as the CS pin, the hardware SS pin 48 | // (10 on most Arduino boards, 53 on the Mega) must be left as an output 49 | // or the SD library functions will not work. 50 | pinMode(SS, OUTPUT); 51 | 52 | 53 | // we'll use the initialization code from the utility libraries 54 | // since we're just testing if the card is working! 55 | while (!card.init(SPI_HALF_SPEED, chipSelect)) { 56 | SerialUSB.println("initialization failed. Things to check:"); 57 | SerialUSB.println("* is a card is inserted?"); 58 | SerialUSB.println("* Is your wiring correct?"); 59 | SerialUSB.println("* did you change the chipSelect pin to match your shield or module?"); 60 | } 61 | 62 | // print the type of card 63 | SerialUSB.print("\nCard type: "); 64 | switch (card.type()) { 65 | case SD_CARD_TYPE_SD1: 66 | SerialUSB.println("SD1"); 67 | break; 68 | case SD_CARD_TYPE_SD2: 69 | SerialUSB.println("SD2"); 70 | break; 71 | case SD_CARD_TYPE_SDHC: 72 | SerialUSB.println("SDHC"); 73 | break; 74 | default: 75 | SerialUSB.println("Unknown"); 76 | } 77 | 78 | // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 79 | if (!volume.init(card)) { 80 | SerialUSB.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); 81 | return; 82 | } 83 | 84 | 85 | // print the type and size of the first FAT-type volume 86 | uint32_t volumesize; 87 | SerialUSB.print("\nVolume type is FAT"); 88 | SerialUSB.println(volume.fatType(), DEC); 89 | SerialUSB.println(); 90 | 91 | volumesize = volume.blocksPerCluster(); // clusters are collections of blocks 92 | volumesize *= volume.clusterCount(); // we'll have a lot of clusters 93 | volumesize *= 512; // SD card blocks are always 512 bytes 94 | SerialUSB.print("Volume size (bytes): "); 95 | SerialUSB.println(volumesize); 96 | SerialUSB.print("Volume size (Kbytes): "); 97 | volumesize /= 1024; 98 | SerialUSB.println(volumesize); 99 | SerialUSB.print("Volume size (Mbytes): "); 100 | volumesize /= 1024; 101 | SerialUSB.println(volumesize); 102 | 103 | 104 | SerialUSB.println("\nFiles found on the card (name, date and size in bytes): "); 105 | root.openRoot(volume); 106 | 107 | // list all files in the card with date and size 108 | root.ls(LS_R | LS_DATE | LS_SIZE); 109 | } 110 | 111 | 112 | void loop(void) { 113 | 114 | } 115 | -------------------------------------------------------------------------------- /examples/SDCard/Datalogger/Datalogger.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card datalogger 3 | 4 | This example shows how to log data from three analog sensors 5 | to an SD card using the SD library. 6 | 7 | The circuit: 8 | SD card attached to SPI bus as follows: 9 | ** UNO: MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed) 10 | and pin #10 (SS) must be an output 11 | ** Mega: MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed) 12 | and pin #52 (SS) must be an output 13 | ** Leonardo: Connect to hardware SPI via the ICSP header 14 | Pin 4 used here for consistency with other Arduino examples 15 | 16 | created 24 Nov 2010 17 | modified 9 Apr 2012 by Tom Igoe 18 | modified 16 Aug 2017 by Lambor Fang 19 | 20 | This example code is in the public domain. 21 | 22 | */ 23 | 24 | #include 25 | 26 | // On the Ethernet Shield, CS is pin 4. Note that even if it's not 27 | // used as the CS pin, the hardware CS pin (10 on most Arduino boards, 28 | // 53 on the Mega) must be left as an output or the SD library 29 | // functions will not work. 30 | const int chipSelect = 43; 31 | 32 | File dataFile; 33 | 34 | void setup() { 35 | SerialUSB.print("Initializing SD card..."); 36 | // make sure that the default chip select pin is set to 37 | // output, even if you don't use it: 38 | pinMode(SS, OUTPUT); 39 | 40 | // see if the card is present and can be initialized: 41 | if (!SD.begin(chipSelect)) { 42 | SerialUSB.println("Card failed, or not present"); 43 | // don't do anything more: 44 | while (1) ; 45 | } 46 | SerialUSB.println("card initialized."); 47 | 48 | // Open up the file we're going to log to! 49 | dataFile = SD.open("datalog.txt", FILE_WRITE); 50 | if (! dataFile) { 51 | SerialUSB.println("error opening datalog.txt"); 52 | // Wait forever since we cant write data 53 | while (1) ; 54 | } 55 | } 56 | 57 | void loop() { 58 | // make a string for assembling the data to log: 59 | String dataString = ""; 60 | 61 | // read three sensors and append to the string: 62 | for (int analogPin = 0; analogPin < 3; analogPin++) { 63 | int sensor = analogRead(analogPin); 64 | dataString += String(sensor); 65 | if (analogPin < 2) { 66 | dataString += ","; 67 | } 68 | } 69 | 70 | dataFile.println(dataString); 71 | 72 | // print to the serial port too: 73 | SerialUSB.println(dataString); 74 | 75 | // The following line will 'save' the file to the SD card after every 76 | // line of data - this will use more power and slow down how much data 77 | // you can read but it's safer! 78 | // If you want to speed up the system, remove the call to flush() and it 79 | // will save the file only every 512 bytes - every time a sector on the 80 | // SD card is filled with data. 81 | dataFile.flush(); 82 | 83 | // Take 1 measurement every 500 milliseconds 84 | delay(500); 85 | } 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /examples/SDCard/DumpFile/DumpFile.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card file dump 3 | 4 | This example shows how to read a file from the SD card using the 5 | SD library and send it over the serialUSB port. 6 | 7 | The circuit: 8 | SD card attached to SPI bus as follows: 9 | ** UNO: MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed) 10 | and pin #10 (SS) must be an output 11 | ** Mega: MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed) 12 | and pin #52 (SS) must be an output 13 | ** Leonardo: Connect to hardware SPI via the ICSP header 14 | 15 | created 22 December 2010 by Limor Fried 16 | modified 9 Apr 2012 by Tom Igoe 17 | modified 16 Aug 2017 by Lambor Fang 18 | 19 | This example code is in the public domain. 20 | 21 | */ 22 | #include 23 | 24 | // change this to match your SD shield or module; 25 | // Arduino Ethernet shield: pin 4 26 | // Adafruit SD shields and modules: pin 10 27 | // Sparkfun SD shield: pin 8 28 | const int chipSelect = 43; 29 | 30 | void setup() { 31 | SerialUSB.print("Initializing SD card..."); 32 | // make sure that the default chip select pin is set to 33 | // output, even if you don't use it: 34 | pinMode(SS, OUTPUT); 35 | 36 | // see if the card is present and can be initialized: 37 | if (!SD.begin(chipSelect)) { 38 | SerialUSB.println("Card failed, or not present"); 39 | // don't do anything more: 40 | return; 41 | } 42 | SerialUSB.println("card initialized."); 43 | 44 | // open the file. note that only one file can be open at a time, 45 | // so you have to close this one before opening another. 46 | File dataFile = SD.open("datalog.txt"); 47 | 48 | // if the file is available, write to it: 49 | if (dataFile) { 50 | while (dataFile.available()) { 51 | SerialUSB.write(dataFile.read()); 52 | } 53 | dataFile.close(); 54 | } 55 | // if the file isn't open, pop up an error: 56 | else { 57 | SerialUSB.println("error opening datalog.txt"); 58 | } 59 | } 60 | 61 | void loop() { 62 | } 63 | 64 | -------------------------------------------------------------------------------- /examples/SDCard/Files/Files.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card basic file example 3 | 4 | This example shows how to create and destroy an SD card file 5 | The circuit: 6 | SD card attached to SPI bus as follows: 7 | ** UNO: MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed) 8 | and pin #10 (SS) must be an output 9 | ** Mega: MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed) 10 | and pin #52 (SS) must be an output 11 | ** Leonardo: Connect to hardware SPI via the ICSP header 12 | 13 | created Nov 2010 14 | by David A. Mellis 15 | modified 9 Apr 2012 16 | by Tom Igoe 17 | modified 16 Aug 2017 by Lambor Fang 18 | 19 | This example code is in the public domain. 20 | 21 | */ 22 | #include 23 | 24 | File myFile; 25 | 26 | // change this to match your SD shield or module; 27 | // Arduino Ethernet shield: pin 4 28 | // Adafruit SD shields and modules: pin 10 29 | // Sparkfun SD shield: pin 8 30 | const int chipSelect = 43; 31 | 32 | void setup() { 33 | SerialUSB.print("Initializing SD card..."); 34 | // On the Ethernet Shield, CS is pin 4. It's set as an output by default. 35 | // Note that even if it's not used as the CS pin, the hardware SS pin 36 | // (10 on most Arduino boards, 53 on the Mega) must be left as an output 37 | // or the SD library functions will not work. 38 | pinMode(SS, OUTPUT); 39 | 40 | if (!SD.begin(chipSelect)) { 41 | SerialUSB.println("initialization failed!"); 42 | return; 43 | } 44 | SerialUSB.println("initialization done."); 45 | 46 | if (SD.exists("example.txt")) { 47 | SerialUSB.println("example.txt exists."); 48 | } else { 49 | SerialUSB.println("example.txt doesn't exist."); 50 | } 51 | 52 | // open a new file and immediately close it: 53 | SerialUSB.println("Creating example.txt..."); 54 | myFile = SD.open("example.txt", FILE_WRITE); 55 | myFile.close(); 56 | 57 | // Check to see if the file exists: 58 | if (SD.exists("example.txt")) { 59 | SerialUSB.println("example.txt exists."); 60 | } else { 61 | SerialUSB.println("example.txt doesn't exist."); 62 | } 63 | 64 | // delete the file: 65 | SerialUSB.println("Removing example.txt..."); 66 | SD.remove("example.txt"); 67 | 68 | if (SD.exists("example.txt")) { 69 | SerialUSB.println("example.txt exists."); 70 | } else { 71 | SerialUSB.println("example.txt doesn't exist."); 72 | } 73 | } 74 | 75 | void loop() { 76 | // nothing happens after setup finishes. 77 | } 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /examples/SDCard/ReadWrite/ReadWrite.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card read/write 3 | 4 | This example shows how to read and write data to and from an SD card file 5 | The circuit: 6 | SD card attached to SPI bus as follows: 7 | ** UNO: MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed) 8 | and pin #10 (SS) must be an output 9 | ** Mega: MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed) 10 | and pin #52 (SS) must be an output 11 | ** Leonardo: Connect to hardware SPI via the ICSP header 12 | 13 | 14 | created Nov 2010 by David A. Mellis 15 | modified 9 Apr 2012 by Tom Igoe 16 | modified 16 Aug 2017 by Lambor Fang 17 | 18 | This example code is in the public domain. 19 | 20 | */ 21 | #include 22 | 23 | File myFile; 24 | 25 | // change this to match your SD shield or module; 26 | // Arduino Ethernet shield: pin 4 27 | // Adafruit SD shields and modules: pin 10 28 | // Sparkfun SD shield: pin 8 29 | const int chipSelect = 43; 30 | 31 | void setup() { 32 | SerialUSB.print("Initializing SD card..."); 33 | // On the Ethernet Shield, CS is pin 4. It's set as an output by default. 34 | // Note that even if it's not used as the CS pin, the hardware SS pin 35 | // (10 on most Arduino boards, 53 on the Mega) must be left as an output 36 | // or the SD library functions will not work. 37 | pinMode(SS, OUTPUT); 38 | 39 | if (!SD.begin(chipSelect)) { 40 | SerialUSB.println("initialization failed!"); 41 | return; 42 | } 43 | SerialUSB.println("initialization done."); 44 | 45 | // open the file. note that only one file can be open at a time, 46 | // so you have to close this one before opening another. 47 | myFile = SD.open("test.txt", FILE_WRITE); 48 | 49 | // if the file opened okay, write to it: 50 | if (myFile) { 51 | SerialUSB.print("Writing to test.txt..."); 52 | myFile.println("testing 1, 2, 3."); 53 | // close the file: 54 | myFile.close(); 55 | SerialUSB.println("done."); 56 | } else { 57 | // if the file didn't open, print an error: 58 | SerialUSB.println("error opening test.txt"); 59 | } 60 | 61 | // re-open the file for reading: 62 | myFile = SD.open("test.txt"); 63 | if (myFile) { 64 | SerialUSB.println("test.txt:"); 65 | 66 | // read from the file until there's nothing else in it: 67 | while (myFile.available()) { 68 | SerialUSB.write(myFile.read()); 69 | } 70 | // close the file: 71 | myFile.close(); 72 | } else { 73 | // if the file didn't open, print an error: 74 | SerialUSB.println("error opening test.txt"); 75 | } 76 | } 77 | 78 | void loop() { 79 | // nothing happens after setup 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /examples/SDCard/listfiles/listfiles.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card basic file example 3 | 4 | This example shows how to create and destroy an SD card file 5 | The circuit: 6 | SD card attached to SPI bus as follows: 7 | ** UNO: MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed) 8 | and pin #10 (SS) must be an output 9 | ** Mega: MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed) 10 | and pin #52 (SS) must be an output 11 | ** Leonardo: Connect to hardware SPI via the ICSP header 12 | 13 | created Nov 2010 by David A. Mellis 14 | modified 9 Apr 2012 by Tom Igoe 15 | modified 13 June 2012 by Limor Fried 16 | modified 16 Aug 2017 by Lambor Fang 17 | 18 | This example code is in the public domain. 19 | 20 | */ 21 | #include 22 | 23 | File root; 24 | 25 | // change this to match your SD shield or module; 26 | // Arduino Ethernet shield: pin 4 27 | // Adafruit SD shields and modules: pin 10 28 | // Sparkfun SD shield: pin 8 29 | const int chipSelect = 43; 30 | 31 | void setup() { 32 | SerialUSB.print("Initializing SD card..."); 33 | // On the Ethernet Shield, CS is pin 4. It's set as an output by default. 34 | // Note that even if it's not used as the CS pin, the hardware SS pin 35 | // (10 on Arduino Uno boards, 53 on the Mega) must be left as an output 36 | // or the SD library functions will not work. 37 | pinMode(SS, OUTPUT); 38 | 39 | if (!SD.begin(chipSelect)) { 40 | SerialUSB.println("initialization failed!"); 41 | return; 42 | } 43 | SerialUSB.println("initialization done."); 44 | 45 | root = SD.open("/"); 46 | 47 | printDirectory(root, 0); 48 | 49 | SerialUSB.println("done!"); 50 | } 51 | 52 | void loop() { 53 | // nothing happens after setup finishes. 54 | } 55 | 56 | void printDirectory(File dir, int numTabs) { 57 | // Begin at the start of the directory 58 | dir.rewindDirectory(); 59 | 60 | while (true) { 61 | File entry = dir.openNextFile(); 62 | if (! entry) { 63 | // no more files 64 | //SerialUSB.println("**nomorefiles**"); 65 | break; 66 | } 67 | for (uint8_t i = 0; i < numTabs; i++) { 68 | SerialUSB.print('\t'); // we'll have a nice indentation 69 | } 70 | // Print the 8.3 name 71 | SerialUSB.print(entry.name()); 72 | // Recurse for directories, otherwise print the file size 73 | if (entry.isDirectory()) { 74 | SerialUSB.println("/"); 75 | printDirectory(entry, numTabs + 1); 76 | } else { 77 | // files have sizes, directories do not 78 | SerialUSB.print("\t\t"); 79 | SerialUSB.println(entry.size(), DEC); 80 | } 81 | entry.close(); 82 | } 83 | } 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /examples/SMSRead/SMSRead.ino: -------------------------------------------------------------------------------- 1 | #include "wio_tracker.h" 2 | 3 | uint16_t newSMSNumber = -1; 4 | char message[128]; 5 | char phone[32]; 6 | char dateTime[32]; 7 | 8 | 9 | WioTracker wio = WioTracker(); 10 | 11 | void setup() { 12 | wio.Power_On(); 13 | SerialUSB.println("Power On!"); 14 | SerialUSB.println("Wait for network registered..."); 15 | 16 | if (!wio.waitForNetworkRegister()) { 17 | SerialUSB.println("Network error!"); 18 | return; 19 | } else { 20 | SerialUSB.println("Network ready!"); 21 | } 22 | wio.readAllRecUnreadSMS(); // Set all "REC UNREAD SMS" to "REC READ SMS" 23 | } 24 | 25 | void loop() { 26 | int id = wio.detectRecUnreadSMS(); 27 | if (-1 != id) { 28 | newSMSNumber = id; 29 | wio.readSMS(newSMSNumber, message, 128, phone, dateTime); 30 | SerialUSB.println("++++++++++++++ Start +++++++++++++++++"); 31 | SerialUSB.print("From: "); 32 | SerialUSB.println(phone); 33 | SerialUSB.print("Date: "); 34 | SerialUSB.println(dateTime); 35 | SerialUSB.println(message); 36 | SerialUSB.println("++++++++++++++++ End +++++++++++++++"); 37 | } else { 38 | SerialUSB.println("Waiting for new SMS!"); 39 | } 40 | 41 | delay(1000); 42 | } 43 | -------------------------------------------------------------------------------- /examples/SMSSend/SMSSend.ino: -------------------------------------------------------------------------------- 1 | #include "wio_tracker.h" 2 | 3 | char message[128] = "Hello from Wio Traker!"; 4 | 5 | WioTracker wio = WioTracker(); 6 | 7 | void setup() { 8 | wio.Power_On(); 9 | SerialUSB.println("Power On!"); 10 | 11 | if (!wio.waitForNetworkRegister()) { 12 | SerialUSB.println("Network error!"); 13 | return; 14 | } else { 15 | SerialUSB.println("Network ready!"); 16 | } 17 | 18 | // Change xxxxxxxxxxx to your test phone number 19 | if (wio.sendSMS("13750024343", message)) { 20 | SerialUSB.println("Send OK!"); 21 | } else { 22 | SerialUSB.println("Send Error!"); 23 | } 24 | 25 | } 26 | 27 | void loop() { 28 | AT_bypass(); 29 | } -------------------------------------------------------------------------------- /examples/TCPConnect/TCPConnect.ino: -------------------------------------------------------------------------------- 1 | #include "ethernet.h" 2 | 3 | Ethernet eth = Ethernet(); 4 | 5 | 6 | // const char apn[10] = "CMNET"; 7 | const char apn[10] = "UNINET"; 8 | const char URL[100] = "mbed.org"; 9 | char http_cmd[100] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\r\n\r"; 10 | int port = 80; 11 | 12 | int ret = 0; 13 | 14 | 15 | void setup() { 16 | SerialUSB.println("Begin..."); 17 | eth.Power_On(); 18 | while (false == eth.Check_If_Power_On()) { 19 | SerialUSB.println("Waitting for module to alvie..."); 20 | delay(1000); 21 | } 22 | 23 | while (!eth.init()) { 24 | delay(1000); 25 | SerialUSB.println("Accessing network..."); 26 | } 27 | SerialUSB.println("Initialize done..."); 28 | 29 | eth.join(apn); 30 | SerialUSB.print("\n\rIP: "); 31 | SerialUSB.print(eth.ip_string); 32 | 33 | if (eth.connect(URL, port, TCP)) { 34 | eth.write(http_cmd); 35 | while (MODULE_PORT.available()) { 36 | serialDebug.write(MODULE_PORT.read()); 37 | } 38 | eth.close(1); 39 | } else { 40 | SerialUSB.println("Connect Error!"); 41 | } 42 | 43 | } 44 | 45 | void loop() { 46 | /* Debug */ 47 | AT_bypass(); 48 | } 49 | -------------------------------------------------------------------------------- /examples/TimerInterrupt/TimerInterrupt.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | HardwareTimer.h create 4 timer instances - Timer1, Timer2, Timer3, Timer4 5 | Use the below methods to initialize a timer interrupt: 6 | - HardwareTimer::setMode(int channel, timer_mode mode) 7 | - HardwareTimer::setPeriod(uint32 microseconds) 8 | - HardwareTimer::refresh(void) 9 | - HardwareTimer::attachInterrupt(int channel, voidFuncPtr handler) 10 | 11 | To detachInterrupt: 12 | - HardwareTimer::detachInterrupt(int channel) 13 | */ 14 | 15 | uint32_t timeBegin = 0; 16 | bool time1Exit = false; 17 | 18 | void callback(void) { 19 | SerialUSB.print("Timer arrived - "); 20 | SerialUSB.println(millis() - timeBegin, DEC); 21 | } 22 | 23 | void Time1Init() { 24 | Timer1.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE); 25 | Timer1.setPeriod(1000000); // microseconds 26 | Timer1.refresh(); 27 | Timer1.attachInterrupt(TIMER_CH1, callback); 28 | } 29 | 30 | void setup() { 31 | delay(2000); 32 | SerialUSB.begin(); 33 | timeBegin = millis(); 34 | Time1Init(); 35 | } 36 | 37 | void loop() { 38 | if ((millis() - timeBegin > 5000) && !time1Exit) { 39 | SerialUSB.print("Timer runs elapse - "); 40 | SerialUSB.println(millis() - timeBegin, DEC); 41 | time1Exit = true; 42 | Timer1.detachInterrupt(TIMER_CH1); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/sleepWakeupControl/sleepWakeupControl.ino: -------------------------------------------------------------------------------- 1 | #include "wio_tracker.h" 2 | 3 | 4 | WioTracker wio = WioTracker(); 5 | 6 | void setup() { 7 | pinMode(wio.DTR_PIN, INPUT); 8 | 9 | SerialUSB.println("Begin..."); 10 | wio.Power_On(); 11 | while (false == wio.Check_If_Power_On()) { 12 | SerialUSB.println("Waitting for module to alvie..."); 13 | delay(1000); 14 | } 15 | SerialUSB.println("Power On O.K!"); 16 | } 17 | 18 | void loop() { 19 | SerialUSB.println("sleep..."); 20 | while (!wio.module_sleep()) { 21 | SerialUSB.println("Try to sleep..."); 22 | delay(1000); 23 | } 24 | SerialUSB.println("sleep..."); 25 | delay(4000); 26 | SerialUSB.println("wakeup..."); 27 | while (!wio.module_wakeup()) { 28 | SerialUSB.println("Try to wakeup..."); 29 | delay(1000); 30 | } 31 | SerialUSB.println("wakeup..."); 32 | delay(4000); 33 | } -------------------------------------------------------------------------------- /gnss.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | gnss.cpp 3 | A library for SeeedStudio GPS Tracker LTE GNSS 4 | 5 | Copyright (c) 2017 Seeed Technology Co., Ltd. 6 | Website : www.seeed.cc 7 | Author : lambor 8 | Create Time: June 2017 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #include "gnss.h" 33 | 34 | 35 | bool GNSS::close_GNSS() { 36 | int errCounts = 0; 37 | 38 | //Open GNSS funtion 39 | while (!check_with_cmd("AT+QGNSSC?\n\r", "+QGNSSC: 0", CMD, 2, 2000, UART_DEBUG)) { 40 | errCounts ++; 41 | if (errCounts > 100) { 42 | return false; 43 | } 44 | check_with_cmd("AT+QGNSSC=0\n\r", "OK", CMD, 2, 2000, UART_DEBUG); 45 | delay(1000); 46 | } 47 | 48 | return true; 49 | } 50 | 51 | bool GNSS::dataFlowMode(void) { 52 | // Make sure that "#define UART_DEBUG" is uncomment. 53 | send_cmd("AT+QGPSLOC?\r\n"); 54 | return wait_for_resp("OK", CMD, 2, 2000, true); 55 | } 56 | 57 | bool GNSS::open_GNSS(void) { 58 | int errCounts = 0; 59 | 60 | //Open GNSS funtion 61 | while (!check_with_cmd("AT+QGPS?\r\n", "+QGPS: 1", CMD, 2, 2000, UART_DEBUG)) { 62 | errCounts ++; 63 | if (errCounts > 5) { 64 | return false; 65 | } 66 | check_with_cmd("AT+QGPS=1\r\n", "OK", CMD, 2, 2000, UART_DEBUG); 67 | delay(1000); 68 | } 69 | 70 | return true; 71 | } 72 | 73 | bool GNSS::getCoordinate(void) { 74 | int tmp = 0; 75 | char* p = NULL; 76 | uint8_t str_len = 0; 77 | char buffer[128]; 78 | 79 | clean_buffer(buffer, 128); 80 | send_cmd("AT+QGPSLOC?\r\n"); 81 | read_buffer(buffer, 128, 2); 82 | // SerialUSB.println(buffer); 83 | if (NULL != (p = strstr(buffer, "+CME ERROR"))) { 84 | return false; 85 | } 86 | 87 | // +QGPSLOC: 084757.700,2235.0272N,11357.9730E,1.6,40.0,3,171.43,0.0,0.0,290617,10 88 | else if (NULL != (p = strstr(buffer, "+QGPSLOC:"))) { 89 | p += 10; 90 | p = strtok(buffer, ","); // time 91 | p = strtok(NULL, ","); // latitude 92 | sprintf(str_latitude, "%s", p); 93 | latitude = strtod(p, NULL); 94 | tmp = (int)(latitude / 100); 95 | latitude = (double)(tmp + (latitude - tmp * 100) / 60.0); 96 | 97 | // Get North and South status 98 | str_len = strlen(p); 99 | if ((*(p + str_len - 1) != 'N') && (*(p + str_len - 1) != 'S')) { 100 | North_or_South[0] = '0'; 101 | North_or_South[1] = '\0'; 102 | } else { 103 | North_or_South[0] = *(p + str_len - 1); 104 | North_or_South[1] = '\0'; 105 | } 106 | 107 | p = strtok(NULL, ","); // longitude 108 | sprintf(str_longitude, "%s", p); 109 | longitude = strtod(p, NULL); 110 | 111 | // Get West and East status 112 | str_len = strlen(p); 113 | if ((*(p + str_len - 1) != 'W') && (*(p + str_len - 1) != 'E')) { 114 | West_or_East[0] = '0'; 115 | West_or_East[1] = '\0'; 116 | } else { 117 | West_or_East[0] = *(p + str_len - 1); 118 | West_or_East[1] = '\0'; 119 | } 120 | 121 | tmp = (int)(longitude / 100); 122 | longitude = (double)(tmp + (longitude - tmp * 100) / 60.0); 123 | 124 | // if(North_or_South[0] == 'S'){ 125 | // // latitude = 0.0 - latitude; 126 | // } else if(North_or_South[0] = 'N'){ 127 | // latitude = 0.0 - latitude; 128 | // } 129 | 130 | // if(West_or_East[0] == 'W'){ 131 | // // longitude = 0.0 - longitude; 132 | // } else if(West_or_East[0] = 'E'){ 133 | // longitude = 0.0 - longitude; 134 | // } 135 | 136 | doubleToString(longitude, latitude); 137 | } else { 138 | return false; 139 | } 140 | return true; 141 | } 142 | 143 | void GNSS::doubleToString(double longitude, double latitude) { 144 | int u8_lon = (int)longitude; 145 | int u8_lat = (int)latitude; 146 | uint32_t u32_lon = (longitude - u8_lon) * 1000000; 147 | uint32_t u32_lat = (latitude - u8_lat) * 1000000; 148 | 149 | sprintf(str_longitude, "%d.%lu", u8_lon, u32_lon); 150 | sprintf(str_latitude, "%d.%lu", u8_lat, u32_lat); 151 | } 152 | 153 | bool GNSS::enable_NMEA_mode() { 154 | if (!check_with_cmd("AT+QGPSCFG=\“nmeasrc\",1\r\n", "OK", CMD, DEFAULT_TIMEOUT, 2000)) { 155 | return false; 156 | } 157 | return true; 158 | } 159 | 160 | bool GNSS::disable_NMEA_mode() { 161 | if (!check_with_cmd("AT+QGPSCFG=\“nmeasrc\",0\r\n", "OK", CMD, DEFAULT_TIMEOUT, 2000)) { 162 | return false; 163 | } 164 | return true; 165 | } 166 | 167 | bool GNSS::NMEA_read_and_save(const char* type, char* save_buff) { 168 | char recv_buff[192]; 169 | char send_buff[32]; 170 | char* p = NULL; 171 | uint16_t i = 0; 172 | 173 | clean_buffer(recv_buff, 192); 174 | clean_buffer(send_buff, 32); 175 | sprintf(send_buff, "AT+QGPSGNMEA=\"%s\"\r\n", type); 176 | send_cmd(send_buff); // Send command 177 | read_string_until(recv_buff, 192, "OK", 1); // Save response data 178 | // SerialUSB.print("##DEBUG read_string_until: "); 179 | // SerialUSB.println(recv_buff); 180 | if (NULL == (p = strstr(recv_buff, "+QGPSGNMEA:"))) { 181 | return false; 182 | } 183 | p += 12; 184 | while ((*(p) != '\n') && (*(p) != '\0')) { // If receive "+QGPSGNMEA:", than keep saving the NMEA sentence 185 | save_buff[i++] = *(p++); 186 | } 187 | save_buff[i] = '\0'; 188 | // SerialUSB.print("##DEBUG save_buff: "); 189 | // SerialUSB.println(save_buff); 190 | return true; 191 | 192 | } 193 | 194 | bool GNSS::read_NMEA(NMEA_type type, char* save_buff) { 195 | switch (type) { 196 | case GGA: 197 | NMEA_read_and_save("GGA", save_buff); 198 | break; 199 | case RMC: 200 | NMEA_read_and_save("RMC", save_buff); 201 | break; 202 | case GSV: 203 | // NMEA_read_and_save("GSV", save_buff); // Delete GSV aquirement, too much content to be saved, 204 | break; 205 | case GSA: 206 | NMEA_read_and_save("GSA", save_buff); 207 | break; 208 | case VTG: 209 | NMEA_read_and_save("VTG", save_buff); 210 | break; 211 | case GNS: 212 | NMEA_read_and_save("GNS", save_buff); // GNS sentence didn't show anything. 213 | break; 214 | 215 | default: 216 | break; 217 | } 218 | 219 | return true; 220 | } 221 | 222 | /** 223 | Read NMEA GSV sentence 224 | GSV sentence gonna be 6 lines, that's too much content to save as other NMEA data. 225 | save_buff should be 512 Bytes size at least. 226 | */ 227 | bool GNSS::read_NMEA_GSV(char* save_buff) { 228 | char recv_buff[512]; 229 | char* p; 230 | uint16_t i = 0; 231 | 232 | clean_buffer(recv_buff, 192); 233 | send_cmd("AT+QGPSGNMEA=\"GSV\"\r\n"); // Send command 234 | read_string_until(recv_buff, 512, "OK", 1); // Save response data 235 | // SerialUSB.print("##DEBUG read_string_until: "); 236 | // SerialUSB.println(recv_buff); 237 | 238 | if (NULL == (p = strstr(recv_buff, "+QGPSGNMEA:"))) { 239 | return false; 240 | } 241 | 242 | // while(NULL != (p = strstr((recv_buff+i), "+QGPSGNMEA:"))) 243 | while (NULL != (p = strstr(p, "+QGPSGNMEA:"))) { 244 | p += 12; 245 | while ((*(p) != '\n') && (*(p) != '\0')) { // If receive "+QGPSGNMEA:", than keep saving the NMEA sentence 246 | save_buff[i++] = *(p++); 247 | } 248 | } 249 | 250 | // SerialUSB.print("##DEBUG save_buff: "); 251 | // SerialUSB.println(save_buff); 252 | return true; 253 | 254 | } 255 | -------------------------------------------------------------------------------- /gnss.h: -------------------------------------------------------------------------------- 1 | /* 2 | gnss.h 3 | A library for SeeedStudio GPS Tracker BT 4 | 5 | Copyright (c) 2017 Seeed Technology Co., Ltd. 6 | Website : www.seeed.cc 7 | Author : lawliet zou, lambor 8 | Create Time: April 2017 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #ifndef __GNSS_H__ 33 | #define __GNSS_H__ 34 | 35 | #include "wio_tracker.h" 36 | #include "UART_Interface.h" 37 | #include "stdio.h" 38 | 39 | typedef enum NMEA_TYPE { 40 | GGA = 0, 41 | RMC, 42 | GSV, 43 | GSA, 44 | VTG, 45 | GNS 46 | } NMEA_type; 47 | 48 | 49 | class GNSS : public WioTracker { 50 | public: 51 | double longitude; 52 | double latitude; 53 | char str_longitude[16]; 54 | char str_latitude[16]; 55 | double ref_longitude = 22.584322; 56 | double ref_latitude = 113.966678; 57 | char North_or_South[2]; 58 | char West_or_East[2]; 59 | 60 | 61 | bool open_GNSS(int mode); 62 | bool close_GNSS(void); 63 | 64 | /** 65 | open GNSS 66 | */ 67 | bool open_GNSS(void); 68 | 69 | /** 70 | Convert double coordinate data to string 71 | */ 72 | void doubleToString(double longitude, double latitude); 73 | 74 | 75 | /** Get coordinate infomation 76 | 77 | */ 78 | bool getCoordinate(void); 79 | 80 | /** 81 | Aquire GPS sentence 82 | */ 83 | bool dataFlowMode(void); 84 | 85 | /** 86 | Set outpu sentences in NMEA mode 87 | */ 88 | bool enable_NMEA_mode(); 89 | 90 | /** 91 | Disable NMEA mode 92 | */ 93 | bool disable_NMEA_mode(); 94 | 95 | /** 96 | Request NMEA data and save the responce sentence 97 | */ 98 | bool NMEA_read_and_save(const char* type, char* save_buff); 99 | 100 | /** 101 | Read NMEA data 102 | */ 103 | bool read_NMEA(NMEA_type data_type, char* recv_buff); 104 | 105 | /** 106 | Read NMEA GSV sentence 107 | GSV sentence gonna be 6 lines, that's too much content to save as other NMEA data. 108 | save_buff should be 512 Bytes size at least. 109 | */ 110 | bool read_NMEA_GSV(char* save_buff); 111 | }; 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /img/boardManager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_LTE_Arduino_Library/91c9b85d476ad61a340f036b26201d6ad055243d/img/boardManager.png -------------------------------------------------------------------------------- /img/zadig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Wio_LTE_Arduino_Library/91c9b85d476ad61a340f036b26201d6ad055243d/img/zadig.png -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | 2 | ####################################### 3 | # Syntax Coloring Map For Seeed Wio GPS Board 4 | ####################################### 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | Ethernet KEYWORD2 14 | init KEYWORD2 15 | join KEYWORD2 16 | getIP KEYWORD2 17 | str_to_ip KEYWORD2 18 | recoverIP KEYWORD2 19 | networkCheck KEYWORD2 20 | connect KEYWORD2 21 | write KEYWORD2 22 | read KEYWORD2 23 | getSocketStatus KEYWORD2 24 | is_connected KEYWORD2 25 | httpGET KEYWORD2 26 | httpPUT KEYWORD2 27 | close KEYWORD2 28 | 29 | GNSS KEYWORD2 30 | open_GNSS KEYWORD2 31 | close_GNSS KEYWORD2 32 | open_GNSS KEYWORD2 33 | doubleToString KEYWORD2 34 | getCoordinate KEYWORD2 35 | dataFlowMode KEYWORD2 36 | enable_NMEA_mode KEYWORD2 37 | disable_NMEA_mode KEYWORD2 38 | NMEA_read_and_save KEYWORD2 39 | read_NMEA KEYWORD2 40 | read_NMEA_GSV KEYWORD2 41 | 42 | WS2812 KEYWORD2 43 | begin KEYWORD2 44 | getLedNum KEYWORD2 45 | setLedNum KEYWORD2 46 | WS2812Clear KEYWORD2 47 | pureColor KEYWORD2 48 | green KEYWORD2 49 | green KEYWORD2 50 | WS2812Send KEYWORD2 51 | saturation KEYWORD2 52 | rainbowCycle KEYWORD2 53 | colorWheel KEYWORD2 54 | RGBCycle KEYWORD2 55 | 56 | serialPort_init KEYWORD2 57 | AT_bypass KEYWORD2 58 | check_readable KEYWORD2 59 | wait_readable KEYWORD2 60 | flush_serial KEYWORD2 61 | read_string_line KEYWORD2 62 | read_string_until KEYWORD2 63 | read_buffer KEYWORD2 64 | clean_buffer KEYWORD2 65 | send_byte KEYWORD2 66 | send_char KEYWORD2 67 | send_cmd KEYWORD2 68 | send_cmd KEYWORD2 69 | send_cmd_P KEYWORD2 70 | Test_AT KEYWORD2 71 | send_End_Mark KEYWORD2 72 | wait_for_resp KEYWORD2 73 | check_with_cmd KEYWORD2 74 | check_with_cmd KEYWORD2 75 | 76 | WioTracker KEYWORD2 77 | Check_If_Power_On KEYWORD2 78 | Power_On KEYWORD2 79 | VCCB_Power_On KEYWORD2 80 | powerReset KEYWORD2 81 | setURCtoUart1 KEYWORD2 82 | checkSIMStatus KEYWORD2 83 | waitForNetworkRegister KEYWORD2 84 | sendSMS KEYWORD2 85 | readAllRecUnreadSMS KEYWORD2 86 | detectRecUnreadSMS KEYWORD2 87 | readSMS KEYWORD2 88 | readSMS KEYWORD2 89 | deleteSMS KEYWORD2 90 | callUp KEYWORD2 91 | answer KEYWORD2 92 | hangup KEYWORD2 93 | getSignalStrength KEYWORD2 94 | recv KEYWORD2 95 | set_CFUN KEYWORD2 96 | set_SysClock KEYWORD2 97 | module_sleep KEYWORD2 98 | module_wakeup KEYWORD2 99 | AT_PowerDown KEYWORD2 100 | 101 | ####################################### 102 | # Constants (LITERAL1) 103 | ####################################### -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Wio LTE Arduino Library 2 | version=1.0.0 3 | author=Seeed Studio 4 | maintainer=Seeed Studio 5 | sentence=Arduino library to control Wio LTE Arduino Library. 6 | paragraph=Wio LTE is a board combined with STM32F405RGT6 and quectel EC21(4G/3G/GPS) module. 7 | category=Device Control 8 | url=https://github.com/Seeed-Studio/Wio_LTE_Arduino_Library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /stm32f4_ws2812.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Seeed_ws2812.cpp 3 | Arduino library for RGB led WS2812 4 | 5 | Copyright (c) 2017 Seeed Technology Co., Ltd. 6 | Website : www.seeed.cc 7 | Author : lambor 8 | Create Time: April 2017 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #include "stm32f4_ws2812.h" 33 | 34 | #define STM32F40xx (1) 35 | 36 | #define nop() __asm__ __volatile__ ("nop") 37 | #define _DELAY_NOP(x) for(uint32_t i = 0; i < x; i++){nop();} 38 | 39 | #if(STM32F40xx == 1) 40 | #define PARTEN_0_CODE(pin) do{ \ 41 | digitalWrite(pin, HIGH); \ 42 | _DELAY_NOP(21) \ 43 | digitalWrite(pin, LOW); \ 44 | _DELAY_NOP(20) \ 45 | } while(0) 46 | 47 | #define PARTEN_1_CODE(pin) do{ \ 48 | digitalWrite(pin, HIGH); \ 49 | _DELAY_NOP(8) \ 50 | digitalWrite(pin, LOW); \ 51 | _DELAY_NOP(25) \ 52 | } while(0) 53 | #endif 54 | 55 | WS2812::WS2812(uint32_t ledn, uint8_t pin) { 56 | ledNum = ledn; 57 | sigPin = pin; 58 | WS2812Buffer = (uint8_t*)malloc(ledNum * 3); 59 | 60 | } 61 | 62 | void WS2812::begin(void) { 63 | pinMode(sigPin, OUTPUT); 64 | WS2812Clear(); 65 | WS2812Send(); 66 | 67 | } 68 | uint32_t WS2812::getLedNum(void) { 69 | return ledNum; 70 | } 71 | 72 | void WS2812::setLedNum(uint32_t lednum) { 73 | ledNum = lednum; 74 | } 75 | 76 | void WS2812::WS2812Clear(void) { 77 | uint32_t i; 78 | for (i = 0; i < ledNum * 3; i++) { 79 | WS2812Buffer[i] = 0; 80 | } 81 | WS2812Send(); 82 | } 83 | 84 | void WS2812::pureColor(uint8_t mode) { 85 | switch (mode) { 86 | case 0: 87 | for (uint32_t i = 0; i < ledNum; i++) { 88 | WS2812SetRGB(i, 0, 0, 255, brightness); 89 | } 90 | break; 91 | case 1: 92 | for (uint32_t i = 0; i < ledNum; i++) { 93 | WS2812SetRGB(i, 0, 255, 0, brightness); 94 | } 95 | break; 96 | case 2: 97 | for (uint32_t i = 0; i < ledNum; i++) { 98 | WS2812SetRGB(i, 255, 0, 0, brightness); 99 | } 100 | break; 101 | default: break; 102 | } 103 | 104 | } 105 | 106 | void WS2812::WS2812SetHSV(uint32_t led, uint32_t hue, 107 | uint32_t saturation, uint32_t value) { 108 | 109 | if (hue < 1536 && saturation < 256 && value < 256) { 110 | uint8_t red, green, blue; 111 | uint8_t min, max, inc, dec, hquot, hrem; 112 | 113 | if (saturation == 0) { 114 | WS2812SetRGB(led, value, value, value, brightness); 115 | return; 116 | } 117 | 118 | hquot = hue / 256; 119 | hrem = hue % 256; 120 | 121 | max = value; 122 | min = (value * (255 - saturation)) / 255; 123 | inc = (value * ((saturation * hrem) / 255)) / 255; 124 | dec = (value * ((saturation * (255 - hrem)) / 255)) / 255; 125 | 126 | 127 | switch (hquot) { 128 | case 0: 129 | red = max; 130 | green = inc; 131 | blue = min; 132 | break; 133 | case 1: 134 | red = dec; 135 | green = max; 136 | blue = min; 137 | break; 138 | case 2: 139 | red = min; 140 | green = max; 141 | blue = inc; 142 | break; 143 | case 3: 144 | red = min; 145 | green = dec; 146 | blue = max; 147 | break; 148 | case 4: 149 | red = inc; 150 | green = min; 151 | blue = max; 152 | break; 153 | case 5: 154 | red = max; 155 | green = min; 156 | blue = dec; 157 | break; 158 | } 159 | WS2812SetRGB(led, red, green, blue); 160 | } 161 | } 162 | 163 | void WS2812::WS2812SetRGB(uint32_t led, uint8_t red, 164 | uint8_t green, uint8_t blue) { 165 | WS2812Buffer[led * 3] = green; 166 | WS2812Buffer[1 + led * 3] = red; 167 | WS2812Buffer[2 + led * 3] = blue; 168 | } 169 | 170 | void WS2812::WS2812SetRGB(uint32_t led, uint8_t red, 171 | uint8_t green, uint8_t blue, uint8_t brightness) { 172 | WS2812Buffer[led * 3] = green * brightness / 256; 173 | WS2812Buffer[1 + led * 3] = red * brightness / 256; 174 | WS2812Buffer[2 + led * 3] = blue * brightness / 256; 175 | } 176 | 177 | 178 | void WS2812::WS2812Send(void) { 179 | uint32_t c; 180 | static uint32_t endTime = 0; 181 | while (micros() - endTime < 50L); 182 | 183 | noInterrupts(); 184 | 185 | for (c = 0; c < (ledNum * 3); c++) { 186 | for (int b = 7; b >= 0; b--) { 187 | // 1 code 188 | if (WS2812Buffer[c] & (0x01 << b)) { 189 | PARTEN_0_CODE(sigPin); 190 | } 191 | // 0 code 192 | else { 193 | PARTEN_1_CODE(sigPin); 194 | } 195 | } 196 | } 197 | interrupts(); 198 | endTime = micros(); 199 | } 200 | 201 | void WS2812::rainbowCycle(uint8_t wait) { 202 | uint16_t i, j; 203 | for (j = 0; j < 256; j++) { 204 | for (i = 0; i < getLedNum(); i++) { 205 | colorWheel((i + j) & 0xff, i); 206 | } 207 | WS2812Send(); 208 | delay(wait); 209 | } 210 | } 211 | 212 | void WS2812::colorWheel(byte WheelPos, uint8_t n) { 213 | if (WheelPos < 85) { 214 | WS2812SetRGB(n, 0, WheelPos * 3, 255 - WheelPos * 3, brightness); 215 | } else if (WheelPos < 170) { 216 | WheelPos -= 85; 217 | WS2812SetRGB(n, WheelPos * 3, 255 - WheelPos * 3, 0, brightness); 218 | } else { 219 | WheelPos -= 170; 220 | WS2812SetRGB(n, 255 - WheelPos * 3, 0, WheelPos * 3, brightness); 221 | } 222 | } 223 | 224 | void WS2812::RGBCycle(uint16_t wait_ms) { 225 | for (uint32_t i = 0; i < ledNum; i++) { 226 | WS2812SetRGB(i, 0, 0, 255, brightness); 227 | } 228 | WS2812Send(); 229 | delay(wait_ms); 230 | for (uint32_t i = 0; i < ledNum; i++) { 231 | WS2812SetRGB(i, 0, 255, 0, brightness); 232 | } 233 | WS2812Send(); 234 | delay(wait_ms); 235 | for (uint32_t i = 0; i < ledNum; i++) { 236 | WS2812SetRGB(i, 255, 0, 0, brightness); 237 | } 238 | WS2812Send(); 239 | delay(wait_ms); 240 | } 241 | -------------------------------------------------------------------------------- /stm32f4_ws2812.h: -------------------------------------------------------------------------------- 1 | /* 2 | Seeed_ws2812.h 3 | Arduino library for RGB led WS2812 4 | 5 | Copyright (c) 2017 Seeed Technology Co., Ltd. 6 | Website : www.seeed.cc 7 | Author : lambor 8 | Create Time: April 2017 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #ifndef STM32F4_WS2812_h 33 | #define STM32F4_WS2812_h 34 | 35 | #include 36 | #include 37 | 38 | class WS2812 { 39 | 40 | public: 41 | WS2812(uint32_t ledn, uint8_t sigPin); 42 | void begin(void); 43 | uint32_t getLedNum(void); 44 | void setLedNum(uint32_t); 45 | void WS2812Clear(void); 46 | void pureColor(uint8_t); 47 | void WS2812SetRGB(uint32_t led, uint8_t red, 48 | uint8_t green, uint8_t blue); 49 | void WS2812SetRGB(uint32_t led, uint8_t red, 50 | uint8_t green, uint8_t blue, uint8_t light); 51 | void WS2812Send(void); 52 | void WS2812SetHSV(uint32_t led, uint32_t hue, 53 | uint32_t saturation, uint32_t value); 54 | void rainbowCycle(uint8_t wait); 55 | void colorWheel(byte WheelPos, uint8_t n); 56 | void RGBCycle(uint16_t); 57 | 58 | uint8_t sigPin; 59 | uint32_t ledNum; 60 | uint8_t brightness = 255; 61 | uint8_t* WS2812Buffer; 62 | 63 | }; 64 | 65 | #endif 66 | /** 67 | STM32F4_WS2812_h 68 | */ -------------------------------------------------------------------------------- /wio_tracker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | wiowio_trackerlte.cpp 3 | A library for SeeedStudio Wio LTE Tracker 4 | 5 | Copyright (c) 2017 Seeed Technology Co., Ltd. 6 | Website : www.seeed.cc 7 | Author : lawliet zou, lambor 8 | Create Time: April 2017 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #include 33 | #include "wio_tracker.h" 34 | 35 | // WioTracker* WioTracker::inst; 36 | 37 | void Peripherial_Init() { 38 | for (int i = 0; i < 64; i++) { 39 | pinMode(i, INPUT); 40 | } 41 | } 42 | 43 | WioTracker::WioTracker() { 44 | Peripherial_Init(); 45 | 46 | #if(1 == RGB_LED_ON) 47 | pinMode(RGB_LED_PWR_PIN, OUTPUT); 48 | digitalWrite(RGB_LED_PWR_PIN, HIGH); // RGB LED Power 49 | #endif 50 | } 51 | 52 | bool WioTracker::init(void) { 53 | if (!check_with_cmd(F("AT\r\n"), "OK\r\n", CMD)) { 54 | return false; 55 | } 56 | 57 | if (!check_with_cmd(F("AT+CPIN?\r\n"), "OK\r\n", CMD)) { 58 | return false; 59 | } 60 | 61 | if (!checkSIMStatus()) { 62 | return false; 63 | } 64 | return true; 65 | } 66 | 67 | bool WioTracker::Check_If_Power_On(void) { 68 | if (check_with_cmd(F("AT\r\n"), "OK", CMD, 2, 2000)) { 69 | // Set URC port to uart1 70 | // setURCtoUart1(); 71 | return true; 72 | } 73 | return false; 74 | } 75 | 76 | void WioTracker::Power_On(void) { 77 | int pwr_status = 1; 78 | int errCnt = 0; 79 | bool is_power_on = false; 80 | 81 | serialPort_init(); 82 | 83 | is_power_on = Check_If_Power_On(); 84 | 85 | #if((1 == WIO_TRACKER_LTE_V12) && (CODEC_PWR_ON == 1)) 86 | pinMode(CODEC_I2C_PWR_PIN, OUTPUT); 87 | digitalWrite(CODEC_I2C_PWR_PIN, HIGH); // CODEC Power 88 | #endif 89 | 90 | #if(1 == MODULE_PWR_ON) 91 | pinMode(MODULE_PWR_PIN, OUTPUT); 92 | digitalWrite(MODULE_PWR_PIN, HIGH); // Module Power Default HIGH 93 | #endif 94 | 95 | #if(1 == GROVE_PWR_ON) 96 | pinMode(ENABLE_VCCB_PIN, OUTPUT); 97 | digitalWrite(ENABLE_VCCB_PIN, HIGH); // VCC_B Enable pin 98 | #endif 99 | 100 | #if(1==ANTENNA_PWR_ON) 101 | pinMode(ANT_PWR_PIN, OUTPUT); 102 | digitalWrite(ANT_PWR_PIN, HIGH); // antenna power enable 103 | #endif 104 | pinMode(WAKEUP_IN_PIN, OUTPUT); 105 | digitalWrite(WAKEUP_IN_PIN, LOW); 106 | if (!is_power_on) { 107 | pinMode(PWR_KEY_PIN, OUTPUT); 108 | digitalWrite(PWR_KEY_PIN, LOW); 109 | digitalWrite(PWR_KEY_PIN, HIGH); 110 | delay(800); 111 | digitalWrite(PWR_KEY_PIN, LOW); 112 | } 113 | 114 | } 115 | 116 | void WioTracker::VCCB_Power_On(void) { 117 | digitalWrite(ENABLE_VCCB_PIN, HIGH); 118 | } 119 | 120 | void WioTracker::powerReset(void) { 121 | 122 | } 123 | 124 | bool WioTracker::setURCtoUart1(void) { 125 | return check_with_cmd("AT+QURCCFG=\"urcport\",\"uart1\"", "OK", CMD, 2); 126 | } 127 | 128 | bool WioTracker::checkSIMStatus(void) { 129 | char Buffer[32]; 130 | int count = 0; 131 | clean_buffer(Buffer, 32); 132 | while (count < 3) { 133 | send_cmd("AT+CPIN?\r\n"); 134 | read_buffer(Buffer, 32, DEFAULT_TIMEOUT); 135 | if ((NULL != strstr(Buffer, "+CPIN: READY"))) { 136 | break; 137 | } 138 | count++; 139 | delay(300); 140 | } 141 | if (count == 3) { 142 | return false; 143 | } 144 | return true; 145 | } 146 | 147 | bool WioTracker::waitForNetworkRegister(void) { 148 | bool ret; 149 | int errCounts = 0; 150 | 151 | // Check Registration Status 152 | while (1) { 153 | if (check_with_cmd("AT+CEREG?\r\n", "+CEREG: 0,1", CMD, 2, 2000) || // Home network 154 | check_with_cmd("AT+CEREG?\r\n", "+CEREG: 0,5", CMD, 2, 2000)) { // Roaming 155 | ret = true; 156 | break; 157 | } 158 | errCounts++; 159 | if (errCounts > 15) { // Check for 30 times 160 | ret = false; 161 | break; 162 | } 163 | delay(1000); 164 | } 165 | 166 | errCounts = 0; 167 | while (1) { 168 | if (check_with_cmd("AT+CGREG?\r\n", "+CGREG: 0,1", CMD, 2, 2000) || // Home network 169 | check_with_cmd("AT+CGREG?\r\n", "+CGREG: 0,5", CMD, 2, 2000)) { // Roaming 170 | ret = true; 171 | break; 172 | } 173 | errCounts++; 174 | if (errCounts > 15) { // Check for 30 times 175 | ret = false; 176 | break; 177 | } 178 | delay(1000); 179 | } 180 | 181 | return ret; 182 | } 183 | 184 | bool WioTracker::sendSMS(char* number, char* data) { 185 | //char cmd[32]; 186 | if (!check_with_cmd(F("AT+CMGF=1\r\n"), "OK\r\n", CMD)) { // Set message mode to ASCII 187 | return false; 188 | } 189 | delay(500); 190 | flush_serial(); 191 | send_cmd("AT+CMGS=\""); 192 | send_cmd(number); 193 | if (!check_with_cmd(F("\"\r\n"), ">", CMD)) { 194 | return false; 195 | } 196 | delay(1000); 197 | send_cmd(data); 198 | delay(500); 199 | send_End_Mark(); 200 | return wait_for_resp("OK\r\n", CMD, 10); 201 | } 202 | 203 | bool WioTracker::readAllRecUnreadSMS(void) { 204 | /* 205 | AT+CMGL="REC UNREAD" 206 | */ 207 | 208 | // Set SMS as text mode 209 | if (!check_with_cmd(F("AT+CMGF=1\r\n"), "OK", CMD)) { // Set message mode to ASCII 210 | return false; 211 | } else { 212 | #if(UART_DEBUG==true) 213 | DEBUG("Set SMS as text mode!"); 214 | #endif 215 | } 216 | 217 | send_cmd("AT+CMGL=\"REC UNREAD"); 218 | if (!check_with_cmd(F("\"\r\n"), "OK", CMD, true)) { 219 | flush_serial(); 220 | } else { 221 | return false; 222 | } 223 | 224 | return true; 225 | } 226 | 227 | int16_t WioTracker::detectRecUnreadSMS(void) { 228 | /* 229 | AT+CMGL="REC UNREAD" 230 | 231 | +CMGL: 0,"REC UNREAD","xxxxxxx",,"17/07/24,14:45:43+32",161,6 232 | xxxxxxx 233 | */ 234 | 235 | int i; 236 | char* s, *ps, *pe; 237 | char Buffer[64]; 238 | char str_index[8]; 239 | 240 | clean_buffer(Buffer, 64); 241 | send_cmd("AT+CMGL=\"REC UNREAD\"\r\n"); 242 | read_buffer(Buffer, 64, 2, 1000); 243 | 244 | DEBUG("SMS Buffer: "); 245 | DEBUG(Buffer); 246 | 247 | if (NULL != (s = strstr(Buffer, "+CMGL:"))) { 248 | ps = s + 7; 249 | pe = strstr(s, "\""); 250 | pe -= 2; 251 | 252 | for (i = 0; ps + i <= pe; i++) { 253 | str_index[i] = *(ps + i); 254 | } 255 | str_index[i] = '\0'; 256 | } else { 257 | return -1; 258 | } 259 | 260 | // Check if str_index valid 261 | for (i = 0; i < strlen(str_index); i++) { 262 | if (!('0' <= str_index[i] && str_index[i] <= '9')) { 263 | #if(UART_DEBUG) 264 | ERROR("SMS index invalid\r\n"); 265 | #endif 266 | return -1; 267 | } 268 | } 269 | 270 | return atoi(str_index); 271 | } 272 | 273 | bool WioTracker::readSMS(int messageIndex, char* message, int length, char* phone, char* datetime) { 274 | /* Response is like: 275 | AT+CMGR=2 276 | 277 | +CMGR: "REC READ","XXXXXXXXXXX","","14/10/09,17:30:17+08" 278 | SMS text here 279 | 280 | So we need (more or lees), 80 chars plus expected message length in buffer. CAUTION FREE MEMORY 281 | */ 282 | 283 | int i = 0; 284 | char Buffer[80 + length]; 285 | //char cmd[16]; 286 | char num[4]; 287 | char* p, *p2, *s; 288 | 289 | check_with_cmd(F("AT+CMGF=1\r\n"), "OK\r\n", CMD); 290 | delay(1000); 291 | //sprintf(cmd,"AT+CMGR=%d\r\n",messageIndex); 292 | //send_cmd(cmd); 293 | send_cmd("AT+CMGR="); 294 | itoa(messageIndex, num, 10); 295 | send_cmd(num); 296 | send_cmd("\r\n"); 297 | clean_buffer(Buffer, sizeof(Buffer)); 298 | read_buffer(Buffer, sizeof(Buffer)); 299 | 300 | if (NULL != (s = strstr(Buffer, "READ\",\""))) { 301 | // Extract phone number string 302 | p = strstr(s, ","); 303 | p2 = p + 2; //We are in the first phone number character 304 | p = strstr((char*)(p2), "\""); 305 | if (NULL != p) { 306 | i = 0; 307 | while (p2 < p) { 308 | phone[i++] = *(p2++); 309 | } 310 | phone[i] = '\0'; 311 | } 312 | // Extract date time string 313 | p = strstr((char*)(p2), ","); 314 | p2 = p + 1; 315 | p = strstr((char*)(p2), ","); 316 | p2 = p + 2; //We are in the first date time character 317 | p = strstr((char*)(p2), "\""); 318 | if (NULL != p) { 319 | i = 0; 320 | while (p2 < p) { 321 | datetime[i++] = *(p2++); 322 | } 323 | datetime[i] = '\0'; 324 | } 325 | if (NULL != (s = strstr(s, "\r\n"))) { 326 | i = 0; 327 | p = s + 2; 328 | while ((*p != '\r') && (i < length - 1)) { 329 | message[i++] = *(p++); 330 | } 331 | message[i] = '\0'; 332 | } 333 | return true; 334 | } 335 | return false; 336 | } 337 | 338 | bool WioTracker::readSMS(int messageIndex, char* message, int length) { 339 | int i = 0; 340 | char Buffer[100]; 341 | //char cmd[16]; 342 | char num[4]; 343 | char* p, *s; 344 | 345 | check_with_cmd(F("AT+CMGF=1\r\n"), "OK\r\n", CMD); 346 | delay(1000); 347 | send_cmd("AT+CMGR="); 348 | itoa(messageIndex, num, 10); 349 | send_cmd(num); 350 | // send_cmd("\r\n"); 351 | send_cmd("\r\n"); 352 | // sprintf(cmd,"AT+CMGR=%d\r\n",messageIndex); 353 | // send_cmd(cmd); 354 | clean_buffer(Buffer, sizeof(Buffer)); 355 | read_buffer(Buffer, sizeof(Buffer), DEFAULT_TIMEOUT); 356 | if (NULL != (s = strstr(Buffer, "+CMGR:"))) { 357 | if (NULL != (s = strstr(s, "\r\n"))) { 358 | p = s + 2; 359 | while ((*p != '\r') && (i < length - 1)) { 360 | message[i++] = *(p++); 361 | } 362 | message[i] = '\0'; 363 | return true; 364 | } 365 | } 366 | return false; 367 | } 368 | 369 | bool WioTracker::deleteSMS(int index) { 370 | //char cmd[16]; 371 | char num[4]; 372 | //sprintf(cmd,"AT+CMGD=%d\r\n",index); 373 | send_cmd("AT+CMGD="); 374 | if (index > 998) { 375 | send_cmd("1,4"); 376 | } else { 377 | itoa(index, num, 10); 378 | send_cmd(num); 379 | } 380 | // We have to wait OK response 381 | //return check_with_cmd(cmd,"OK\r\n",CMD); 382 | return check_with_cmd(F("\r"), "OK\r\n", CMD); 383 | } 384 | 385 | 386 | bool WioTracker::callUp(char* number) { 387 | //char cmd[24]; 388 | if (!check_with_cmd(F("AT+COLP=1\r\n"), "OK\r\n", CMD)) { 389 | return false; 390 | } 391 | delay(1000); 392 | //HACERR quitar SPRINTF para ahorar memoria ??? 393 | //sprintf(cmd,"ATD%s;\r\n", number); 394 | //send_cmd(cmd); 395 | send_cmd("ATD"); 396 | send_cmd(number); 397 | send_cmd(";\r\n"); 398 | return true; 399 | } 400 | 401 | void WioTracker::answer(void) { 402 | send_cmd("ATA\r\n"); //TO CHECK: ATA doesnt return "OK" ???? 403 | } 404 | 405 | bool WioTracker::hangup(void) { 406 | return check_with_cmd(F("ATH\r\n"), "OK\r\n", CMD); 407 | } 408 | 409 | 410 | bool WioTracker::getSignalStrength(int* buffer) { 411 | //AT+CSQ --> 6 + CR = 10 412 | //+CSQ: , --> CRLF + 5 + CRLF = 9 413 | //OK --> CRLF + 2 + CRLF = 6 414 | 415 | byte i = 0; 416 | char Buffer[26]; 417 | char* p, *s; 418 | char buffers[4]; 419 | flush_serial(); 420 | send_cmd("AT+CSQ\r"); 421 | clean_buffer(Buffer, 26); 422 | read_buffer(Buffer, 26, DEFAULT_TIMEOUT); 423 | if (NULL != (s = strstr(Buffer, "+CSQ:"))) { 424 | s = strstr((char*)(s), " "); 425 | s = s + 1; //We are in the first phone number character 426 | p = strstr((char*)(s), ","); //p is last character """ 427 | if (NULL != s) { 428 | i = 0; 429 | while (s < p) { 430 | buffers[i++] = *(s++); 431 | } 432 | buffers[i] = '\0'; 433 | } 434 | *buffer = atoi(buffers); 435 | return true; 436 | } 437 | return false; 438 | } 439 | 440 | int WioTracker::recv(char* buf, int len) { 441 | clean_buffer(buf, len); 442 | read_buffer(buf, len); //Ya he llamado a la funcion con la longitud del buffer - 1 y luego le estoy añadiendo el 0 443 | return strlen(buf); 444 | } 445 | 446 | 447 | /*************************** Module consumption control **************************/ 448 | 449 | bool WioTracker::set_CFUN(int mode) { 450 | char buf_w[20]; 451 | clean_buffer(buf_w, 20); 452 | sprintf(buf_w, "AT+CFUN=%d", mode); 453 | send_cmd(buf_w); 454 | return check_with_cmd("\n\r", "OK", CMD, 2, 2000, UART_DEBUG); 455 | } 456 | 457 | bool WioTracker::set_SysClock(int mode) { 458 | char buf_w[20]; 459 | clean_buffer(buf_w, 20); 460 | sprintf(buf_w, "AT+QSCLK=%d", mode); 461 | send_cmd(buf_w); 462 | return check_with_cmd("\r\n", "OK", CMD, 2, 2000); 463 | } 464 | 465 | bool WioTracker::AT_PowerDown(void) { 466 | return check_with_cmd("AT+QPOWD=1\n\r", "NORMAL POWER DOWN", CMD, 5, 2000, UART_DEBUG); 467 | } 468 | 469 | // AT CMD module sleep 470 | bool WioTracker::module_sleep() { 471 | bool ret; 472 | 473 | pinMode(WAKEUP_IN_PIN, OUTPUT); 474 | pinMode(DTR_PIN, INPUT); 475 | // Send Sleep AT CMD 476 | return set_SysClock(1); 477 | 478 | } 479 | 480 | // AT CMD wakeup module 481 | bool WioTracker::module_wakeup() { 482 | bool ret; 483 | pinMode(WAKEUP_IN_PIN, OUTPUT); 484 | pinMode(DTR_PIN, OUTPUT); 485 | digitalWrite(DTR_PIN, LOW); 486 | digitalWrite(DTR_PIN, LOW); 487 | delay(1000); 488 | // Send Wakeup AT CMD 489 | ret = set_SysClock(0); 490 | if (ret) { 491 | digitalWrite(DTR_PIN, INPUT); 492 | } 493 | return ret; 494 | } 495 | 496 | 497 | /*************************** End of Module consumption control **************************/ -------------------------------------------------------------------------------- /wio_tracker.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiwio_trackerolte.h 3 | A library for SeeedStudio Wio Tracker LTE 4 | 5 | Copyright (c) 2017 Seeed Technology Co., Ltd. 6 | Website : www.seeed.cc 7 | Author : lawliet zou, lambor 8 | Create Time: April 2017 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #ifndef __WIO_TRACKER_H__ 33 | #define __WIO_TRACKER_H__ 34 | 35 | #include "UART_Interface.h" 36 | #include "itoa.h" 37 | #include "board_config.h" 38 | 39 | /** WioTracker class. 40 | used to realize WioTracker communication 41 | */ 42 | 43 | class WioTracker { 44 | public: 45 | /** Create WioTracker instance 46 | @param number default phone number during mobile communication 47 | */ 48 | 49 | WioTracker(); 50 | 51 | /** get instance of WioTracker class 52 | */ 53 | // static WioTracker* getInstance() { 54 | // return inst; 55 | // }; 56 | 57 | /** initialize WioTracker module including SIM card check & signal strength 58 | @return true if connected, false otherwise 59 | */ 60 | 61 | bool init(void); 62 | 63 | 64 | /** check if WioTracker module is powered on or not 65 | @returns 66 | true on success 67 | false on error 68 | */ 69 | bool Check_If_Power_On(void); 70 | 71 | 72 | /** power Up WioTracker module 73 | @param pin D13 is connectted to a power switch IC, the power is on when pin D13 pull up. 74 | @returns 75 | 76 | */ 77 | void Power_On(void); 78 | void VCCB_Power_On(void); 79 | 80 | /** power reset for SIM800 board 81 | @param pin (preconfigurated as OUTPUT) 82 | @returns 83 | 84 | */ 85 | void powerReset(void); 86 | 87 | /** Set URC port to uart1 88 | @returns 89 | true on successfully 90 | false on failed 91 | */ 92 | bool setURCtoUart1(void); 93 | 94 | /** check SIM card status 95 | @returns 96 | true on SIM card Ready 97 | false on error 98 | */ 99 | bool checkSIMStatus(void); 100 | 101 | /** Wait for network register 102 | @returns 103 | true on success 104 | false on error 105 | */ 106 | bool waitForNetworkRegister(void); 107 | 108 | 109 | /** send text SMS 110 | @param *number phone number which SMS will be send to 111 | @param *data message that will be send to 112 | @returns 113 | true on success 114 | false on error 115 | */ 116 | bool sendSMS(char* number, char* data); 117 | 118 | /** Set all REC UNREAD SMS to REC READ 119 | @returns 120 | true on success 121 | false on error 122 | */ 123 | bool readAllRecUnreadSMS(void); 124 | 125 | /** Detect REC UNREAD SMS 126 | @returns 127 | -1 on no REC UNREAD SMS detected 128 | index of REC UNREAD SMS detected 129 | */ 130 | int16_t detectRecUnreadSMS(void); 131 | 132 | /** read SMS, phone and date if getting a SMS message. It changes SMS status to READ 133 | @param messageIndex SIM position to read 134 | @param message buffer used to get SMS message 135 | @param length length of message buffer 136 | @param phone buffer used to get SMS's sender phone number 137 | @param datetime buffer used to get SMS's send datetime 138 | @returns 139 | true on success 140 | false on error 141 | */ 142 | bool readSMS(int messageIndex, char* message, int length, char* phone, char* datetime); 143 | 144 | /** read SMS if getting a SMS message 145 | @param buffer buffer that get from WioTracker module(when getting a SMS, WioTracker module will return a buffer array) 146 | @param message buffer used to get SMS message 147 | @param check whether to check phone number(we may only want to read SMS from specified phone number) 148 | @returns 149 | true on success 150 | false on error 151 | */ 152 | bool readSMS(int messageIndex, char* message, int length); 153 | 154 | /** delete SMS message on SIM card 155 | @param index the index number which SMS message will be delete 156 | index > 998, delete all message stored on SIM card 157 | @returns 158 | true on success 159 | false on error 160 | */ 161 | bool deleteSMS(int index); 162 | 163 | /** call someone 164 | @param number the phone number which you want to call 165 | @returns 166 | true on success 167 | false on error 168 | */ 169 | bool callUp(char* number); 170 | 171 | /** auto answer if coming a call 172 | @returns 173 | */ 174 | void answer(void); 175 | 176 | /** hang up if coming a call 177 | @returns 178 | true on success 179 | false on error 180 | */ 181 | bool hangup(void); 182 | 183 | /** get Signal Strength from SIM900 (see AT command: AT+CSQ) as integer 184 | @param 185 | @returns 186 | true on success 187 | false on error 188 | */ 189 | bool getSignalStrength(int* buffer); 190 | 191 | int recv(char* buf, int len); 192 | 193 | /** Set phone functionarity mode 194 | @param 195 | 0, least consumption 1, 4 196 | 1, standard mode 197 | 4, shut down RF send and receive function 198 | */ 199 | bool set_CFUN(int mode); 200 | 201 | /** Set module system clock 202 | @param 203 | 0 Disable slow clock 204 | 1 Enable slow clock, and it is controlled by DTR 205 | */ 206 | bool set_SysClock(int mode); 207 | 208 | /** Set module into sleep mode 209 | @param 210 | @return 211 | true on sleep successfully 212 | false on sleep failed 213 | */ 214 | bool module_sleep(void); 215 | 216 | /** Set module wakeup from sleep mode 217 | @param 218 | @return 219 | true on wakeup successfully 220 | false on wakeup failed 221 | */ 222 | bool module_wakeup(void); 223 | 224 | /** 225 | Turn off module power buy AT commnad 226 | */ 227 | bool AT_PowerDown(void); 228 | 229 | #if (1 == WIO_TRACKER_LTE_V11) 230 | const int DTR_PIN = 1; // PA1 231 | const int BAT_C_PIN = 16; // PB0 232 | const int RGB_LED_PIN = 17; // PB1 233 | const int MODULE_PWR_PIN = 18; // PB2 234 | const int ENABLE_VCCB_PIN = 26; // PB10 235 | const int ANT_PWR_PIN = 28; // PB12 236 | const int STATUS_PIN = 31; // PB15 237 | const int WAKEUP_IN_PIN = 32; // PC0 238 | const int AP_READY_PIN = 33; // PC1 239 | const int WAKEUP_DISABLE_PIN = 34; // PC2 240 | const int RESET_MODULE_PIN = 35; // PC3 241 | const int PWR_KEY_PIN = 36; // PC4 242 | #elif (1 == WIO_TRACKER_LTE_V12) 243 | const int DTR_PIN = 1; // PA1 244 | const int RGB_LED_PWR_PIN = 8; // PA8 245 | const int SD_PWR_PIN = 15; // PA15 246 | const int BAT_C_PIN = 16; // PB0 247 | const int RGB_LED_PIN = 17; // PB1 248 | const int MODULE_PWR_PIN = 21; // PB5 249 | const int ENABLE_VCCB_PIN = 26; // PB10 250 | const int ANT_PWR_PIN = 28; // PB12 251 | const int STATUS_PIN = 31; // PB15 252 | const int WAKEUP_IN_PIN = 32; // PC0 253 | const int AP_READY_PIN = 33; // PC1 254 | const int WAKEUP_DISABLE_PIN = 34; // PC2 255 | const int RESET_MODULE_PIN = 35; // PC3 256 | const int PWR_KEY_PIN = 36; // PC4 257 | const int CODEC_I2C_PWR_PIN = 37; // PC5 258 | #endif 259 | }; 260 | #endif 261 | --------------------------------------------------------------------------------