├── LICENSE ├── README.md ├── SNIPE.cpp ├── SNIPE.h ├── docs ├── CodeZoo_LoRa_Module_ATCommands.pdf └── CodeZoo_LoRa_Module_V2_Shield_Schematic.pdf ├── examples ├── DHT_Recv │ └── DHT_Recv.ino ├── DHT_Recv2 │ └── DHT_Recv2.ino ├── DHT_Send2 │ └── DHT_Send2.ino ├── LoRaPingPongTest │ └── LoRaPingPongTest.ino ├── LoRaPropertySetGet │ └── LoRaPropertySetGet.ino ├── LoRa_GPS_Send │ └── LoRa_GPS_Send.ino ├── LoRa_LED_Recv │ └── LoRa_LED_Recv.ino ├── LoRa_LED_Send │ └── LoRa_LED_Send.ino ├── LoRa_RGB_Recv │ ├── LoRa_RGB_Recv.ino │ └── LoRa_RGB_Recv.jpeg ├── LoRa_RGB_Send │ ├── LoRa_RGB_Send.ino │ └── RGB_Send_Device.jpeg ├── WiFiClient_lora │ └── WiFiClient_lora.ino ├── class_Recv │ └── class_Recv.ino └── class_Send │ └── class_Send.ino └── keywords.txt /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SNIPE 2 | CodeZoo Arduino LoRa Module Library & Example 3 | 4 | # CodeZoo LoRa Arduino Shield 5 | ![lora](https://user-images.githubusercontent.com/22319034/46274208-97a77a80-c593-11e8-82dd-04ed77d9ba0b.png) 6 | -------------------------------------------------------------------------------- /SNIPE.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * A library for controlling SNIPE LoRa radio. 3 | * 4 | * @Author Rooney.Jang 5 | * @Date 08/28/2018 6 | * 7 | */ 8 | 9 | #include "Arduino.h" 10 | #include "SNIPE.h" 11 | 12 | extern "C" { 13 | #include "string.h" 14 | #include "stdlib.h" 15 | } 16 | 17 | /* 18 | @param serial Needs to be an already opened Stream ({Software/Hardware}Serial) to write to and read from. 19 | */ 20 | SNIPE::SNIPE(Stream& serial): 21 | _serial(serial) 22 | { 23 | _timeOut = 2000; /* default Timeout */ 24 | _serial.setTimeout( (_timeOut+500) ); /* +500ms, LoRa TX/RX Timeout default 2000 */ 25 | } 26 | 27 | bool SNIPE::lora_init() 28 | { 29 | int cnt = 10; //retry count 30 | 31 | String ret = sendRawCommand(F("AT")); 32 | if (!ret.startsWith("OK")) 33 | { 34 | while(cnt){ 35 | cnt--; 36 | delay(1000); 37 | 38 | ret = sendRawCommand(F("AT")); 39 | if (ret.startsWith("OK")) 40 | break; 41 | } 42 | if(cnt) 43 | return true; 44 | else 45 | return false; 46 | } 47 | else 48 | { 49 | return true; 50 | } 51 | } 52 | 53 | void SNIPE::lora_reset() 54 | { 55 | sendRawCommand(F("ATZ")); 56 | } 57 | 58 | 59 | String SNIPE::lora_getFreq() 60 | { 61 | String ret = sendRawCommand(F("AT+FREQ=?")); 62 | 63 | ret.trim(); 64 | 65 | return ret; 66 | } 67 | 68 | bool SNIPE::lora_setFreq(int freq) 69 | { 70 | String ret = sendRawCommand("AT+FREQ=" + (String)freq); 71 | if (ret.startsWith("OK")) 72 | { 73 | return true; 74 | } 75 | else 76 | { 77 | return false; 78 | } 79 | } 80 | 81 | String SNIPE::lora_getTxp() 82 | { 83 | String ret = sendRawCommand(F("AT+TXP=?")); 84 | ret.trim(); 85 | 86 | return ret; 87 | } 88 | 89 | bool SNIPE::lora_setTxp(int txp) 90 | { 91 | String ret = sendRawCommand("AT+TXP=" + (String)txp); 92 | if (ret.startsWith("OK")) 93 | { 94 | return true; 95 | } 96 | else 97 | { 98 | return false; 99 | } 100 | } 101 | 102 | String SNIPE::lora_getSf() 103 | { 104 | String ret = sendRawCommand(F("AT+SF=?")); 105 | ret.trim(); 106 | 107 | return ret; 108 | } 109 | 110 | bool SNIPE::lora_setSf(int sf) 111 | { 112 | String ret = sendRawCommand("AT+SF=" + (String)sf); 113 | if (ret.startsWith("OK")) 114 | { 115 | return true; 116 | } 117 | else 118 | { 119 | return false; 120 | } 121 | } 122 | 123 | String SNIPE::lora_getRxtout() 124 | { 125 | String ret = sendRawCommand(F("AT+RXTOUT=?")); 126 | ret.trim(); 127 | 128 | return ret; 129 | } 130 | 131 | bool SNIPE::lora_setRxtout(int rxtout) 132 | { 133 | /* Serial timeout calibration */ 134 | if(_timeOut < rxtout){ 135 | _timeOut = rxtout; 136 | _serial.setTimeout( (_timeOut+500) ); 137 | } 138 | 139 | String ret = sendRawCommand("AT+RXTOUT=" + (String)rxtout); 140 | if (ret.startsWith("OK")) 141 | { 142 | return true; 143 | } 144 | else 145 | { 146 | return false; 147 | } 148 | } 149 | 150 | String SNIPE::lora_getTxtout() 151 | { 152 | String ret = sendRawCommand(F("AT+TXTOUT=?")); 153 | ret.trim(); 154 | 155 | return ret; 156 | } 157 | 158 | bool SNIPE::lora_setTxtout(int txtout) 159 | { 160 | /* Serial timeout calibration */ 161 | if(_timeOut < txtout){ 162 | _timeOut = txtout; 163 | _serial.setTimeout( (_timeOut+500) ); 164 | } 165 | 166 | String ret = sendRawCommand("AT+TXTOUT=" + (String)txtout); 167 | if (ret.startsWith("OK")) 168 | { 169 | return true; 170 | } 171 | else 172 | { 173 | return false; 174 | } 175 | } 176 | 177 | bool SNIPE::lora_setAESMode(int mode) 178 | { 179 | String ver; 180 | switch (mode) 181 | { 182 | case 0: 183 | ver = sendRawCommand(F("AT+USEAES=0")); //Set AES Disable mode. 184 | break; 185 | case 1: 186 | ver = sendRawCommand(F("AT+USEAES=1")); //Set AES Enable mode. 187 | break; 188 | default: 189 | return false; 190 | } 191 | if (ver.startsWith("OK")) 192 | { 193 | return true; 194 | } 195 | else 196 | { 197 | return false; 198 | } 199 | } 200 | 201 | String SNIPE::lora_getAppKey() 202 | { 203 | String ret = sendRawCommand(F("AT+APPKEY=?")); 204 | ret.trim(); 205 | 206 | return ret; 207 | } 208 | 209 | bool SNIPE::lora_setAppKey(String appKEY) 210 | { 211 | String command = ""; 212 | 213 | if (appKEY.length() != 47 ) 214 | { 215 | // Serial.println("The parameter appKEY is set incorrectly!"); 216 | return false; 217 | } 218 | 219 | command = "AT+APPKEY=" + appKEY; 220 | // Serial.println(command); 221 | String ret = sendRawCommand(command); 222 | if (ret.startsWith("OK")) 223 | { 224 | return true; 225 | } 226 | else 227 | { 228 | return false; 229 | } 230 | } 231 | 232 | String SNIPE::lora_getRssi() 233 | { 234 | String ret = sendRawCommand(F("AT+RSSI=?")); 235 | ret.trim(); 236 | 237 | return ret; 238 | } 239 | 240 | String SNIPE::lora_getSnr() 241 | { 242 | String ret = sendRawCommand(F("AT+SNR=?")); 243 | ret.trim(); 244 | 245 | return ret; 246 | } 247 | 248 | String SNIPE::lora_getVersion() 249 | { 250 | String ret = sendRawCommand(F("AT+VER=?")); 251 | ret.trim(); 252 | 253 | return ret; 254 | } 255 | 256 | bool SNIPE::lora_setConf() 257 | { 258 | String ret = sendRawCommand("AT+LORASET"); 259 | if (ret.startsWith("OK")) 260 | { 261 | return true; 262 | } 263 | else 264 | { 265 | return false; 266 | } 267 | } 268 | 269 | bool SNIPE::lora_send(String Text) 270 | { 271 | String command = ""; 272 | 273 | if (Text.length() > 120 ) 274 | { 275 | Serial.println("The number of characters exceeded 120!"); 276 | return false; 277 | } 278 | 279 | command = "AT+SEND=" + Text; 280 | // Serial.println(command); 281 | String ret = sendRawCommand(command); 282 | if (ret.startsWith("OK")) 283 | { 284 | return true; 285 | } 286 | else 287 | { 288 | return false; 289 | } 290 | } 291 | 292 | bool SNIPE::lora_sendBinary(String Hex) 293 | { 294 | String command = ""; 295 | 296 | if (Hex.length() > 240 ) 297 | { 298 | Serial.println("The number of hex characters exceeded 240!"); 299 | return false; 300 | } 301 | 302 | command = "AT+SENDB=" + Hex; 303 | // Serial.println(command); 304 | String ret = sendRawCommand(command); 305 | if (ret.startsWith("OK")) 306 | { 307 | return true; 308 | } 309 | else 310 | { 311 | return false; 312 | } 313 | } 314 | 315 | String SNIPE::lora_recv() 316 | { 317 | String ret = sendRawCommand(F("AT+RECV")); 318 | ret.trim(); 319 | 320 | return ret; 321 | } 322 | 323 | String SNIPE::lora_recvBinary() 324 | { 325 | String ret = sendRawCommand(F("AT+RECVB")); 326 | ret.trim(); 327 | 328 | return ret; 329 | } 330 | 331 | String SNIPE::sendRawCommand(String command) 332 | { 333 | String ret; 334 | 335 | delay(100); 336 | 337 | while(_serial.available()) 338 | _serial.read(); 339 | 340 | _serial.println(command); 341 | ret = _serial.readStringUntil('\n'); 342 | ret.trim(); 343 | 344 | return ret; 345 | } 346 | -------------------------------------------------------------------------------- /SNIPE.h: -------------------------------------------------------------------------------- 1 | /* 2 | * A library for controlling SNIPE LoRa radio. 3 | * 4 | * @Author Rooney.Jang 5 | * @Date 08/28/2018 6 | * 7 | */ 8 | 9 | #ifndef SNIPE_h 10 | #define SNIPE_h 11 | 12 | #define LORA_AES_OFF 0 13 | #define LORA_AES_ON 1 14 | 15 | #define LORA_CH_1 1 //921.9 Mhz 16 | #define LORA_CH_2 2 //922.1 Mhz 17 | #define LORA_CH_3 3 //922.3 Mhz 18 | #define LORA_CH_4 4 //922.5 Mhz 19 | #define LORA_CH_5 5 //922.7 Mhz 20 | #define LORA_CH_6 6 //922.9 Mhz 21 | #define LORA_CH_7 7 //923.1 Mhz 22 | #define LORA_CH_8 8 //923.3 Mhz 23 | 24 | #define LORA_SF_7 7 25 | #define LORA_SF_8 8 26 | #define LORA_SF_9 9 27 | #define LORA_SF_10 10 28 | #define LORA_SF_11 11 29 | #define LORA_SF_12 12 30 | #include "Arduino.h" 31 | 32 | class SNIPE 33 | { 34 | public: 35 | 36 | /* 37 | * A simplified constructor taking only a Stream ({Software/Hardware}Serial) object. 38 | * The serial port should already be initialised when initialising this library. 39 | */ 40 | SNIPE(Stream& serial); 41 | 42 | /* 43 | * Initialization the module. 44 | */ 45 | bool lora_init(void); 46 | 47 | /* 48 | * Reset the module. 49 | */ 50 | void lora_reset(void); 51 | 52 | /* 53 | * Get the frequency of the module. 54 | */ 55 | String lora_getFreq(void); 56 | 57 | /* 58 | * Set the frequency of the module. 59 | */ 60 | bool lora_setFreq(int freq); 61 | 62 | /* 63 | * Get the Tx Power of the module. 64 | */ 65 | String lora_getTxp(void); 66 | 67 | /* 68 | * Set the Tx Power of the module. 69 | */ 70 | bool lora_setTxp(int txp); 71 | 72 | /* 73 | * Get the Spreading Factor of the module. 74 | */ 75 | String lora_getSf(void); 76 | 77 | /* 78 | * Set the Spreading Factor of the module. 79 | */ 80 | bool lora_setSf(int sf); 81 | 82 | /* 83 | * Get the Rx Timeout of the module. 84 | */ 85 | String lora_getRxtout(void); 86 | 87 | /* 88 | * Set the Rx Timeout of the module. 89 | */ 90 | bool lora_setRxtout(int rxtout); 91 | 92 | /* 93 | * Get the Tx Timeout of the module. 94 | */ 95 | String lora_getTxtout(void); 96 | 97 | /* 98 | * Set the Tx Timeout of the module. 99 | */ 100 | bool lora_setTxtout(int txtout); 101 | 102 | /* 103 | * Set the module AES mode, the module defaults to AES mode. 104 | * mode = 0: Set the module to AES Disable mode. 105 | * mode = 1: Set the module to AES Enable mode. 106 | */ 107 | bool lora_setAESMode(int mode); 108 | 109 | /* 110 | * Get the module AES Key. 111 | */ 112 | String lora_getAppKey(void); 113 | 114 | /* 115 | * Set the module AES Key. 116 | * appKEY : Application key as a HEX string. Example "a5 84 99 8d 0d bd b1 54 51 a3 40 8f 92 9d 38 f5" 117 | */ 118 | bool lora_setAppKey(String appKEY); 119 | 120 | /* 121 | * Get the module RSSI. 122 | */ 123 | String lora_getRssi(void); 124 | 125 | /* 126 | * Get the module SNR. 127 | */ 128 | String lora_getSnr(void); 129 | 130 | /* 131 | * Gets the firmware version number of the module. 132 | * Only applies to the firmware that the module programmed for the SNIPE AT command. 133 | */ 134 | String lora_getVersion(void); 135 | 136 | /* 137 | * Apply the Configuration value to the module. 138 | * Configuration value : Frequency, TX Power, Spreading Factor, RX Timeout, TX Timeout 139 | */ 140 | bool lora_setConf(void); 141 | 142 | /* 143 | * Send Text Data to the module 144 | */ 145 | bool lora_send(String Text); 146 | 147 | /* 148 | * Send Binary Data to the module 149 | */ 150 | bool lora_sendBinary(String Hex); 151 | 152 | /* 153 | * Returns the data received by the module. 154 | * 155 | */ 156 | String lora_recv(void); 157 | 158 | /* 159 | * Returns the binary data received by the module. 160 | * 161 | */ 162 | String lora_recvBinary(void); 163 | 164 | /* 165 | * Send a raw command to the SNIPE module. 166 | * Returns the raw string as received back from the SNIPE. 167 | * If the SNIPE replies with multiple line, only the first line will be returned. 168 | */ 169 | String sendRawCommand(String command); 170 | 171 | private: 172 | Stream& _serial; 173 | int _timeOut = 0; 174 | 175 | }; 176 | #endif 177 | -------------------------------------------------------------------------------- /docs/CodeZoo_LoRa_Module_ATCommands.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codezoo-ltd/SNIPE/ee5c0f6017999dcd6fe965fa99421ee55108907d/docs/CodeZoo_LoRa_Module_ATCommands.pdf -------------------------------------------------------------------------------- /docs/CodeZoo_LoRa_Module_V2_Shield_Schematic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codezoo-ltd/SNIPE/ee5c0f6017999dcd6fe965fa99421ee55108907d/docs/CodeZoo_LoRa_Module_V2_Shield_Schematic.pdf -------------------------------------------------------------------------------- /examples/DHT_Recv/DHT_Recv.ino: -------------------------------------------------------------------------------- 1 | // Example testing sketch for various DHT humidity/temperature sensors 2 | // Written by ladyada, public domain 3 | 4 | #include "DHT.h" 5 | #include 6 | #include "SNIPE.h" 7 | 8 | #define DHTPIN 2 // what pin we're connected to 9 | 10 | // Uncomment whatever type you're using! 11 | //#define DHTTYPE DHT11 // DHT 11 12 | #define DHTTYPE DHT22 // DHT 22 (AM2302) 13 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 14 | 15 | #define TXpin 11 16 | #define RXpin 10 17 | #define ATSerial Serial 18 | 19 | // Connect pin 1 (on the left) of the sensor to +5V 20 | // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 21 | // to 3.3V instead of 5V! 22 | // Connect pin 2 of the sensor to whatever your DHTPIN is 23 | // Connect pin 4 (on the right) of the sensor to GROUND 24 | // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor 25 | 26 | // Initialize DHT sensor for normal 16mhz Arduino 27 | DHT dht(DHTPIN, DHTTYPE); 28 | // NOTE: For working with a faster chip, like an Arduino Due or Teensy, you 29 | // might need to increase the threshold for cycle counts considered a 1 or 0. 30 | // You can do this by passing a 3rd parameter for this threshold. It's a bit 31 | // of fiddling to find the right value, but in general the faster the CPU the 32 | // higher the value. The default for a 16mhz AVR is a value of 6. For an 33 | // Arduino Due that runs at 84mhz a value of 30 works. 34 | // Example to initialize DHT sensor for Arduino Due: 35 | //DHT dht(DHTPIN, DHTTYPE, 30); 36 | 37 | //16byte hex key 38 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; 39 | 40 | SoftwareSerial DebugSerial(RXpin,TXpin); 41 | SNIPE SNIPE(ATSerial); 42 | 43 | void setup() { 44 | ATSerial.begin(115200); 45 | 46 | // put your setup code here, to run once: 47 | while(ATSerial.read()>= 0) {} 48 | while(!ATSerial); 49 | 50 | DebugSerial.begin(115200); 51 | 52 | /* SNIPE LoRa Initialization */ 53 | if (!SNIPE.lora_init()) { 54 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 55 | while (1); 56 | } 57 | 58 | /* SNIPE LoRa Set Appkey */ 59 | if (!SNIPE.lora_setAppKey(lora_app_key)) { 60 | DebugSerial.println("SNIPE LoRa app key value has not been changed"); 61 | } 62 | 63 | /* SNIPE LoRa Set Frequency */ 64 | if (!SNIPE.lora_setFreq(LORA_CH_1)) { 65 | DebugSerial.println("SNIPE LoRa Frequency value has not been changed"); 66 | } 67 | 68 | /* SNIPE LoRa Set Spreading Factor */ 69 | if (!SNIPE.lora_setSf(LORA_SF_7)) { 70 | DebugSerial.println("SNIPE LoRa Sf value has not been changed"); 71 | } 72 | 73 | /* SNIPE LoRa Set Rx Timeout 74 | * If you select LORA_SF_12, 75 | * RX Timout use a value greater than 5000 76 | */ 77 | /* SNIPE LoRa Set Rx Timeout */ 78 | if (!SNIPE.lora_setRxtout(5000)) { 79 | DebugSerial.println("SNIPE LoRa Rx Timout value has not been changed"); 80 | } 81 | 82 | DebugSerial.println("SNIPE LoRa DHT22 Test"); 83 | 84 | dht.begin(); 85 | } 86 | 87 | void loop() { 88 | 89 | String ver = SNIPE.lora_recv(); 90 | delay(300); 91 | 92 | DebugSerial.println(ver); 93 | 94 | if (ver == "PING" ) 95 | { 96 | DebugSerial.println("recv success"); 97 | DebugSerial.println(SNIPE.lora_getRssi()); 98 | DebugSerial.println(SNIPE.lora_getSnr()); 99 | 100 | // Reading temperature or humidity takes about 250 milliseconds! 101 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 102 | float h = dht.readHumidity(); 103 | // Read temperature as Celsius 104 | float t = dht.readTemperature(); 105 | // Read temperature as Fahrenheit 106 | float f = dht.readTemperature(true); 107 | 108 | // Check if any reads failed and exit early (to try again). 109 | if (isnan(h) || isnan(t) || isnan(f)) { 110 | DebugSerial.println("Failed to read from DHT sensor!"); 111 | return; 112 | } 113 | 114 | // Compute heat index 115 | // Must send in temp in Fahrenheit! 116 | float hi = dht.computeHeatIndex(f, h); 117 | 118 | DebugSerial.print("Humidity: "); 119 | DebugSerial.print(h); 120 | DebugSerial.print(" %\t"); 121 | DebugSerial.print("Temperature: "); 122 | DebugSerial.print(t); 123 | DebugSerial.print(" *C "); 124 | DebugSerial.print(f); 125 | DebugSerial.print(" *F\t"); 126 | DebugSerial.print("Heat index: "); 127 | DebugSerial.print(hi); 128 | DebugSerial.println(" *F"); 129 | 130 | if(SNIPE.lora_send("PONG")) 131 | { 132 | DebugSerial.println("send success"); 133 | } 134 | else 135 | { 136 | DebugSerial.println("send fail"); 137 | delay(500); 138 | } 139 | } 140 | delay(1000); 141 | } 142 | -------------------------------------------------------------------------------- /examples/DHT_Recv2/DHT_Recv2.ino: -------------------------------------------------------------------------------- 1 | // Example testing sketch for various DHT humidity/temperature sensors 2 | // Written by ladyada, public domain 3 | 4 | #include "DHT.h" 5 | #include 6 | #include "SNIPE.h" 7 | 8 | #define DHTPIN 2 // what pin we're connected to 9 | 10 | // Uncomment whatever type you're using! 11 | //#define DHTTYPE DHT11 // DHT 11 12 | #define DHTTYPE DHT22 // DHT 22 (AM2302) 13 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 14 | 15 | #define ADDR 10 //(0x00 ~ 0xFF) 16 | #define TXpin 11 17 | #define RXpin 10 18 | #define ATSerial Serial 19 | 20 | // Connect pin 1 (on the left) of the sensor to +5V 21 | // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 22 | // to 3.3V instead of 5V! 23 | // Connect pin 2 of the sensor to whatever your DHTPIN is 24 | // Connect pin 4 (on the right) of the sensor to GROUND 25 | // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor 26 | 27 | // Initialize DHT sensor for normal 16mhz Arduino 28 | DHT dht(DHTPIN, DHTTYPE); 29 | // NOTE: For working with a faster chip, like an Arduino Due or Teensy, you 30 | // might need to increase the threshold for cycle counts considered a 1 or 0. 31 | // You can do this by passing a 3rd parameter for this threshold. It's a bit 32 | // of fiddling to find the right value, but in general the faster the CPU the 33 | // higher the value. The default for a 16mhz AVR is a value of 6. For an 34 | // Arduino Due that runs at 84mhz a value of 30 works. 35 | // Example to initialize DHT sensor for Arduino Due: 36 | //DHT dht(DHTPIN, DHTTYPE, 30); 37 | 38 | //16byte hex key 39 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; 40 | 41 | SoftwareSerial DebugSerial(RXpin,TXpin); 42 | SNIPE SNIPE(ATSerial); 43 | char buffer[20]; 44 | int addr; 45 | 46 | void setup() { 47 | ATSerial.begin(115200); 48 | 49 | // put your setup code here, to run once: 50 | while(ATSerial.read()>= 0) {} 51 | while(!ATSerial); 52 | 53 | DebugSerial.begin(115200); 54 | 55 | /* SNIPE LoRa Initialization */ 56 | if (!SNIPE.lora_init()) { 57 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 58 | while (1); 59 | } 60 | 61 | /* SNIPE LoRa Set AppKey */ 62 | if (!SNIPE.lora_setAppKey(lora_app_key)) { 63 | DebugSerial.println("SNIPE LoRa app key value has not been changed"); 64 | } 65 | 66 | /* SNIPE LoRa Set Frequency */ 67 | if (!SNIPE.lora_setFreq(LORA_CH_1)) { 68 | DebugSerial.println("SNIPE LoRa Frequency value has not been changed"); 69 | } 70 | 71 | /* SNIPE LoRa Set Spreading Factor */ 72 | if (!SNIPE.lora_setSf(LORA_SF_7)) { 73 | DebugSerial.println("SNIPE LoRa Sf value has not been changed"); 74 | } 75 | 76 | /* SNIPE LoRa Set Rx Timeout 77 | * If you select LORA_SF_12, 78 | * RX Timout use a value greater than 5000 79 | */ 80 | if (!SNIPE.lora_setRxtout(5000)) { 81 | DebugSerial.println("SNIPE LoRa Rx Timout value has not been changed"); 82 | } 83 | 84 | DebugSerial.println("SNIPE LoRa DHT22 Recv"); 85 | 86 | dht.begin(); 87 | } 88 | 89 | void loop() { 90 | char temp[8]; 91 | char humi[8]; 92 | String ver = SNIPE.lora_recv(); 93 | 94 | if (ver != "AT_RX_TIMEOUT" && ver != "AT_RX_ERROR") 95 | { 96 | DebugSerial.println(ver); 97 | memset(buffer, 0x0, sizeof(buffer)); 98 | ver.toCharArray(buffer, sizeof(buffer)); 99 | sscanf(buffer, "%d", &addr); 100 | 101 | if(addr == ADDR){ 102 | String send_value; 103 | DebugSerial.println(SNIPE.lora_getRssi()); 104 | DebugSerial.println(SNIPE.lora_getSnr()); 105 | // Reading temperature or humidity takes about 250 milliseconds! 106 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 107 | float h = dht.readHumidity(); 108 | // Read temperature as Celsius 109 | float t = dht.readTemperature(); 110 | // Read temperature as Fahrenheit 111 | float f = dht.readTemperature(true); 112 | 113 | // Check if any reads failed and exit early (to try again). 114 | if (isnan(h) || isnan(t) || isnan(f)) { 115 | DebugSerial.println("Failed to read from DHT sensor!"); 116 | return; 117 | } 118 | 119 | // Compute heat index 120 | // Must send in temp in Fahrenheit! 121 | float hi = dht.computeHeatIndex(f, h); 122 | 123 | memset(buffer, 0x0, sizeof(buffer)); 124 | dtostrf(t, 5, 2, temp); 125 | dtostrf(h, 5, 2, humi); 126 | 127 | sprintf(buffer, "%d:%s:%s", addr, temp, humi); 128 | send_value = String(buffer); 129 | 130 | DebugSerial.println("-----LoRa_send_value-----"); 131 | DebugSerial.println(send_value); 132 | 133 | DebugSerial.print("Humidity: "); 134 | DebugSerial.print(h); 135 | DebugSerial.print(" %\t"); 136 | DebugSerial.print("Temperature: "); 137 | DebugSerial.print(t); 138 | DebugSerial.print(" *C "); 139 | 140 | if(SNIPE.lora_send(send_value)) 141 | { 142 | DebugSerial.println("send success"); 143 | } 144 | else 145 | { 146 | DebugSerial.println("send fail"); 147 | delay(500); 148 | } 149 | 150 | } 151 | else 152 | DebugSerial.println("It is not my address!!!"); 153 | } 154 | delay(1000); 155 | } 156 | -------------------------------------------------------------------------------- /examples/DHT_Send2/DHT_Send2.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SNIPE.h" 3 | 4 | #define ADDR 10 //(0x00 ~ 0xFF) 5 | #define TXpin 11 6 | #define RXpin 10 7 | #define ATSerial Serial 8 | 9 | //16byte hex key 10 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; 11 | 12 | SoftwareSerial DebugSerial(RXpin,TXpin); 13 | SNIPE SNIPE(ATSerial); 14 | 15 | void setup() { 16 | ATSerial.begin(115200); 17 | 18 | // put your setup code here, to run once: 19 | while(ATSerial.read()>= 0) {} 20 | while(!ATSerial); 21 | 22 | DebugSerial.begin(115200); 23 | 24 | /* SNIPE LoRa Initialization */ 25 | if (!SNIPE.lora_init()) { 26 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 27 | while (1); 28 | } 29 | 30 | /* SNIPE LoRa Set AppKey */ 31 | if (!SNIPE.lora_setAppKey(lora_app_key)) { 32 | DebugSerial.println("SNIPE LoRa app key value has not been changed"); 33 | } 34 | 35 | /* SNIPE LoRa Set Frequency */ 36 | if (!SNIPE.lora_setFreq(LORA_CH_1)) { 37 | DebugSerial.println("SNIPE LoRa Frequency value has not been changed"); 38 | } 39 | 40 | /* SNIPE LoRa Set Spreading Factor */ 41 | if (!SNIPE.lora_setSf(LORA_SF_7)) { 42 | DebugSerial.println("SNIPE LoRa Sf value has not been changed"); 43 | } 44 | 45 | /* SNIPE LoRa Set Rx Timeout 46 | * If you select LORA_SF_12, 47 | * RX Timout use a value greater than 5000 48 | */ 49 | if (!SNIPE.lora_setRxtout(5000)) { 50 | DebugSerial.println("SNIPE LoRa Rx Timout value has not been changed"); 51 | } 52 | 53 | DebugSerial.println("SNIPE LoRa PingPong Test"); 54 | } 55 | 56 | void loop() { 57 | 58 | char addr[2]; 59 | String msg; 60 | 61 | sprintf(addr, "%d", ADDR); 62 | msg = (String)addr; 63 | 64 | if (SNIPE.lora_send(msg)) 65 | { 66 | DebugSerial.println("send success"); 67 | 68 | String ver = SNIPE.lora_recv(); 69 | 70 | if (ver != "AT_RX_TIMEOUT" && ver != "AT_RX_ERROR") 71 | { 72 | DebugSerial.println(ver); 73 | DebugSerial.println(SNIPE.lora_getRssi()); 74 | DebugSerial.println(SNIPE.lora_getSnr()); 75 | } 76 | else 77 | { 78 | DebugSerial.println("recv fail"); 79 | delay(500); 80 | } 81 | } 82 | delay(1000); 83 | 84 | } 85 | -------------------------------------------------------------------------------- /examples/LoRaPingPongTest/LoRaPingPongTest.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SNIPE.h" 3 | 4 | #define PING 1 5 | #define PONG 2 6 | 7 | #define CODE PING /* Please define PING or PONG */ 8 | 9 | #define TXpin 11 10 | #define RXpin 10 11 | #define ATSerial Serial 12 | 13 | //16byte hex key 14 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; 15 | 16 | SoftwareSerial DebugSerial(RXpin,TXpin); 17 | SNIPE SNIPE(ATSerial); 18 | 19 | void setup() { 20 | ATSerial.begin(115200); 21 | 22 | // put your setup code here, to run once: 23 | while(ATSerial.read()>= 0) {} 24 | while(!ATSerial); 25 | 26 | DebugSerial.begin(115200); 27 | 28 | /* SNIPE LoRa Initialization */ 29 | if (!SNIPE.lora_init()) { 30 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 31 | while (1); 32 | } 33 | 34 | /* SNIPE LoRa Set Appkey */ 35 | if (!SNIPE.lora_setAppKey(lora_app_key)) { 36 | DebugSerial.println("SNIPE LoRa app key value has not been changed"); 37 | } 38 | 39 | /* SNIPE LoRa Set Frequency */ 40 | if (!SNIPE.lora_setFreq(LORA_CH_1)) { 41 | DebugSerial.println("SNIPE LoRa Frequency value has not been changed"); 42 | } 43 | 44 | /* SNIPE LoRa Set Spreading Factor */ 45 | if (!SNIPE.lora_setSf(LORA_SF_7)) { 46 | DebugSerial.println("SNIPE LoRa Sf value has not been changed"); 47 | } 48 | 49 | /* SNIPE LoRa Set Rx Timeout 50 | * If you select LORA_SF_12, 51 | * RX Timout use a value greater than 5000 52 | */ 53 | if (!SNIPE.lora_setRxtout(5000)) { 54 | DebugSerial.println("SNIPE LoRa Rx Timout value has not been changed"); 55 | } 56 | 57 | DebugSerial.println("SNIPE LoRa PingPong Test"); 58 | } 59 | 60 | void loop() { 61 | 62 | #if CODE == PING 63 | if (SNIPE.lora_send("PING")) 64 | { 65 | DebugSerial.println("send success"); 66 | 67 | String ver = SNIPE.lora_recv(); 68 | DebugSerial.println(ver); 69 | 70 | if (ver == "PONG") 71 | { 72 | DebugSerial.println("recv success"); 73 | DebugSerial.println(SNIPE.lora_getRssi()); 74 | DebugSerial.println(SNIPE.lora_getSnr()); 75 | } 76 | else 77 | { 78 | DebugSerial.println("recv fail"); 79 | delay(500); 80 | } 81 | } 82 | delay(1000); 83 | 84 | #elif CODE == PONG 85 | String ver = SNIPE.lora_recv(); 86 | delay(300); 87 | 88 | DebugSerial.println(ver); 89 | 90 | if (ver == "PING" ) 91 | { 92 | DebugSerial.println("recv success"); 93 | DebugSerial.println(SNIPE.lora_getRssi()); 94 | DebugSerial.println(SNIPE.lora_getSnr()); 95 | 96 | if(SNIPE.lora_send("PONG")) 97 | { 98 | DebugSerial.println("send success"); 99 | } 100 | else 101 | { 102 | DebugSerial.println("send fail"); 103 | delay(500); 104 | } 105 | } 106 | delay(1000); 107 | #endif 108 | } 109 | -------------------------------------------------------------------------------- /examples/LoRaPropertySetGet/LoRaPropertySetGet.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SNIPE.h" 3 | #define TXpin 11 4 | #define RXpin 10 5 | #define ATSerial Serial 6 | 7 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; //16byte hex key 8 | 9 | SoftwareSerial DebugSerial(RXpin,TXpin); 10 | SNIPE SNIPE(ATSerial); 11 | 12 | void setup() { 13 | ATSerial.begin(115200); 14 | 15 | // put your setup code here, to run once: 16 | while(ATSerial.read()>= 0) {} 17 | while(!ATSerial); 18 | 19 | DebugSerial.begin(115200); 20 | 21 | if (!SNIPE.lora_init()) { 22 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 23 | while (1); 24 | } 25 | 26 | DebugSerial.println("SNIPE LoRa StartUP"); 27 | } 28 | 29 | void loop() { 30 | DebugSerial.println("--- SNIPE LoRaPropertySetGet loop ---"); 31 | 32 | DebugSerial.println(SNIPE.lora_getFreq()); 33 | delay(500); 34 | 35 | DebugSerial.println(SNIPE.lora_setFreq(LORA_CH_2)==true?"TRUE":"FALSE"); 36 | delay(500); 37 | 38 | DebugSerial.println(SNIPE.lora_getTxp()); 39 | delay(500); 40 | 41 | DebugSerial.println(SNIPE.lora_setTxp(5)==true?"TRUE":"FALSE"); //Tx Power (dBm) 42 | delay(500); 43 | 44 | DebugSerial.println(SNIPE.lora_getSf()); 45 | delay(500); 46 | 47 | DebugSerial.println(SNIPE.lora_setSf(LORA_SF_12)==true?"TRUE":"FALSE"); 48 | delay(500); 49 | 50 | DebugSerial.println(SNIPE.lora_getRxtout()); 51 | delay(500); 52 | 53 | DebugSerial.println(SNIPE.lora_setRxtout(1000)==true?"TRUE":"FALSE"); 54 | delay(500); 55 | 56 | DebugSerial.println(SNIPE.lora_getTxtout()); 57 | delay(500); 58 | 59 | DebugSerial.println(SNIPE.lora_setTxtout(1000)==true?"TRUE":"FALSE"); 60 | delay(500); 61 | 62 | DebugSerial.println(SNIPE.lora_setAESMode(LORA_AES_OFF)==true?"TRUE":"FALSE"); 63 | delay(500); 64 | 65 | DebugSerial.println(SNIPE.lora_getAppKey()); 66 | delay(500); 67 | 68 | DebugSerial.println(SNIPE.lora_setAppKey(lora_app_key)==true?"TRUE":"FALSE"); 69 | delay(500); 70 | 71 | DebugSerial.println(SNIPE.lora_getVersion()); 72 | delay(500); 73 | } 74 | -------------------------------------------------------------------------------- /examples/LoRa_GPS_Send/LoRa_GPS_Send.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 0. https://github.com/mikalhart/TinyGPS 3 | 1. Please Click Clone or download button 4 | 2. Download ZIP 5 | 3. Install "TinyGPS-master.zip" into the the Arduino IDE 6 | 4. https://www.geoplaner.com/ Please Check the latitude and longitude values from Arduino. 7 | */ 8 | #include 9 | #include 10 | #include "SNIPE.h" 11 | #define TXpin 12 12 | #define RXpin 11 13 | #define GPS_TX 9 14 | #define GPS_RX 8 15 | 16 | #define ATSerial Serial 17 | 18 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; //16byte hex key 19 | 20 | SoftwareSerial DebugSerial(RXpin, TXpin); 21 | SNIPE SNIPE(ATSerial); 22 | TinyGPS gps; 23 | SoftwareSerial ss(GPS_RX, GPS_TX); 24 | 25 | void setup() { 26 | ATSerial.begin(115200); 27 | 28 | // put your setup code here, to run once: 29 | while (ATSerial.read() >= 0) {} 30 | while (!ATSerial); 31 | 32 | DebugSerial.begin(115200); 33 | ss.begin(9600); 34 | 35 | if (!SNIPE.lora_init()) { 36 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 37 | while (1); 38 | } 39 | 40 | } 41 | 42 | void loop() 43 | { 44 | bool newData = false; 45 | unsigned long chars; 46 | unsigned short sentences, failed; 47 | 48 | // For one second we parse GPS data and report some key values 49 | for (unsigned long start = millis(); millis() - start < 1000;) 50 | { 51 | while (ss.available()) 52 | { 53 | char c = ss.read(); 54 | // Serial.write(c); // uncomment this line if you want to see the GPS data flowing 55 | if (gps.encode(c)) // Did a new valid sentence come in? 56 | newData = true; 57 | } 58 | } 59 | 60 | if (newData) 61 | { 62 | float flat, flon; 63 | unsigned long age; 64 | char gps_buf[32]; 65 | char gps_lat[12]; 66 | char gps_lon[12]; 67 | String gps_value; 68 | memset(gps_buf, 0x0, sizeof(gps_buf)); 69 | 70 | gps.f_get_position(&flat, &flon, &age); 71 | DebugSerial.print("LAT="); 72 | DebugSerial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6); 73 | DebugSerial.print(" LON="); 74 | DebugSerial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6); 75 | DebugSerial.print(" SAT="); 76 | DebugSerial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites()); 77 | DebugSerial.print(" PREC="); 78 | DebugSerial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop()); 79 | 80 | if (flat != TinyGPS::GPS_INVALID_F_ANGLE && 81 | flon != TinyGPS::GPS_INVALID_F_ANGLE){ 82 | dtostrf(flat, 9, 6, gps_lat); 83 | dtostrf(flon, 10, 6, gps_lon); 84 | sprintf(gps_buf, "%s:%s", gps_lat, gps_lon); 85 | gps_value = (String)gps_buf; 86 | 87 | DebugSerial.println("-----gps_send_value-----"); 88 | DebugSerial.println(gps_value); 89 | 90 | //LoRa Send : GPS value 91 | if (SNIPE.lora_send(gps_value)) 92 | { 93 | DebugSerial.println("send success"); 94 | } 95 | else 96 | { 97 | DebugSerial.println("send fail"); 98 | delay(500); 99 | } 100 | } 101 | } 102 | 103 | gps.stats(&chars, &sentences, &failed); 104 | DebugSerial.print(" CHARS="); 105 | DebugSerial.print(chars); 106 | DebugSerial.print(" SENTENCES="); 107 | DebugSerial.print(sentences); 108 | DebugSerial.print(" CSUM ERR="); 109 | DebugSerial.println(failed); 110 | if (chars == 0) 111 | DebugSerial.println("** No characters received from GPS: check wiring **"); 112 | } 113 | -------------------------------------------------------------------------------- /examples/LoRa_LED_Recv/LoRa_LED_Recv.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SNIPE.h" 3 | 4 | #define TXpin 11 5 | #define RXpin 10 6 | #define ATSerial Serial 7 | 8 | SoftwareSerial DebugSerial(RXpin,TXpin); 9 | SNIPE SNIPE(ATSerial); 10 | 11 | //16byte hex key 12 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; 13 | 14 | void setup() { 15 | ATSerial.begin(115200); 16 | 17 | // put your setup code here, to run once: 18 | while(ATSerial.read()>= 0) {} 19 | while(!ATSerial); 20 | 21 | DebugSerial.begin(115200); 22 | 23 | /* SNIPE LoRa Initialization */ 24 | if (!SNIPE.lora_init()) { 25 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 26 | while (1); 27 | } 28 | 29 | /* SNIPE LoRa Set App Key */ 30 | if (!SNIPE.lora_setAppKey(lora_app_key)) { 31 | DebugSerial.println("SNIPE LoRa app key value has not been changed"); 32 | } 33 | 34 | /* SNIPE LoRa Set Frequency */ 35 | if (!SNIPE.lora_setFreq(LORA_CH_1)) { 36 | DebugSerial.println("SNIPE LoRa Frequency value has not been changed"); 37 | } 38 | 39 | /* SNIPE LoRa Set Spreading Factor */ 40 | if (!SNIPE.lora_setSf(LORA_SF_7)) { 41 | DebugSerial.println("SNIPE LoRa Sf value has not been changed"); 42 | } 43 | 44 | /* SNIPE LoRa Set Rx Timeout 45 | * If you select LORA_SF_12, 46 | * RX Timout use a value greater than 5000 47 | */ 48 | if (!SNIPE.lora_setRxtout(5000)) { 49 | DebugSerial.println("SNIPE LoRa Rx Timout value has not been changed"); 50 | } 51 | 52 | DebugSerial.println("SNIPE LoRa LED Recv"); 53 | 54 | // initialize digital pin LED_BUILTIN as an output. 55 | pinMode(LED_BUILTIN, OUTPUT); 56 | } 57 | 58 | void loop() { 59 | String ver = SNIPE.lora_recv(); 60 | 61 | if (ver == "123" ) 62 | { 63 | digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) 64 | DebugSerial.println("SNIPE LoRa LED on"); 65 | DebugSerial.println(SNIPE.lora_getRssi()); 66 | DebugSerial.println(SNIPE.lora_getSnr()); 67 | SNIPE.lora_send("Ack"); 68 | } 69 | else if (ver == "456") 70 | { 71 | digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW 72 | DebugSerial.println("SNIPE LoRa LED off"); 73 | DebugSerial.println(SNIPE.lora_getRssi()); 74 | DebugSerial.println(SNIPE.lora_getSnr()); 75 | SNIPE.lora_send("Ack"); 76 | } 77 | else 78 | { 79 | DebugSerial.println("recv Error!!!"); 80 | delay(1000); 81 | } 82 | delay(1000); 83 | } 84 | -------------------------------------------------------------------------------- /examples/LoRa_LED_Send/LoRa_LED_Send.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SNIPE.h" 3 | 4 | #define TXpin 11 5 | #define RXpin 10 6 | #define ATSerial Serial 7 | 8 | SoftwareSerial DebugSerial(RXpin,TXpin); 9 | SNIPE SNIPE(ATSerial); 10 | 11 | //16byte hex key 12 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; 13 | 14 | int status = 0; 15 | 16 | void setup() { 17 | ATSerial.begin(115200); 18 | 19 | // put your setup code here, to run once: 20 | while(ATSerial.read()>= 0) {} 21 | while(!ATSerial); 22 | 23 | DebugSerial.begin(115200); 24 | 25 | /* SNIPE LoRa Initialization */ 26 | if (!SNIPE.lora_init()) { 27 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 28 | while (1); 29 | } 30 | 31 | /* SNIPE LoRa Set App Key */ 32 | if (!SNIPE.lora_setAppKey(lora_app_key)) { 33 | DebugSerial.println("SNIPE LoRa app key value has not been changed"); 34 | } 35 | 36 | /* SNIPE LoRa Set Frequency */ 37 | if (!SNIPE.lora_setFreq(LORA_CH_1)) { 38 | DebugSerial.println("SNIPE LoRa Frequency value has not been changed"); 39 | } 40 | 41 | /* SNIPE LoRa Set Spreading Factor */ 42 | if (!SNIPE.lora_setSf(LORA_SF_7)) { 43 | DebugSerial.println("SNIPE LoRa Sf value has not been changed"); 44 | } 45 | 46 | /* SNIPE LoRa Set Rx Timeout 47 | * If you select LORA_SF_12, 48 | * RX Timout use a value greater than 5000 49 | */ 50 | if (!SNIPE.lora_setRxtout(5000)) { 51 | DebugSerial.println("SNIPE LoRa Rx Timout value has not been changed"); 52 | } 53 | 54 | DebugSerial.println("SNIPE LoRa LED Send"); 55 | } 56 | 57 | void loop() { 58 | String ver; 59 | 60 | /* status == 0 : led Off 61 | * status !=0 : led On 62 | */ 63 | if (!status){ 64 | //Send Command : Led On 65 | if (SNIPE.lora_send("123")) 66 | { 67 | DebugSerial.println("send command [123] success"); 68 | ver = SNIPE.lora_recv(); 69 | if(ver == "Ack") 70 | status = !status; 71 | } 72 | else 73 | { 74 | DebugSerial.println("send fail"); 75 | delay(500); 76 | } 77 | }else{ 78 | //Send Command : Led Off 79 | if (SNIPE.lora_send("456")) 80 | { 81 | DebugSerial.println("send command [456] success"); 82 | ver = SNIPE.lora_recv(); 83 | if(ver == "Ack") 84 | status = !status; 85 | } 86 | else 87 | { 88 | DebugSerial.println("send fail"); 89 | delay(500); 90 | } 91 | } 92 | delay(1000); 93 | 94 | } 95 | -------------------------------------------------------------------------------- /examples/LoRa_RGB_Recv/LoRa_RGB_Recv.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SNIPE.h" 3 | #define TXpin 9 4 | #define RXpin 8 5 | #define ATSerial Serial 6 | 7 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; //16byte hex key 8 | 9 | SoftwareSerial DebugSerial(RXpin,TXpin); 10 | SNIPE SNIPE(ATSerial); 11 | 12 | int red_Input; 13 | int green_Input; 14 | int blue_Input; 15 | char buffer[16]; 16 | 17 | void setup() { 18 | ATSerial.begin(115200); 19 | 20 | // put your setup code here, to run once: 21 | while(ATSerial.read()>= 0) {} 22 | while(!ATSerial); 23 | 24 | DebugSerial.begin(115200); 25 | 26 | if (!SNIPE.lora_init()) { 27 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 28 | while (1); 29 | } 30 | 31 | pinMode(13, OUTPUT); //Green 32 | pinMode(12, OUTPUT); //Red 33 | pinMode(11, OUTPUT); //Blue 34 | DebugSerial.println("SNIPE LoRa StartUP"); 35 | } 36 | 37 | void loop() { 38 | String ver = SNIPE.lora_recv(); 39 | 40 | if (ver != "AT_RX_TIMEOUT" && ver != "AT_RX_ERROR") 41 | { 42 | DebugSerial.println(ver); 43 | memset(buffer, 0x0, sizeof(buffer)); 44 | ver.toCharArray(buffer, sizeof(buffer)); 45 | sscanf(buffer, "%d:%d:%d", &red_Input,&green_Input,&blue_Input); 46 | analogWrite(12, red_Input); 47 | analogWrite(13, green_Input); 48 | analogWrite(11, blue_Input); 49 | 50 | DebugSerial.println(SNIPE.lora_getRssi()); 51 | DebugSerial.println(SNIPE.lora_getSnr()); 52 | } 53 | else 54 | { 55 | DebugSerial.println(ver); 56 | } 57 | delay(500); 58 | } 59 | -------------------------------------------------------------------------------- /examples/LoRa_RGB_Recv/LoRa_RGB_Recv.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codezoo-ltd/SNIPE/ee5c0f6017999dcd6fe965fa99421ee55108907d/examples/LoRa_RGB_Recv/LoRa_RGB_Recv.jpeg -------------------------------------------------------------------------------- /examples/LoRa_RGB_Send/LoRa_RGB_Send.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SNIPE.h" 3 | #define TXpin 11 4 | #define RXpin 10 5 | #define ATSerial Serial 6 | 7 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; //16byte hex key 8 | 9 | SoftwareSerial DebugSerial(RXpin,TXpin); 10 | SNIPE SNIPE(ATSerial); 11 | 12 | int red_Input; 13 | int green_Input; 14 | int blue_Input; 15 | 16 | void setup() { 17 | ATSerial.begin(115200); 18 | 19 | // put your setup code here, to run once: 20 | while(ATSerial.read()>= 0) {} 21 | while(!ATSerial); 22 | 23 | DebugSerial.begin(115200); 24 | 25 | if (!SNIPE.lora_init()) { 26 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 27 | while (1); 28 | } 29 | 30 | DebugSerial.println("SNIPE LoRa StartUP"); 31 | } 32 | 33 | void loop() { 34 | red_Input = analogRead(A0); 35 | green_Input = analogRead(A1); 36 | blue_Input = analogRead(A2); 37 | 38 | red_Input = red_Input/4; // 가변저항의 입력값(0-1023사이의 값)을 RGB값(0-255)의 값으로 보정 39 | green_Input = green_Input/4; // 가변저항의 입력값(0-1023사이의 값)을 RGB값(0-255)의 값으로 보정 40 | blue_Input = blue_Input/4; // 가변저항의 입력값(0-1023사이의 값)을 RGB값(0-255)의 값으로 보정 41 | 42 | //String rgb_value = "RGB Red:" + (String)red_Input + " Green:" + (String)green_Input + " Blue:" + (String)blue_Input; 43 | String rgb_value = (String)red_Input + ":" + (String)green_Input + ":" + (String)blue_Input; 44 | DebugSerial.println(rgb_value); 45 | 46 | //LoRa Send : HelloWorld 47 | if (SNIPE.lora_send(rgb_value)) 48 | { 49 | DebugSerial.println("send success"); 50 | } 51 | else 52 | { 53 | DebugSerial.println("send fail"); 54 | delay(500); 55 | } 56 | delay(500); 57 | } 58 | -------------------------------------------------------------------------------- /examples/LoRa_RGB_Send/RGB_Send_Device.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codezoo-ltd/SNIPE/ee5c0f6017999dcd6fe965fa99421ee55108907d/examples/LoRa_RGB_Send/RGB_Send_Device.jpeg -------------------------------------------------------------------------------- /examples/WiFiClient_lora/WiFiClient_lora.ino: -------------------------------------------------------------------------------- 1 | /* 2 | This sketch sends data via HTTP GET requests to data.sparkfun.com service. 3 | 4 | You need to get streamId and privateKey at data.sparkfun.com and paste them 5 | below. Or just customize this script to talk to other HTTP servers. 6 | 7 | */ 8 | #include 9 | #include 10 | #include "SNIPE.h" 11 | 12 | #define ATSerial Serial 13 | 14 | //16byte hex key 15 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; 16 | 17 | const char* ssid = "iptime_good(2.4G)"; 18 | const char* password = ""; 19 | 20 | IPAddress server(192,168,0,155); 21 | const int httpPort = 51292; 22 | 23 | #define TXpin D9 24 | #define RXpin D8 25 | 26 | SoftwareSerial DebugSerial(RXpin,TXpin); 27 | SNIPE SNIPE(ATSerial); 28 | 29 | // Use WiFiClient class to create TCP connections 30 | WiFiClient client; 31 | 32 | void setup() { 33 | ATSerial.begin(115200); 34 | // put your setup code here, to run once: 35 | while(ATSerial.read()>= 0) {} 36 | while(!ATSerial); 37 | 38 | DebugSerial.begin(115200); 39 | 40 | if (!SNIPE.lora_init()) { 41 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 42 | while (1); 43 | } 44 | 45 | /* SNIPE LoRa Set AppKey */ 46 | if (!SNIPE.lora_setAppKey(lora_app_key)) { 47 | DebugSerial.println("SNIPE LoRa app key value has not been changed"); 48 | } 49 | 50 | /* SNIPE LoRa Set Frequency */ 51 | if (!SNIPE.lora_setFreq(LORA_CH_2)) { 52 | DebugSerial.println("SNIPE LoRa Frequency value has not been changed"); 53 | } 54 | 55 | /* SNIPE LoRa Set Spreading Factor */ 56 | if (!SNIPE.lora_setSf(LORA_SF_7)) { 57 | DebugSerial.println("SNIPE LoRa Sf value has not been changed"); 58 | } 59 | 60 | /* SNIPE LoRa Set Rx Timeout 61 | * If you select LORA_SF_12, 62 | * RX Timout use a value greater than 5000 63 | */ 64 | /* SNIPE LoRa Set Rx Timeout */ 65 | if (!SNIPE.lora_setRxtout(3000)) { 66 | DebugSerial.println("SNIPE LoRa Rx Timout value has not been changed"); 67 | } 68 | 69 | DebugSerial.println("Simple LoRa Gateway StartUP"); 70 | 71 | // We start by connecting to a WiFi network 72 | 73 | DebugSerial.println(); 74 | DebugSerial.println(); 75 | DebugSerial.print("Connecting to "); 76 | DebugSerial.println(ssid); 77 | 78 | /* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default, 79 | would try to act as both a client and an access-point and could cause 80 | network-issues with your other WiFi-devices on your WiFi-network. */ 81 | WiFi.mode(WIFI_STA); 82 | WiFi.begin(ssid, password); 83 | 84 | while (WiFi.status() != WL_CONNECTED) { 85 | delay(500); 86 | DebugSerial.print("."); 87 | } 88 | 89 | DebugSerial.println(""); 90 | DebugSerial.println("WiFi connected"); 91 | DebugSerial.println("IP address: "); 92 | DebugSerial.println(WiFi.localIP()); 93 | 94 | if (!client.connect(server, httpPort)) { 95 | DebugSerial.println("connection failed"); 96 | return; 97 | } 98 | 99 | DebugSerial.print("connecting to Server"); 100 | } 101 | 102 | int addr_loop = 1; 103 | int retry_cnt = 0; 104 | #define MAX_USER 12 105 | 106 | void loop() { 107 | 108 | char addr[2]; 109 | String msg; 110 | 111 | /* If communication is not successful, 112 | * retry 5 times 113 | */ 114 | retry_cnt = 5; 115 | 116 | /* 15 configured nodes */ 117 | if(addr_loop > MAX_USER) 118 | addr_loop = 1; 119 | 120 | sprintf( addr, "%d", addr_loop ); 121 | 122 | DebugSerial.println("send [Addr]: "); 123 | DebugSerial.print(addr_loop); 124 | DebugSerial.println("----------//"); 125 | 126 | addr_loop++; 127 | 128 | msg = (String)addr; 129 | 130 | while(retry_cnt--) 131 | { 132 | if (SNIPE.lora_send(msg)) 133 | { 134 | DebugSerial.println("send success"); 135 | String ver = SNIPE.lora_recv(); 136 | 137 | if (ver != "AT_RX_TIMEOUT" && ver != "AT_RX_ERROR") 138 | { 139 | String rssi; 140 | String snr; 141 | 142 | rssi = SNIPE.lora_getRssi(); 143 | snr = SNIPE.lora_getSnr(); 144 | client.print(ver); 145 | client.print(rssi); 146 | client.print(snr); 147 | 148 | DebugSerial.println(ver); 149 | DebugSerial.println(rssi); 150 | DebugSerial.println(snr); 151 | 152 | break; 153 | } 154 | else 155 | { 156 | DebugSerial.println("recv fail"); 157 | delay(100); 158 | } 159 | } 160 | } 161 | delay(100); 162 | } 163 | -------------------------------------------------------------------------------- /examples/class_Recv/class_Recv.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "SNIPE.h" 5 | 6 | #define TXpin 9 7 | #define RXpin 8 8 | #define ATSerial Serial 9 | 10 | char classCallValue[5]; /* 0:class1, 1:class2, 2:class3, 3:class4, 4:class5 */ 11 | 12 | //16byte hex key 13 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; 14 | 15 | // Set the LCD address to 0x27 for a 16 chars and 2 line display 16 | LiquidCrystal_I2C lcd(0x27, 16, 2); 17 | SoftwareSerial DebugSerial(RXpin, TXpin); 18 | SNIPE SNIPE(ATSerial); 19 | char buffer[8]; 20 | int addr; 21 | int callStatus; 22 | 23 | void setup() { 24 | ATSerial.begin(115200); 25 | 26 | // put your setup code here, to run once: 27 | while (ATSerial.read() >= 0) {} 28 | while (!ATSerial); 29 | 30 | DebugSerial.begin(115200); 31 | 32 | // classCallValue initialization (all Zero) 33 | for (int i = 0; i < 5; i++) { 34 | classCallValue[i] = '0'; 35 | } 36 | 37 | // initialize the LCD 38 | lcd.begin(); 39 | 40 | // Turn on the blacklight and print a message. 41 | lcd.backlight(); 42 | lcd.setCursor(0, 0); 43 | lcd.print("1:"); 44 | lcd.setCursor(2, 0); 45 | lcd.write(classCallValue[0]); 46 | 47 | lcd.setCursor(4, 0); 48 | lcd.print("2:"); 49 | lcd.setCursor(6, 0); 50 | lcd.write(classCallValue[1]); 51 | 52 | lcd.setCursor(8, 0); 53 | lcd.print("3:"); 54 | lcd.setCursor(10, 0); 55 | lcd.write(classCallValue[2]); 56 | 57 | lcd.setCursor(0, 1); 58 | lcd.print("4:"); 59 | lcd.setCursor(2, 1); 60 | lcd.write(classCallValue[3]); 61 | 62 | lcd.setCursor(4, 1); 63 | lcd.print("5:"); 64 | lcd.setCursor(6, 1); 65 | lcd.write(classCallValue[4]); 66 | 67 | /* SNIPE LoRa Initialization */ 68 | if (!SNIPE.lora_init()) { 69 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 70 | while (1); 71 | } 72 | 73 | /* SNIPE LoRa Set AppKey */ 74 | if (!SNIPE.lora_setAppKey(lora_app_key)) { 75 | DebugSerial.println("SNIPE LoRa app key value has not been changed"); 76 | } 77 | 78 | /* SNIPE LoRa Set Frequency */ 79 | if (!SNIPE.lora_setFreq(LORA_CH_1)) { 80 | DebugSerial.println("SNIPE LoRa Frequency value has not been changed"); 81 | } 82 | 83 | /* SNIPE LoRa Set Spreading Factor */ 84 | if (!SNIPE.lora_setSf(LORA_SF_7)) { 85 | DebugSerial.println("SNIPE LoRa Sf value has not been changed"); 86 | } 87 | 88 | /* SNIPE LoRa Set Rx Timeout 89 | If you select LORA_SF_12, 90 | RX Timout use a value greater than 5000 91 | */ 92 | if (!SNIPE.lora_setRxtout(5000)) { 93 | DebugSerial.println("SNIPE LoRa Rx Timout value has not been changed"); 94 | } 95 | 96 | DebugSerial.println("Class Recv"); 97 | 98 | } 99 | 100 | void loop() { 101 | String ver = SNIPE.lora_recv(); 102 | 103 | if (ver != "AT_RX_TIMEOUT" && ver != "AT_RX_ERROR") 104 | { 105 | DebugSerial.println(SNIPE.lora_getRssi()); 106 | DebugSerial.println(SNIPE.lora_getSnr()); 107 | 108 | DebugSerial.println(ver); 109 | memset(buffer, 0x0, sizeof(buffer)); 110 | ver.toCharArray(buffer, sizeof(buffer)); 111 | sscanf(buffer, "%d:%d", &addr, &callStatus); 112 | 113 | /* value check */ 114 | if ( addr > 0 && addr < 6 && callStatus > 0 && callStatus < 3 ) { 115 | /* addr = 1~5 */ 116 | if(callStatus == 1){ 117 | classCallValue[addr-1] = '1'; 118 | }else if(callStatus == 2){ 119 | classCallValue[addr-1] = '0'; 120 | } 121 | 122 | lcd.clear(); 123 | 124 | lcd.backlight(); 125 | lcd.setCursor(0, 0); 126 | lcd.print("1:"); 127 | lcd.setCursor(2, 0); 128 | lcd.write(classCallValue[0]); 129 | 130 | lcd.setCursor(4, 0); 131 | lcd.print("2:"); 132 | lcd.setCursor(6, 0); 133 | lcd.write(classCallValue[1]); 134 | 135 | lcd.setCursor(8, 0); 136 | lcd.print("3:"); 137 | lcd.setCursor(10, 0); 138 | lcd.write(classCallValue[2]); 139 | 140 | lcd.setCursor(0, 1); 141 | lcd.print("4:"); 142 | lcd.setCursor(2, 1); 143 | lcd.write(classCallValue[3]); 144 | 145 | lcd.setCursor(4, 1); 146 | lcd.print("5:"); 147 | lcd.setCursor(6, 1); 148 | lcd.write(classCallValue[4]); 149 | 150 | 151 | String send_value; 152 | memset(buffer, 0x0, sizeof(buffer)); 153 | 154 | sprintf(buffer, "%d:%d", addr, callStatus); 155 | send_value = String(buffer); 156 | 157 | DebugSerial.println("-----LoRa_send_value-----"); 158 | DebugSerial.println(send_value); 159 | 160 | if (SNIPE.lora_send(send_value)) 161 | { 162 | DebugSerial.println("send success"); 163 | } 164 | else 165 | { 166 | DebugSerial.println("send fail"); 167 | delay(500); 168 | } 169 | } 170 | 171 | } else 172 | DebugSerial.println("Recv Ready..."); 173 | } 174 | -------------------------------------------------------------------------------- /examples/class_Send/class_Send.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SNIPE.h" 3 | 4 | #define BUTTON_CALL 2 5 | #define BUTTON_CLEAR 3 6 | #define USER_LED A5 7 | #define WAITING_TIME 3000 /* 3 Seconds */ 8 | 9 | int btn1 = 0; 10 | unsigned long button_time1 = 0; 11 | unsigned long last_button_time1 = 0; 12 | 13 | int btn2 = 0; 14 | unsigned long button_time2 = 0; 15 | unsigned long last_button_time2 = 0; 16 | 17 | int callStatus = 0; /* 0: default, 1: CALL, 2: CLEAR */ 18 | char recvBuffer[8]; 19 | int address; 20 | int chkCallStatus; 21 | 22 | //Pressed for more than 300ms 23 | void SW01_ISR(){ 24 | button_time1 = millis(); 25 | if (button_time1 - last_button_time1 > 300) 26 | { 27 | btn1 = 1; 28 | last_button_time1 = button_time1; 29 | } 30 | } 31 | 32 | void SW02_ISR(){ 33 | button_time2 = millis(); 34 | if (button_time2 - last_button_time2 > 300) 35 | { 36 | btn2 = 1; 37 | last_button_time2 = button_time2; 38 | } 39 | } 40 | #define ADDR 1 //(0x00 ~ 0xFF) 41 | #define TXpin 11 42 | #define RXpin 10 43 | #define ATSerial Serial 44 | 45 | //16byte hex key 46 | String lora_app_key = "11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00"; 47 | 48 | SoftwareSerial DebugSerial(RXpin,TXpin); 49 | SNIPE SNIPE(ATSerial); 50 | 51 | void setup() { 52 | ATSerial.begin(115200); 53 | 54 | while(ATSerial.read()>= 0) {} 55 | while(!ATSerial); 56 | 57 | DebugSerial.begin(115200); 58 | 59 | pinMode(USER_LED, OUTPUT); 60 | pinMode(BUTTON_CALL, INPUT_PULLUP); 61 | pinMode(BUTTON_CLEAR, INPUT_PULLUP); 62 | 63 | /* SNIPE LoRa Initialization */ 64 | if (!SNIPE.lora_init()) { 65 | DebugSerial.println("SNIPE LoRa Initialization Fail!"); 66 | while (1); 67 | } 68 | 69 | /* SNIPE LoRa Set AppKey */ 70 | if (!SNIPE.lora_setAppKey(lora_app_key)) { 71 | DebugSerial.println("SNIPE LoRa app key value has not been changed"); 72 | } 73 | 74 | /* SNIPE LoRa Set Frequency */ 75 | if (!SNIPE.lora_setFreq(LORA_CH_1)) { 76 | DebugSerial.println("SNIPE LoRa Frequency value has not been changed"); 77 | } 78 | 79 | /* SNIPE LoRa Set Spreading Factor */ 80 | if (!SNIPE.lora_setSf(LORA_SF_7)) { 81 | DebugSerial.println("SNIPE LoRa Sf value has not been changed"); 82 | } 83 | 84 | /* SNIPE LoRa Set Rx Timeout 85 | * If you select LORA_SF_12, 86 | * RX Timout use a value greater than 5000 87 | */ 88 | if (!SNIPE.lora_setRxtout(5000)) { 89 | DebugSerial.println("SNIPE LoRa Rx Timout value has not been changed"); 90 | } 91 | 92 | attachInterrupt(digitalPinToInterrupt(BUTTON_CALL), SW01_ISR, FALLING); 93 | attachInterrupt(digitalPinToInterrupt(BUTTON_CLEAR), SW02_ISR, FALLING); 94 | 95 | DebugSerial.println("Class Send Test"); 96 | } 97 | 98 | void loop() { 99 | 100 | // put your main code here, to run repeatedly: 101 | if(btn1 == 1) //SW1 interrupt 102 | { 103 | btn1 = 0; 104 | callStatus = 1; //1: CALL 105 | digitalWrite(USER_LED, HIGH); 106 | } 107 | 108 | if(btn2 == 1) //SW2 interrupt 109 | { 110 | btn2 = 0; 111 | callStatus = 2; //2: CLEAR 112 | digitalWrite(USER_LED, HIGH); 113 | } 114 | 115 | if(callStatus){ 116 | char addr[8]; 117 | String msg; 118 | 119 | sprintf(addr, "%d:%d", ADDR, callStatus); 120 | msg = (String)addr; 121 | DebugSerial.println("[Send Message]"); 122 | DebugSerial.println(msg); 123 | 124 | if (SNIPE.lora_send(msg)) 125 | { 126 | DebugSerial.println("send success"); 127 | 128 | String ver = SNIPE.lora_recv(); 129 | 130 | if (ver != "AT_RX_TIMEOUT" && ver != "AT_RX_ERROR") 131 | { 132 | /* Receive Status */ 133 | DebugSerial.println(SNIPE.lora_getRssi()); 134 | DebugSerial.println(SNIPE.lora_getSnr()); 135 | DebugSerial.println(ver); 136 | 137 | /* if (addr == ADDR) */ 138 | memset(recvBuffer, 0x0, sizeof(recvBuffer)); 139 | ver.toCharArray(recvBuffer, sizeof(recvBuffer)); 140 | sscanf(recvBuffer, "%d:%d", &address, &chkCallStatus); 141 | 142 | if(address == ADDR && chkCallStatus == callStatus){ 143 | callStatus = 0; /* 0: default */ 144 | digitalWrite(USER_LED, LOW); 145 | } 146 | } 147 | else 148 | { 149 | DebugSerial.println("recv fail"); 150 | } 151 | } 152 | delay(WAITING_TIME); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For SNIPE 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SNIPE KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | lora_init KEYWORD2 15 | lora_reset KEYWORD2 16 | lora_getFreq KEYWORD2 17 | lora_setFreq KEYWORD2 18 | lora_getTxp KEYWORD2 19 | lora_setTxp KEYWORD2 20 | lora_getSf KEYWORD2 21 | lora_setSf KEYWORD2 22 | lora_getRxtout KEYWORD2 23 | lora_setRxtout KEYWORD2 24 | lora_getTxtout KEYWORD2 25 | lora_setTxtout KEYWORD2 26 | lora_setAESMode KEYWORD2 27 | lora_getAppKey KEYWORD2 28 | lora_setAppKey KEYWORD2 29 | lora_getRssi KEYWORD2 30 | lora_getSnr KEYWORD2 31 | lora_getVersion KEYWORD2 32 | lora_setConf KEYWORD2 33 | lora_send KEYWORD2 34 | lora_sendBinary KEYWORD2 35 | lora_recv KEYWORD2 36 | lora_recvBinary KEYWORD2 37 | sendRawCommand KEYWORD2 38 | 39 | ####################################### 40 | # Instances (KEYWORD2) 41 | ####################################### 42 | 43 | ####################################### 44 | # Constants (LITERAL1) 45 | ####################################### 46 | LORA_CH_1 LITERAL1 47 | LORA_CH_2 LITERAL1 48 | LORA_CH_3 LITERAL1 49 | LORA_CH_4 LITERAL1 50 | LORA_CH_5 LITERAL1 51 | LORA_CH_6 LITERAL1 52 | LORA_CH_7 LITERAL1 53 | LORA_CH_8 LITERAL1 54 | LORA_SF_7 LITERAL1 55 | LORA_SF_8 LITERAL1 56 | LORA_SF_9 LITERAL1 57 | LORA_SF_10 LITERAL1 58 | LORA_SF_11 LITERAL1 59 | LORA_SF_12 LITERAL1 60 | LORA_AES_OFF LITERAL1 61 | LORA_AES_ON LITERAL1 62 | --------------------------------------------------------------------------------