├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake ├── ArduinoToolchain.cmake └── Platform │ └── Arduino.cmake ├── examples ├── DemoTest │ └── DemoTest.ino ├── DemoTestUnaShieldV1 │ └── DemoTestUnaShieldV1.ino ├── DemoTestUnaShieldV2S │ └── DemoTestUnaShieldV2S.ino ├── DemoTestUnaShieldV2S2 │ └── DemoTestUnaShieldV2S2.ino ├── DemoTestUnaShieldV2SRCZ3 │ └── DemoTestUnaShieldV2SRCZ3.ino ├── accelerometer-compass-V2S2-sensor │ └── accelerometer-compass-V2S2-sensor.ino ├── accelerometer-sensor │ └── accelerometer-sensor.ino ├── bean-test │ └── bean-test.ino ├── button-sensor │ └── button-sensor.ino ├── downlink │ └── downlink.ino ├── grove-sensor │ └── grove-sensor.ino ├── multiple_inputs │ ├── Fsm.cpp │ ├── Fsm.h │ ├── finite_state_machine.png │ ├── graphviz.dot │ └── multiple_inputs.ino ├── read-light-level │ └── read-light-level.ino ├── read-temperature │ └── read-temperature.ino ├── send-altitude-structured │ ├── Adafruit_BME280.cpp │ ├── Adafruit_BME280.h │ ├── Adafruit_Sensor.h │ └── send-altitude-structured.ino ├── send-altitude │ ├── Adafruit_BME280.cpp │ ├── Adafruit_BME280.h │ ├── Adafruit_Sensor.h │ └── send-altitude.ino ├── send-light-level │ └── send-light-level.ino ├── send-temperature │ ├── send-temperature.ino │ └── send-temperature.old ├── send-test │ ├── send-test.ino │ └── send-test.old └── temperature-sensor │ └── temperature-sensor.ino ├── keywords.txt ├── library.properties ├── src ├── Akeru.cpp ├── Akeru.h ├── BeanSoftwareSerial.cpp ├── BeanSoftwareSerial.h ├── Message.cpp ├── Message.h ├── Radiocrafts.cpp ├── Radiocrafts.h ├── SIGFOX.h ├── SamdSoftwareSerial.cpp ├── SamdSoftwareSerial.h ├── Wisol.cpp └── Wisol.h └── test ├── .idea └── vcs.xml ├── CMakeLists.txt ├── LocalDHT.cpp ├── LocalDHT.h ├── LocalWString.cpp ├── LocalWString.h ├── test.cpp ├── unabiz-arduino.ino └── util.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Manually classify the file types so that GitHub will label this as an Arduino project. 2 | *.ino linguist-language=Arduino 3 | *.cpp linguist-language=Arduino 4 | *.h linguist-language=Arduino 5 | *.cmake linguist-language=Arduino 6 | docs/* linguist-documentation 7 | 8 | # Set the default behavior, in case people don't have core.autocrlf set. 9 | * text eol=lf 10 | 11 | # Denote all files that are truly binary and should not be modified. 12 | *.png binary 13 | *.jpg binary 14 | 15 | # Custom for Visual Studio 16 | *.cs diff=csharp 17 | 18 | # Standard to msysgit 19 | *.doc diff=astextplain 20 | *.DOC diff=astextplain 21 | *.docx diff=astextplain 22 | *.DOCX diff=astextplain 23 | *.dot diff=astextplain 24 | *.DOT diff=astextplain 25 | *.pdf diff=astextplain 26 | *.PDF diff=astextplain 27 | *.rtf diff=astextplain 28 | *.RTF diff=astextplain 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | 3 | .idea/* 4 | test/.idea/* 5 | 6 | ### C++ template 7 | # Compiled Object files 8 | *.slo 9 | *.lo 10 | *.o 11 | *.obj 12 | 13 | # Precompiled Headers 14 | *.gch 15 | *.pch 16 | 17 | # Compiled Dynamic libraries 18 | *.so 19 | *.dylib 20 | *.dll 21 | 22 | # Fortran module files 23 | *.mod 24 | *.smod 25 | 26 | # Compiled Static libraries 27 | *.lai 28 | *.la 29 | *.a 30 | *.lib 31 | 32 | # Executables 33 | *.exe 34 | *.out 35 | *.app 36 | 37 | # This is needed for CLion compiler but causes problems for Arduino IDE. 38 | /unabiz-arduino.ino 39 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | set(CMAKE_VERBOSE_MAKEFILE TRUE) 3 | set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake) 4 | set(PROJECT_NAME unabiz-arduino) 5 | set(PROJECT_LIB ${PROJECT_NAME}_lib) 6 | project(${PROJECT_NAME}) 7 | add_definitions(-DCLION) 8 | message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") 9 | 10 | # Arduino Options - See https://github.com/queezythegreat/arduino-cmake 11 | # Change this to the Arduino port. 12 | #if(WIN32) 13 | #set(${PROJECT_NAME}_PORT COM4) 14 | #else() 15 | set(${PROJECT_NAME}_PORT /dev/tty.usbmodem1411) 16 | #endif() 17 | 18 | # Build the library. 19 | set(${PROJECT_LIB}_SRCS Akeru.cpp Message.cpp Radiocrafts.cpp Wisol.cpp) 20 | set(${PROJECT_LIB}_HDRS Akeru.h Message.h Radiocrafts.h SIGFOX.h Wisol.h) 21 | generate_arduino_library(${PROJECT_LIB}) 22 | 23 | # Build the application. 24 | set(${PROJECT_NAME}_SKETCH ${PROJECT_NAME}.ino) 25 | set(${PROJECT_NAME}_ARDLIBS SoftwareSerial) 26 | set(${PROJECT_NAME}_LIBS ${PROJECT_LIB}) 27 | generate_arduino_firmware(${PROJECT_NAME}) 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Check out the docs at: https://unabiz.github.io/unashield/ 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /cmake/ArduinoToolchain.cmake: -------------------------------------------------------------------------------- 1 | #=============================================================================# 2 | # Author: Tomasz Bogdal (QueezyTheGreat) 3 | # Home: https://github.com/queezythegreat/arduino-cmake 4 | # 5 | # This Source Code Form is subject to the terms of the Mozilla Public 6 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | # You can obtain one at http://mozilla.org/MPL/2.0/. 8 | #=============================================================================# 9 | set(CMAKE_SYSTEM_NAME Arduino) 10 | 11 | set(CMAKE_C_COMPILER avr-gcc) 12 | set(CMAKE_CXX_COMPILER avr-g++) 13 | 14 | # Add current directory to CMake Module path automatically 15 | if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/Platform/Arduino.cmake) 16 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}) 17 | endif() 18 | 19 | #=============================================================================# 20 | # System Paths # 21 | #=============================================================================# 22 | if(UNIX) 23 | include(Platform/UnixPaths) 24 | if(APPLE) 25 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ~/Applications 26 | /Applications 27 | /Developer/Applications 28 | /sw # Fink 29 | /opt/local) # MacPorts 30 | endif() 31 | elseif(WIN32) 32 | include(Platform/WindowsPaths) 33 | endif() 34 | 35 | 36 | #=============================================================================# 37 | # Detect Arduino SDK # 38 | #=============================================================================# 39 | if(NOT ARDUINO_SDK_PATH) 40 | set(ARDUINO_PATHS) 41 | 42 | foreach(DETECT_VERSION_MAJOR 1) 43 | foreach(DETECT_VERSION_MINOR RANGE 5 0) 44 | list(APPEND ARDUINO_PATHS arduino-${DETECT_VERSION_MAJOR}.${DETECT_VERSION_MINOR}) 45 | foreach(DETECT_VERSION_PATCH RANGE 3 0) 46 | list(APPEND ARDUINO_PATHS arduino-${DETECT_VERSION_MAJOR}.${DETECT_VERSION_MINOR}.${DETECT_VERSION_PATCH}) 47 | endforeach() 48 | endforeach() 49 | endforeach() 50 | 51 | foreach(VERSION RANGE 23 19) 52 | list(APPEND ARDUINO_PATHS arduino-00${VERSION}) 53 | endforeach() 54 | 55 | if(UNIX) 56 | file(GLOB SDK_PATH_HINTS /usr/share/arduino* 57 | /opt/local/arduino* 58 | /opt/arduino* 59 | /usr/local/share/arduino*) 60 | elseif(WIN32) 61 | set(SDK_PATH_HINTS "C:\\Program Files\\Arduino" 62 | "C:\\Program Files (x86)\\Arduino" 63 | ) 64 | endif() 65 | list(SORT SDK_PATH_HINTS) 66 | list(REVERSE SDK_PATH_HINTS) 67 | endif() 68 | 69 | find_path(ARDUINO_SDK_PATH 70 | NAMES lib/version.txt 71 | PATH_SUFFIXES share/arduino 72 | Arduino.app/Contents/Resources/Java/ 73 | Arduino.app/Contents/Java/ 74 | ${ARDUINO_PATHS} 75 | HINTS ${SDK_PATH_HINTS} 76 | DOC "Arduino SDK path.") 77 | 78 | if(ARDUINO_SDK_PATH) 79 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr) 80 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr/utils) 81 | else() 82 | message(FATAL_ERROR "Could not find Arduino SDK (set ARDUINO_SDK_PATH)!") 83 | endif() 84 | 85 | set(ARDUINO_CPUMENU) 86 | if(ARDUINO_CPU) 87 | set(ARDUINO_CPUMENU ".menu.cpu.${ARDUINO_CPU}") 88 | endif(ARDUINO_CPU) 89 | 90 | -------------------------------------------------------------------------------- /examples/DemoTest/DemoTest.ino: -------------------------------------------------------------------------------- 1 | // DemoTest moved to 2 | // DemoTestUnaShieldV1 for UnaShield V1 3 | // DemoTestUnaShieldV2S for UnaShield V2S 4 | -------------------------------------------------------------------------------- /examples/DemoTestUnaShieldV1/DemoTestUnaShieldV1.ino: -------------------------------------------------------------------------------- 1 | // Send sample SIGFOX messages with UnaBiz UnaShield V1 Arduino Shield. 2 | // This sketch includes diagnostics functions in the UnaShield. 3 | // For a simpler sample sketch, see examples/send-light-level. 4 | #include "SIGFOX.h" 5 | 6 | // IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly. 7 | static const String device = "g88pi"; // Set this to your device name if you're using UnaBiz Emulator. 8 | static const bool useEmulator = false; // Set to true if using UnaBiz Emulator. 9 | static const bool echo = true; // Set to true if the SIGFOX library should display the executed commands. 10 | static const Country country = COUNTRY_SG; // Set this to your country to configure the SIGFOX transmission frequencies. 11 | // static UnaShieldV2S transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V2S Dev Kit 12 | static UnaShieldV1 transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V1 Dev Kit 13 | 14 | void setup() { // Will be called only once. 15 | // Initialize console so we can see debug messages (9600 bits per second). 16 | Serial.begin(9600); Serial.println(F("Running setup...")); 17 | // Check whether the SIGFOX module is functioning. 18 | if (!transceiver.begin()) stop(F("Unable to init SIGFOX module, may be missing")); // Will never return. 19 | 20 | // Send a raw 12-byte message payload to SIGFOX. In the loop() function we will use the Message class, which sends structured messages. 21 | transceiver.sendMessage("0102030405060708090a0b0c"); 22 | // Delay 10 seconds before sending next message. 23 | Serial.println("Waiting 10 seconds..."); 24 | delay(10000); 25 | } 26 | 27 | void loop() { // Will be called repeatedly. 28 | // Send message counter, temperature and voltage as a SIGFOX message, up to 10 times. 29 | static int counter = 0, successCount = 0, failCount = 0; // Count messages sent and failed. 30 | Serial.print(F("\nRunning loop #")); Serial.println(counter); 31 | 32 | // Get temperature and voltage of the SIGFOX module. 33 | int temperature; float voltage; 34 | transceiver.getTemperature(temperature); 35 | transceiver.getVoltage(voltage); 36 | 37 | // Convert the numeric counter, temperature and voltage into a compact message with binary fields. 38 | Message msg(transceiver); // Will contain the structured sensor data. 39 | msg.addField("ctr", counter); // 4 bytes for the counter. 40 | msg.addField("tmp", temperature); // 4 bytes for the temperature. 41 | msg.addField("vlt", voltage); // 4 bytes for the voltage. 42 | // Total 12 bytes out of 12 bytes used. 43 | 44 | // Send the message. 45 | if (msg.send()) { 46 | successCount++; // If successful, count the message sent successfully. 47 | } else { 48 | failCount++; // If failed, count the message that could not be sent. 49 | } 50 | counter++; 51 | 52 | // Send only 10 messages. 53 | if (counter >= 10) { 54 | // If more than 10 times, display the results and hang here forever. 55 | stop(String(F("Messages sent successfully: ")) + successCount + 56 | F(", failed: ") + failCount); // Will never return. 57 | } 58 | 59 | // Delay 10 seconds before sending next message. 60 | Serial.println("Waiting 10 seconds..."); 61 | delay(10000); 62 | } 63 | 64 | /* Expected output for UnaShield V1: 65 | 66 | Running setup... 67 | - Disabling emulation mode... 68 | - Entering command mode... 69 | - Radiocrafts.sendBuffer: 00 70 | >> 00 71 | << 3e 72 | - Radiocrafts.sendBuffer: response: 73 | - Radiocrafts.enterCommandMode: OK 74 | - Entering config mode from send mode... 75 | - Radiocrafts.sendBuffer: 4d 76 | >> 4d 77 | << 3e 78 | - Radiocrafts.sendBuffer: response: 79 | - Radiocrafts.enterConfigMode: OK 80 | - Radiocrafts.sendBuffer: 2800 81 | >> 28 00 82 | << 83 | - Radiocrafts.sendBuffer: response: 84 | - Exiting config mode to send mode... 85 | - Radiocrafts.sendBuffer: ff 86 | >> ff 87 | << 3e 88 | - Radiocrafts.sendBuffer: response: 89 | - Radiocrafts.exitConfigMode: OK 90 | - Exiting command mode... 91 | - Radiocrafts.sendBuffer: 58 92 | >> 58 93 | << 94 | - Radiocrafts.sendBuffer: response: 95 | - Radiocrafts.exitCommandMode: OK 96 | - Checking emulation mode (expecting 0)... 97 | - Radiocrafts.getParameter: address=0x28 98 | - Entering command mode... 99 | - Radiocrafts.sendBuffer: 00 100 | >> 00 101 | << 3e 102 | - Radiocrafts.sendBuffer: response: 103 | - Radiocrafts.enterCommandMode: OK 104 | - Radiocrafts.sendBuffer: 5928 105 | >> 59 28 106 | << 3e 00 3e 107 | - Radiocrafts.sendBuffer: response: 00 108 | - Exiting command mode... 109 | - Radiocrafts.sendBuffer: 58 110 | >> 58 111 | << 112 | - Radiocrafts.sendBuffer: response: 113 | - Radiocrafts.exitCommandMode: OK 114 | - Radiocrafts.getParameter: address=0x28 returned 00 115 | - Getting SIGFOX ID... 116 | - Entering command mode... 117 | - Radiocrafts.sendBuffer: 00 118 | >> 00 119 | << 3e 120 | - Radiocrafts.sendBuffer: response: 121 | - Radiocrafts.enterCommandMode: OK 122 | - Radiocrafts.sendBuffer: 39 123 | >> 39 124 | << 34 8a 1c 00 7e ec d9 02 49 bf 58 8b 3e 125 | - Radiocrafts.sendBuffer: response: 348a1c007eecd90249bf588b 126 | - Exiting command mode... 127 | - Radiocrafts.sendBuffer: 58 128 | >> 58 129 | << 130 | - Radiocrafts.sendBuffer: response: 131 | - Radiocrafts.exitCommandMode: OK 132 | - Radiocrafts.getID: returned id=001c8a34, pac=7eecd90249bf588b 133 | - SIGFOX ID = 001c8a34 134 | - PAC = 7eecd90249bf588b 135 | - Setting frequency for country -26112 136 | - Radiocrafts.setFrequencySG 137 | - Entering command mode... 138 | - Radiocrafts.sendBuffer: 00 139 | >> 00 140 | << 3e 141 | - Radiocrafts.sendBuffer: response: 142 | - Radiocrafts.enterCommandMode: OK 143 | - Entering config mode from send mode... 144 | - Radiocrafts.sendBuffer: 4d 145 | >> 4d 146 | << 3e 147 | - Radiocrafts.sendBuffer: response: 148 | - Radiocrafts.enterConfigMode: OK 149 | - Radiocrafts.sendBuffer: 0003 150 | >> 00 03 151 | << 152 | - Radiocrafts.sendBuffer: response: 153 | - Exiting config mode to send mode... 154 | - Radiocrafts.sendBuffer: ff 155 | >> ff 156 | << 3e 157 | - Radiocrafts.sendBuffer: response: 158 | - Radiocrafts.exitConfigMode: OK 159 | - Exiting command mode... 160 | - Radiocrafts.sendBuffer: 58 161 | >> 58 162 | << 163 | - Radiocrafts.sendBuffer: response: 164 | - Radiocrafts.exitCommandMode: OK 165 | - Set frequency result = 166 | - Getting frequency (expecting 3)... 167 | - Entering command mode... 168 | - Radiocrafts.sendBuffer: 00 169 | >> 00 170 | << 3e 171 | - Radiocrafts.sendBuffer: response: 172 | - Radiocrafts.enterCommandMode: OK 173 | - Radiocrafts.sendBuffer: 5900 174 | >> 59 00 175 | << 3e 176 | - Radiocrafts.sendBuffer: response: 177 | - Exiting command mode... 178 | - Radiocrafts.sendBuffer: 58 179 | >> 58 180 | << 00 3e 181 | - Radiocrafts.sendBuffer: response: 00 182 | - Warning: Radiocrafts.exitCommandMode resending exit command, may be in incorrect mode 183 | - Radiocrafts.sendBuffer: 58 184 | >> 58 185 | << 186 | - Radiocrafts.sendBuffer: response: 187 | - Radiocrafts.exitCommandMode: OK 188 | - Frequency (expecting 3) = 189 | - Radiocrafts.sendMessage: 001c8a34,0102030405060708090a0b0c 190 | - Radiocrafts.sendBuffer: 0c0102030405060708090a0b0c 191 | >> 0c 01 02 03 04 05 06 07 08 09 0a 0b 0c 192 | << 193 | - Radiocrafts.sendBuffer: response: 194 | 195 | Waiting 10 seconds... 196 | 197 | Running loop #0 198 | - Entering command mode... 199 | - Radiocrafts.sendBuffer: 00 200 | >> 00 201 | << 3e 202 | - Radiocrafts.sendBuffer: response: 203 | - Radiocrafts.enterCommandMode: OK 204 | - Radiocrafts.sendBuffer: 55 205 | >> 55 206 | << a0 3e 207 | - Radiocrafts.sendBuffer: response: a0 208 | - Exiting command mode... 209 | - Radiocrafts.sendBuffer: 58 210 | >> 58 211 | << 212 | - Radiocrafts.sendBuffer: response: 213 | - Radiocrafts.exitCommandMode: OK 214 | - Radiocrafts.getTemperature: returned 32 215 | - Entering command mode... 216 | - Radiocrafts.sendBuffer: 00 217 | >> 00 218 | << 3e 219 | - Radiocrafts.sendBuffer: response: 220 | - Radiocrafts.enterCommandMode: OK 221 | - Radiocrafts.sendBuffer: 56 222 | >> 56 223 | << 71 3e 224 | - Radiocrafts.sendBuffer: response: 71 225 | - Exiting command mode... 226 | - Radiocrafts.sendBuffer: 58 227 | >> 58 228 | << 229 | - Radiocrafts.sendBuffer: response: 230 | - Radiocrafts.exitCommandMode: OK 231 | - Radiocrafts.getVoltage: returned 3.39 232 | - Message.addField: ctr=0 233 | - Message.addField: tmp=32 234 | - Message.addField: vlt=33.3 235 | - Radiocrafts.sendMessage: 001c8a34,920e0000b051400194592100 236 | Warning: Should wait 10 mins before sending the next message 237 | - Radiocrafts.sendBuffer: 0c920e0000b051400194592100 238 | >> 0c 92 0e 00 00 b0 51 40 01 94 59 21 00 239 | << 240 | - Radiocrafts.sendBuffer: response: 241 | 242 | Waiting 10 seconds... 243 | 244 | Running loop #1 245 | - Entering command mode... 246 | - Radiocrafts.sendBuffer: 00 247 | >> 00 248 | << 3e 249 | - Radiocrafts.sendBuffer: response: 250 | - Radiocrafts.enterCommandMode: OK 251 | - Radiocrafts.sendBuffer: 55 252 | >> 55 253 | << a0 3e 254 | - Radiocrafts.sendBuffer: response: a0 255 | - Exiting command mode... 256 | - Radiocrafts.sendBuffer: 58 257 | >> 58 258 | << 259 | - Radiocrafts.sendBuffer: response: 260 | - Radiocrafts.exitCommandMode: OK 261 | - Radiocrafts.getTemperature: returned 32 262 | - Entering command mode... 263 | - Radiocrafts.sendBuffer: 00 264 | >> 00 265 | << 3e 266 | - Radiocrafts.sendBuffer: response: 267 | - Radiocrafts.enterCommandMode: OK 268 | - Radiocrafts.sendBuffer: 56 269 | >> 56 270 | << 71 3e 271 | - Radiocrafts.sendBuffer: response: 71 272 | - Exiting command mode... 273 | - Radiocrafts.sendBuffer: 58 274 | >> 58 275 | << 276 | - Radiocrafts.sendBuffer: response: 277 | - Radiocrafts.exitCommandMode: OK 278 | - Radiocrafts.getVoltage: returned 3.39 279 | - Message.addField: ctr=1 280 | - Message.addField: tmp=32 281 | - Message.addField: vlt=33.3 282 | - Radiocrafts.sendMessage: 001c8a34,920e0a00b051400194592100 283 | Warning: Should wait 10 mins before sending the next message 284 | - Radiocrafts.sendBuffer: 0c920e0a00b051400194592100 285 | >> 0c 92 0e 0a 00 b0 51 40 01 94 59 21 00 286 | << 287 | - Radiocrafts.sendBuffer: response: 288 | 289 | Waiting 10 seconds... 290 | 291 | Running loop #2 292 | - Entering command mode... 293 | - Radiocrafts.sendBuffer: 00 294 | >> 00 295 | << 3e 296 | - Radiocrafts.sendBuffer: response: 297 | - Radiocrafts.enterCommandMode: OK 298 | - Radiocrafts.sendBuffer: 55 299 | >> 55 300 | << a1 3e 301 | - Radiocrafts.sendBuffer: response: a1 302 | - Exiting command mode... 303 | - Radiocrafts.sendBuffer: 58 304 | >> 58 305 | << 306 | - Radiocrafts.sendBuffer: response: 307 | - Radiocrafts.exitCommandMode: OK 308 | - Radiocrafts.getTemperature: returned 33 309 | - Entering command mode... 310 | - Radiocrafts.sendBuffer: 00 311 | >> 00 312 | << 3e 313 | - Radiocrafts.sendBuffer: response: 314 | - Radiocrafts.enterCommandMode: OK 315 | - Radiocrafts.sendBuffer: 56 316 | >> 56 317 | << 71 3e 318 | - Radiocrafts.sendBuffer: response: 71 319 | - Exiting command mode... 320 | - Radiocrafts.sendBuffer: 58 321 | >> 58 322 | << 323 | - Radiocrafts.sendBuffer: response: 324 | - Radiocrafts.exitCommandMode: OK 325 | - Radiocrafts.getVoltage: returned 3.39 326 | - Message.addField: ctr=2 327 | - Message.addField: tmp=33 328 | - Message.addField: vlt=33.3 329 | - Radiocrafts.sendMessage: 001c8a34,920e1400b0514a0194592100 330 | Warning: Should wait 10 mins before sending the next message 331 | - Radiocrafts.sendBuffer: 0c920e1400b0514a0194592100 332 | >> 0c 92 0e 14 00 b0 51 4a 01 94 59 21 00 333 | << 334 | - Radiocrafts.sendBuffer: response: 335 | 336 | Waiting 10 seconds... 337 | 338 | Running loop #3 339 | - Entering command mode... 340 | - Radiocrafts.sendBuffer: 00 341 | >> 00 342 | << 3e 343 | - Radiocrafts.sendBuffer: response: 344 | - Radiocrafts.enterCommandMode: OK 345 | - Radiocrafts.sendBuffer: 55 346 | >> 55 347 | << a1 3e 348 | - Radiocrafts.sendBuffer: response: a1 349 | - Exiting command mode... 350 | - Radiocrafts.sendBuffer: 58 351 | >> 58 352 | << 353 | - Radiocrafts.sendBuffer: response: 354 | - Radiocrafts.exitCommandMode: OK 355 | - Radiocrafts.getTemperature: returned 33 356 | - Entering command mode... 357 | - Radiocrafts.sendBuffer: 00 358 | >> 00 359 | << 3e 360 | - Radiocrafts.sendBuffer: response: 361 | - Radiocrafts.enterCommandMode: OK 362 | - Radiocrafts.sendBuffer: 56 363 | >> 56 364 | << 71 3e 365 | - Radiocrafts.sendBuffer: response: 71 366 | - Exiting command mode... 367 | - Radiocrafts.sendBuffer: 58 368 | >> 58 369 | << 370 | - Radiocrafts.sendBuffer: response: 371 | - Radiocrafts.exitCommandMode: OK 372 | - Radiocrafts.getVoltage: returned 3.39 373 | - Message.addField: ctr=3 374 | - Message.addField: tmp=33 375 | - Message.addField: vlt=33.3 376 | - Radiocrafts.sendMessage: 001c8a34,920e1e00b0514a0194592100 377 | Warning: Should wait 10 mins before sending the next message 378 | - Radiocrafts.sendBuffer: 0c920e1e00b0514a0194592100 379 | >> 0c 92 0e 1e 00 b0 51 4a 01 94 59 21 00 380 | << 381 | - Radiocrafts.sendBuffer: response: 382 | 383 | Waiting 10 seconds... 384 | 385 | */ 386 | 387 | -------------------------------------------------------------------------------- /examples/DemoTestUnaShieldV2S/DemoTestUnaShieldV2S.ino: -------------------------------------------------------------------------------- 1 | // Send sample SIGFOX messages with UnaBiz UnaShield V2S Arduino Shield. 2 | // This sketch includes diagnostics functions in the UnaShield. 3 | // For a simpler sample sketch, see examples/send-light-level. 4 | #include "SIGFOX.h" 5 | 6 | // IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly. 7 | static const String device = "g88pi"; // Set this to your device name if you're using UnaBiz Emulator. 8 | static const bool useEmulator = false; // Set to true if using UnaBiz Emulator. 9 | static const bool echo = true; // Set to true if the SIGFOX library should display the executed commands. 10 | static const Country country = COUNTRY_SG; // Set this to your country to configure the SIGFOX transmission frequencies. 11 | static UnaShieldV2S transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V2S Dev Kit 12 | // static UnaShieldV1 transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V1 Dev Kit 13 | 14 | void setup() { // Will be called only once. 15 | // Initialize console so we can see debug messages (9600 bits per second). 16 | Serial.begin(9600); Serial.println(F("Running setup...")); 17 | // Check whether the SIGFOX module is functioning. 18 | if (!transceiver.begin()) stop(F("Unable to init SIGFOX module, may be missing")); // Will never return. 19 | 20 | // Send a raw 12-byte message payload to SIGFOX. In the loop() function we will use the Message class, which sends structured messages. 21 | transceiver.sendMessage("0102030405060708090a0b0c"); 22 | 23 | // Delay 10 seconds before sending next message. 24 | Serial.println(F("Waiting 10 seconds...")); 25 | delay(10000); 26 | } 27 | 28 | void loop() { // Will be called repeatedly. 29 | // Send message counter, temperature and voltage as a structured SIGFOX message, up to 10 times. 30 | static int counter = 0, successCount = 0, failCount = 0; // Count messages sent and failed. 31 | Serial.print(F("\nRunning loop #")); Serial.println(counter); 32 | 33 | // Get temperature and voltage of the SIGFOX module. 34 | float temperature; float voltage; 35 | transceiver.getTemperature(temperature); 36 | transceiver.getVoltage(voltage); 37 | 38 | // Convert the numeric counter, temperature and voltage into a compact message with binary fields. 39 | Message msg(transceiver); // Will contain the structured sensor data. 40 | msg.addField("ctr", counter); // 4 bytes for the counter. 41 | msg.addField("tmp", temperature); // 4 bytes for the temperature. 42 | msg.addField("vlt", voltage); // 4 bytes for the voltage. 43 | // Total 12 bytes out of 12 bytes used. 44 | 45 | // Send the message. 46 | if (msg.send()) { 47 | successCount++; // If successful, count the message sent successfully. 48 | } else { 49 | failCount++; // If failed, count the message that could not be sent. 50 | } 51 | counter++; 52 | 53 | // Send only 10 messages. 54 | if (counter >= 10) { 55 | // If more than 10 times, display the results and hang here forever. 56 | stop(String(F("Messages sent successfully: ")) + successCount + 57 | F(", failed: ") + failCount); // Will never return. 58 | } 59 | 60 | // Delay 10 seconds before sending next message. 61 | Serial.println("Waiting 10 seconds..."); 62 | delay(10000); 63 | } 64 | 65 | /* Expected output for UnaShield V2S: 66 | 67 | Running setup... 68 | - Disabling emulation mode... 69 | - Checking emulation mode (expecting 0)... 70 | - Getting SIGFOX ID... 71 | - Wisol.sendBuffer: AT$I=10 72 | 73 | >> AT$I=10 74 | << 002C30EB0x0d 75 | - Wisol.sendBuffer: response: 002C30EB 76 | - Wisol.sendBuffer: AT$I=11 77 | 78 | >> AT$I=11 79 | << A8664B5523B5405D0x0d 80 | - Wisol.sendBuffer: response: A8664B5523B5405D 81 | - Wisol.getID: returned id=002C30EB, pac=A8664B5523B5405D 82 | - SIGFOX ID = 002C30EB 83 | - PAC = A8664B5523B5405D 84 | - Wisol.setFrequencySG 85 | - Set frequency result = OK 86 | - Getting frequency (expecting 3)... 87 | - Frequency (expecting 3) = 52 88 | - Wisol.sendMessage: 002C30EB,0102030405060708090a0b0c 89 | - Wisol.sendBuffer: AT$GI? 90 | 91 | >> AT$GI? 92 | 93 | << 1,3 94 | - Wisol.sendBuffer: response: 1,3 95 | - Wisol.sendBuffer: AT$SF=0102030405060708090a0b0c 96 | 97 | >> AT$SF=0102030405060708090a0b0c 98 | 99 | << OK0x0d 100 | - Wisol.sendBuffer: response: OK 101 | OK 102 | Waiting 10 seconds... 103 | 104 | Running loop #0 105 | - Wisol.sendBuffer: AT$T? 106 | 107 | >> AT$T? 108 | << 277 109 | - Wisol.sendBuffer: response: 277 110 | - Wisol.getTemperature: returned 2.77 111 | - Wisol.sendBuffer: AT$V? 112 | 113 | >> AT$V? 114 | << 33500x0d 115 | - Wisol.sendBuffer: response: 3350 116 | - Wisol.getVoltage: returned 3.35 117 | - Message.addField: ctr=0 118 | - Message.addField: tmp=27.7 119 | - Message.addField: vlt=33.3 120 | - Wisol.sendMessage: 002C30EB,920e0000b0511b0094592100 121 | Warning: Should wait 10 mins before sending the next message 122 | - Wisol.sendBuffer: AT$GI? 123 | 124 | >> AT$GI? 125 | 126 | << 1,0 127 | - Wisol.sendBuffer: response: 1,0 128 | - Wisol.sendBuffer: AT$RC 129 | 130 | >> AT$RC 131 | << OK0x0d 132 | - Wisol.sendBuffer: response: OK 133 | - Wisol.sendBuffer: AT$SF=920e0000b0511b0094592100 134 | 135 | >> AT$SF=920e0000b0511b0094592100 136 | 137 | << OK0x0d 138 | - Wisol.sendBuffer: response: OK 139 | OK 140 | Waiting 10 seconds... 141 | */ 142 | 143 | -------------------------------------------------------------------------------- /examples/DemoTestUnaShieldV2S2/DemoTestUnaShieldV2S2.ino: -------------------------------------------------------------------------------- 1 | // Send sample SIGFOX messages with UnaBiz UnaShield V2S Arduino Shield. 2 | // This sketch includes diagnostics functions in the UnaShield. 3 | // For a simpler sample sketch, see examples/send-light-level. 4 | #include "SIGFOX.h" 5 | 6 | // IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly. 7 | static const String device = "g88pi"; // Set this to your device name if you're using UnaBiz Emulator. 8 | static const bool useEmulator = false; // Set to true if using UnaBiz Emulator. 9 | static const bool echo = true; // Set to true if the SIGFOX library should display the executed commands. 10 | static const Country country = COUNTRY_TW; // Set this to your country to configure the SIGFOX transmission frequencies. 11 | static UnaShieldV2S transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V2S / V2S2 Dev Kit 12 | // static UnaShieldV1 transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V1 Dev Kit 13 | 14 | void setup() { // Will be called only once. 15 | // Initialize console so we can see debug messages (9600 bits per second). 16 | Serial.begin(9600); Serial.println(F("Running setup...")); 17 | // Check whether the SIGFOX module is functioning. 18 | if (!transceiver.begin()) stop(F("Unable to init SIGFOX module, may be missing")); // Will never return. 19 | 20 | // Send a raw 12-byte message payload to SIGFOX. In the loop() function we will use the Message class, which sends structured messages. 21 | transceiver.sendMessage("0102030405060708090a0b0c"); 22 | 23 | // Delay 10 seconds before sending next message. 24 | Serial.println(F("Waiting 10 seconds...")); 25 | delay(10000); 26 | } 27 | 28 | void loop() { // Will be called repeatedly. 29 | // Send message counter, temperature and voltage as a structured SIGFOX message, up to 10 times. 30 | static int counter = 0, successCount = 0, failCount = 0; // Count messages sent and failed. 31 | Serial.print(F("\nRunning loop #")); Serial.println(counter); 32 | 33 | // Get temperature and voltage of the SIGFOX module. 34 | float temperature; float voltage; 35 | transceiver.getTemperature(temperature); 36 | transceiver.getVoltage(voltage); 37 | 38 | // Convert the numeric counter, temperature and voltage into a compact message with binary fields. 39 | Message msg(transceiver); // Will contain the structured sensor data. 40 | msg.addField("ctr", counter); // 4 bytes for the counter. 41 | msg.addField("tmp", temperature); // 4 bytes for the temperature. 42 | msg.addField("vlt", voltage); // 4 bytes for the voltage. 43 | // Total 12 bytes out of 12 bytes used. 44 | 45 | // Send the message. 46 | if (msg.send()) { 47 | successCount++; // If successful, count the message sent successfully. 48 | } else { 49 | failCount++; // If failed, count the message that could not be sent. 50 | } 51 | counter++; 52 | 53 | // Send only 10 messages. 54 | if (counter >= 10) { 55 | // If more than 10 times, display the results and hang here forever. 56 | stop(String(F("Messages sent successfully: ")) + successCount + 57 | F(", failed: ") + failCount); // Will never return. 58 | } 59 | 60 | // Delay 10 seconds before sending next message. 61 | Serial.println("Waiting 10 seconds..."); 62 | delay(10000); 63 | } 64 | 65 | /* Expected output for UnaShield V2S: 66 | 67 | Running setup... 68 | - Disabling emulation mode... 69 | - Checking emulation mode (expecting 0)... 70 | - Getting SIGFOX ID... 71 | - Wisol.sendBuffer: AT$I=10 72 | 73 | >> AT$I=10 74 | << 002C30EB0x0d 75 | - Wisol.sendBuffer: response: 002C30EB 76 | - Wisol.sendBuffer: AT$I=11 77 | 78 | >> AT$I=11 79 | << A8664B5523B5405D0x0d 80 | - Wisol.sendBuffer: response: A8664B5523B5405D 81 | - Wisol.getID: returned id=002C30EB, pac=A8664B5523B5405D 82 | - SIGFOX ID = 002C30EB 83 | - PAC = A8664B5523B5405D 84 | - Wisol.setFrequencySG 85 | - Set frequency result = OK 86 | - Getting frequency (expecting 3)... 87 | - Frequency (expecting 3) = 52 88 | - Wisol.sendMessage: 002C30EB,0102030405060708090a0b0c 89 | - Wisol.sendBuffer: AT$GI? 90 | 91 | >> AT$GI? 92 | 93 | << 1,3 94 | - Wisol.sendBuffer: response: 1,3 95 | - Wisol.sendBuffer: AT$SF=0102030405060708090a0b0c 96 | 97 | >> AT$SF=0102030405060708090a0b0c 98 | 99 | << OK0x0d 100 | - Wisol.sendBuffer: response: OK 101 | OK 102 | Waiting 10 seconds... 103 | 104 | Running loop #0 105 | - Wisol.sendBuffer: AT$T? 106 | 107 | >> AT$T? 108 | << 277 109 | - Wisol.sendBuffer: response: 277 110 | - Wisol.getTemperature: returned 2.77 111 | - Wisol.sendBuffer: AT$V? 112 | 113 | >> AT$V? 114 | << 33500x0d 115 | - Wisol.sendBuffer: response: 3350 116 | - Wisol.getVoltage: returned 3.35 117 | - Message.addField: ctr=0 118 | - Message.addField: tmp=27.7 119 | - Message.addField: vlt=33.3 120 | - Wisol.sendMessage: 002C30EB,920e0000b0511b0094592100 121 | Warning: Should wait 10 mins before sending the next message 122 | - Wisol.sendBuffer: AT$GI? 123 | 124 | >> AT$GI? 125 | 126 | << 1,0 127 | - Wisol.sendBuffer: response: 1,0 128 | - Wisol.sendBuffer: AT$RC 129 | 130 | >> AT$RC 131 | << OK0x0d 132 | - Wisol.sendBuffer: response: OK 133 | - Wisol.sendBuffer: AT$SF=920e0000b0511b0094592100 134 | 135 | >> AT$SF=920e0000b0511b0094592100 136 | 137 | << OK0x0d 138 | - Wisol.sendBuffer: response: OK 139 | OK 140 | Waiting 10 seconds... 141 | */ 142 | 143 | -------------------------------------------------------------------------------- /examples/DemoTestUnaShieldV2SRCZ3/DemoTestUnaShieldV2SRCZ3.ino: -------------------------------------------------------------------------------- 1 | // Send sample SIGFOX messages with UnaBiz UnaShield V2S Arduino Shield. 2 | // This sketch includes diagnostics functions in the UnaShield. 3 | // For a simpler sample sketch, see examples/send-light-level. 4 | #include "SIGFOX.h" 5 | 6 | // IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly. 7 | static const String device = "NOTUSED"; // Set this to your device name if you're using UnaBiz Emulator. 8 | static const bool useEmulator = false; // Set to true if using UnaBiz Emulator. 9 | static const bool echo = true; // Set to true if the SIGFOX library should display the executed commands. 10 | static const Country country = COUNTRY_JP; // Set this to your country to configure the SIGFOX transmission frequencies. 11 | static UnaShieldV2S transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V2S Dev Kit 12 | static String response; // Will store the downlink response from SIGFOX. 13 | 14 | void setup() { // Will be called only once. 15 | // Initialize console so we can see debug messages (9600 bits per second). 16 | Serial.begin(9600); Serial.println(F("Running setup...")); 17 | // Check whether the SIGFOX module is functioning. 18 | if (!transceiver.begin()) stop(F("Unable to init SIGFOX module, may be missing")); // Will never return. 19 | 20 | // Send a raw 12-byte message payload to SIGFOX. In the loop() function we will use the Message class, which sends structured messages. 21 | transceiver.sendMessage("0102030405060708090a0b0c"); 22 | 23 | // Delay 10 seconds before sending next message. 24 | Serial.println(F("Waiting 10 seconds...")); 25 | delay(10000); 26 | } 27 | 28 | void loop() { // Will be called repeatedly. 29 | // Send message counter, temperature and voltage as a structured SIGFOX message, up to 10 times. 30 | static int counter = 0, successCount = 0, failCount = 0; // Count messages sent and failed. 31 | Serial.print(F("\nRunning loop #")); Serial.println(counter); 32 | 33 | // Get temperature and voltage of the SIGFOX module. 34 | float temperature; float voltage; 35 | transceiver.getTemperature(temperature); 36 | transceiver.getVoltage(voltage); 37 | 38 | // Convert the numeric counter, temperature and voltage into a compact message with binary fields. 39 | Message msg(transceiver); // Will contain the structured sensor data. 40 | msg.addField("ctr", counter); // 4 bytes for the counter. 41 | msg.addField("tmp", temperature); // 4 bytes for the temperature. 42 | msg.addField("vlt", voltage); // 4 bytes for the voltage. 43 | // Total 12 bytes out of 12 bytes used. 44 | 45 | // Send the message. 46 | if (msg.send()) { 47 | successCount++; // If successful, count the message sent successfully. 48 | } else { 49 | failCount++; // If failed, count the message that could not be sent. 50 | } 51 | counter++; 52 | 53 | // Send only 10 messages. 54 | if (counter >= 10) { 55 | // If more than 10 times, display the results and hang here forever. 56 | stop(String(F("Messages sent successfully: ")) + successCount + 57 | F(", failed: ") + failCount); // Will never return. 58 | } 59 | 60 | // Delay 10 seconds before sending next message. 61 | Serial.println("Waiting 10 seconds..."); 62 | delay(10000); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /examples/accelerometer-compass-V2S2-sensor/accelerometer-compass-V2S2-sensor.ino: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file X_NUCLEO_IKS01A2_LSM303AGR_DataLog_Terminal.ino 4 | * @author AST 5 | * @version V1.0.0 6 | * @date 7 September 2017 7 | * @brief Arduino test application for the STMicrolectronics X-NUCLEO-IKS01A2 8 | * MEMS Inertial and Environmental sensor expansion board. 9 | * This application makes use of C++ classes obtained from the C 10 | * components' drivers. 11 | ****************************************************************************** 12 | * @attention 13 | * 14 | *

© COPYRIGHT(c) 2017 STMicroelectronics

15 | * 16 | * Redistribution and use in source and binary forms, with or without modification, 17 | * are permitted provided that the following conditions are met: 18 | * 1. Redistributions of source code must retain the above copyright notice, 19 | * this list of conditions and the following disclaimer. 20 | * 2. Redistributions in binary form must reproduce the above copyright notice, 21 | * this list of conditions and the following disclaimer in the documentation 22 | * and/or other materials provided with the distribution. 23 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 33 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 35 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | ****************************************************************************** 39 | */ 40 | 41 | 42 | // Includes. 43 | #include 44 | #include 45 | 46 | #if defined(ARDUINO_SAM_DUE) 47 | #define DEV_I2C Wire1 //Define which I2C bus is used. Wire1 for the Arduino Due 48 | #define SerialPort Serial 49 | #else 50 | #define DEV_I2C Wire //Or Wire 51 | #define SerialPort Serial 52 | #endif 53 | 54 | // Components. 55 | LSM303AGR_ACC_Sensor *Acc; 56 | LSM303AGR_MAG_Sensor *Mag; 57 | 58 | void setup() { 59 | // Led. 60 | pinMode(13, OUTPUT); 61 | 62 | // Initialize serial for output. 63 | SerialPort.begin(9600); 64 | 65 | // Initialize I2C bus. 66 | DEV_I2C.begin(); 67 | 68 | // Initlialize components. 69 | Acc = new LSM303AGR_ACC_Sensor(&DEV_I2C); 70 | Acc->Enable(); 71 | Mag = new LSM303AGR_MAG_Sensor(&DEV_I2C); 72 | Mag->Enable(); 73 | } 74 | 75 | void loop() { 76 | // Led blinking. 77 | digitalWrite(13, HIGH); 78 | delay(250); 79 | digitalWrite(13, LOW); 80 | delay(250); 81 | 82 | // Read accelerometer LSM303AGR. 83 | int32_t accelerometer[3]; 84 | Acc->GetAxes(accelerometer); 85 | 86 | // Read magnetometer LSM303AGR. 87 | int32_t magnetometer[3]; 88 | Mag->GetAxes(magnetometer); 89 | 90 | // Output data. 91 | SerialPort.print("| Acc[mg]: "); 92 | SerialPort.print(accelerometer[0]); 93 | SerialPort.print(" "); 94 | SerialPort.print(accelerometer[1]); 95 | SerialPort.print(" "); 96 | SerialPort.print(accelerometer[2]); 97 | SerialPort.print(" | Mag[mGauss]: "); 98 | SerialPort.print(magnetometer[0]); 99 | SerialPort.print(" "); 100 | SerialPort.print(magnetometer[1]); 101 | SerialPort.print(" "); 102 | SerialPort.print(magnetometer[2]); 103 | SerialPort.println(" |"); 104 | } -------------------------------------------------------------------------------- /examples/accelerometer-sensor/accelerometer-sensor.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************/ 2 | /*! 3 | @file Adafruit_MMA8451.h 4 | @author K. Townsend (Adafruit Industries) 5 | @license BSD (see license.txt) 6 | 7 | This is an example for the Adafruit MMA8451 Accel breakout board 8 | ----> https://www.adafruit.com/products/2019 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | @section HISTORY 15 | 16 | v1.0 - First release 17 | */ 18 | /**************************************************************************/ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | Adafruit_MMA8451 mma = Adafruit_MMA8451(); 25 | 26 | void setup(void) { 27 | Serial.begin(9600); 28 | 29 | Serial.println("Adafruit MMA8451 test!"); 30 | 31 | 32 | ////if (! mma.begin()) { 33 | if (! mma.begin(0x1c)) { //// // NOTE: Must use 0x1c for UnaShield V2S 34 | Serial.println("Couldnt start"); 35 | while (1); 36 | } 37 | Serial.println("MMA8451 found!"); 38 | 39 | mma.setRange(MMA8451_RANGE_2_G); 40 | 41 | Serial.print("Range = "); Serial.print(2 << mma.getRange()); 42 | Serial.println("G"); 43 | 44 | } 45 | 46 | void loop() { 47 | // Read the 'raw' data in 14-bit counts 48 | mma.read(); 49 | Serial.print("X:\t"); Serial.print(mma.x); 50 | Serial.print("\tY:\t"); Serial.print(mma.y); 51 | Serial.print("\tZ:\t"); Serial.print(mma.z); 52 | Serial.println(); 53 | 54 | /* Get a new sensor event */ 55 | sensors_event_t event; 56 | mma.getEvent(&event); 57 | 58 | /* Display the results (acceleration is measured in m/s^2) */ 59 | Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t"); 60 | Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t"); 61 | Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t"); 62 | Serial.println("m/s^2 "); 63 | 64 | /* Get the orientation of the sensor */ 65 | uint8_t o = mma.getOrientation(); 66 | 67 | switch (o) { 68 | case MMA8451_PL_PUF: 69 | Serial.println("Portrait Up Front"); 70 | break; 71 | case MMA8451_PL_PUB: 72 | Serial.println("Portrait Up Back"); 73 | break; 74 | case MMA8451_PL_PDF: 75 | Serial.println("Portrait Down Front"); 76 | break; 77 | case MMA8451_PL_PDB: 78 | Serial.println("Portrait Down Back"); 79 | break; 80 | case MMA8451_PL_LRF: 81 | Serial.println("Landscape Right Front"); 82 | break; 83 | case MMA8451_PL_LRB: 84 | Serial.println("Landscape Right Back"); 85 | break; 86 | case MMA8451_PL_LLF: 87 | Serial.println("Landscape Left Front"); 88 | break; 89 | case MMA8451_PL_LLB: 90 | Serial.println("Landscape Left Back"); 91 | break; 92 | } 93 | Serial.println(); 94 | delay(500); 95 | 96 | } 97 | /* 98 | Adafruit MMA8451 test! 99 | MMA8451 found! 100 | Range = 2G 101 | X: -7363 Y: 191 Z: 4070 102 | X: -0.24 Y: 0.11 Z: 9.67 m/s^2 103 | Portrait Up Front 104 | 105 | X: -84 Y: 52 Z: 4054 106 | X: -0.22 Y: 0.10 Z: 9.65 m/s^2 107 | Portrait Up Front 108 | 109 | X: -98 Y: 38 Z: 4036 110 | X: -0.23 Y: 0.12 Z: 9.70 m/s^2 111 | Portrait Up Front 112 | 113 | X: -94 Y: 52 Z: 4034 114 | X: -0.22 Y: 0.11 Z: 9.65 m/s^2 115 | Portrait Up Front 116 | 117 | X: -84 Y: 54 Z: 4052 118 | X: -0.20 Y: 0.11 Z: 9.64 m/s^2 119 | Portrait Up Front 120 | 121 | X: -80 Y: 32 Z: 4044 122 | X: -0.21 Y: 0.11 Z: 9.66 m/s^2 123 | Portrait Up Front 124 | 125 | X: -90 Y: 52 Z: 4018 126 | X: -0.21 Y: 0.08 Z: 9.67 m/s^2 127 | Portrait Up Front 128 | 129 | X: -98 Y: 46 Z: 4028 130 | X: -0.24 Y: 0.11 Z: 9.66 m/s^2 131 | Portrait Up Front 132 | 133 | X: -92 Y: 36 Z: 4032 134 | X: -0.23 Y: 0.07 Z: 9.65 m/s^2 135 | Portrait Up Front 136 | 137 | X: 332 Y: -16 Z: 4274 138 | X: 0.35 Y: -0.01 Z: 10.13 m/s^2 139 | Portrait Up Front 140 | 141 | X: 80 Y: -2046 Z: 2946 142 | X: 0.16 Y: -4.73 Z: 6.59 m/s^2 143 | Portrait Up Front 144 | 145 | X: -608 Y: 1050 Z: 3746 146 | X: -1.44 Y: 2.62 Z: 9.02 m/s^2 147 | Portrait Down Front 148 | 149 | X: -176 Y: -404 Z: 6182 150 | X: -0.46 Y: -1.60 Z: 15.28 m/s^2 151 | Portrait Down Front 152 | 153 | X: -830 Y: 680 Z: 2916 154 | X: -2.02 Y: 1.72 Z: 7.07 m/s^2 155 | Portrait Down Front 156 | 157 | X: -622 Y: 490 Z: 3862 158 | X: -1.44 Y: 1.14 Z: 9.22 m/s^2 159 | Portrait Down Front 160 | 161 | X: -322 Y: 376 Z: 2848 162 | X: -0.43 Y: 1.43 Z: 7.53 m/s^2 163 | Portrait Up Front 164 | 165 | X: -142 Y: 44 Z: 4060 166 | X: -0.32 Y: 0.11 Z: 9.66 m/s^2 167 | Portrait Up Front 168 | 169 | X: -144 Y: 46 Z: 4022 170 | X: -0.34 Y: 0.12 Z: 9.64 m/s^2 171 | Portrait Up Front 172 | 173 | X: -130 Y: 36 Z: 4056 174 | X: -0.35 Y: 0.13 Z: 9.70 m/s^2 175 | Portrait Up Front 176 | 177 | X: -132 Y: 42 Z: 4044 178 | X: -0.32 Y: 0.11 Z: 9.67 m/s^2 179 | Portrait Up Front 180 | 181 | X: -144 Y: 52 Z: 4042 182 | X: -0.32 Y: 0.15 Z: 9.67 m/s^2 183 | Portrait Up Front 184 | 185 | X: -134 Y: 38 Z: 4046 186 | X: -0.33 Y: 0.09 Z: 9.68 m/s^2 187 | Portrait Up Front 188 | 189 | X: -124 Y: 44 Z: 4054 190 | X: -0.28 Y: 0.11 Z: 9.75 m/s^2 191 | Portrait Up Front 192 | 193 | X: -120 Y: 44 Z: 4044 194 | X: -0.28 Y: 0.14 Z: 9.72 m/s^2 195 | Portrait Up Front 196 | 197 | X: -140 Y: 54 Z: 4032 198 | X: -0.29 Y: 0.13 Z: 9.66 m/s^2 199 | Portrait Up Front 200 | 201 | X: -122 Y: 52 Z: 4054 202 | X: -0.31 Y: 0.11 Z: 9.70 m/s^2 203 | Portrait Up Front 204 | 205 | X: -112 Y: 42 Z: 4072 206 | X: -0.32 Y: 0.13 Z: 9.74 m/s^2 207 | Portrait Up Front 208 | 209 | X: -124 Y: 34 Z: 4034 210 | X: -0.28 Y: 0.11 Z: 9.68 m/s^2 211 | Portrait Up Front 212 | 213 | X: -120 Y: 48 Z: 4040 214 | X: -0.30 Y: 0.11 Z: 9.66 m/s^2 215 | Portrait Up Front 216 | 217 | X: -110 Y: 48 Z: 4034 218 | X: -0.30 Y: 0.12 Z: 9.68 m/s^2 219 | Portrait Up Front 220 | 221 | X: -128 Y: 48 Z: 4038 222 | X: -0.30 Y: 0.13 Z: 9.68 m/s^2 223 | Portrait Up Front 224 | 225 | X: -130 Y: 36 Z: 4040 226 | X: -0.31 Y: 0.11 Z: 9.63 m/s^2 227 | Portrait Up Front 228 | 229 | */ 230 | -------------------------------------------------------------------------------- /examples/bean-test/bean-test.ino: -------------------------------------------------------------------------------- 1 | /* /Applications/Arduino.app/Contents/Java/hardware/LightBlue-Bean/avr/libraries/SoftwareSerial/SoftwareSerial.cpp: 2 | 3 | #if !defined(BEAN_BEAN_BEAN_H) //// 4 | 5 | #if defined(PCINT0_vect) 6 | ISR(PCINT0_vect) 7 | { 8 | SoftwareSerial::handle_interrupt(); 9 | } 10 | #endif 11 | 12 | #if defined(PCINT1_vect) 13 | ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect)); 14 | #endif 15 | 16 | #if defined(PCINT2_vect) 17 | ISR(PCINT2_vect, ISR_ALIASOF(PCINT0_vect)); 18 | #endif 19 | 20 | #if defined(PCINT3_vect) 21 | ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect)); 22 | #endif 23 | 24 | #else //// BEAN_BEAN_H 25 | #include "PinChangeInt.h" 26 | #endif //// BEAN_BEAN_H 27 | 28 | // 29 | // Constructor 30 | // 31 | SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false) : 32 | _rx_delay_centering(0), 33 | _rx_delay_intrabit(0), 34 | _rx_delay_stopbit(0), 35 | _tx_delay(0), 36 | _buffer_overflow(false), 37 | _inverse_logic(inverse_logic) 38 | { 39 | setTX(transmitPin); 40 | setRX(receivePin); 41 | #if defined(BEAN_BEAN_BEAN_H) //// 42 | ////Bean.attachChangeInterrupt(receivePin, SoftwareSerial::handle_interrupt); 43 | attachPinChangeInterrupt(receivePin, SoftwareSerial::handle_interrupt, CHANGE); 44 | #endif //// BEAN_BEAN_BEAN_H 45 | } 46 | */ 47 | 48 | #include 49 | //SoftwareSerial mySerial(2, 3); // RX, TX 50 | BeanSoftwareSerial mySerial(5, 4); // RX, TX 51 | 52 | void setup() 53 | { 54 | // Open serial communications and wait for port to open: 55 | Serial.begin(9600); // Serial.print("Receiving on pin D"); Serial.println(INPUT_CAPTURE_PIN); Serial.print("Transmitting on pin D"); Serial.println(OUTPUT_COMPARE_A_PIN); Serial.print("Unusable for analogWrite / PWM: D"); Serial.println(OUTPUT_COMPARE_B_PIN); 56 | Serial.println("setup"); 57 | 58 | // set the data rate for the SoftwareSerial port 59 | //mySerial.begin(9600); 60 | mySerial.begin(19200); 61 | //mySerial.println("Hello, world?"); 62 | } 63 | 64 | const char version = 'e'; 65 | unsigned long count = 0, count2 = 0, count3 = 0; 66 | 67 | // Convert nibble to hex digit. 68 | static const char nibbleToHex[] = "0123456789abcdef"; 69 | 70 | void loop() // run over and over 71 | { 72 | if (count++ > 5 * 1000 * 1000) { 73 | count = 0; 74 | if (count2++ > 50) { 75 | count2 = 0; 76 | count3++; 77 | Serial.print('\n'); 78 | Serial.print(version); Serial.println(count3); // Serial.print(" / RX D"); Serial.print(INPUT_CAPTURE_PIN); Serial.print(" / TX D"); Serial.print(OUTPUT_COMPARE_A_PIN); Serial.print(" / No PWM D"); Serial.println(OUTPUT_COMPARE_B_PIN); 79 | //mySerial.print(version); mySerial.println(count3); 80 | //mySerial.write((uint8_t) 0xff); // Wake from sleep. 81 | //mySerial.write((uint8_t) 0x00); // Enter command mode. 82 | mySerial.write((uint8_t) '0'); // List all parameters. 83 | //mySerial.write((uint8_t) '1'); // Send mode. 84 | //mySerial.write((uint8_t) '9'); // Read ID. 85 | delay(10); 86 | } 87 | } 88 | if (mySerial.available()) { 89 | int ch = mySerial.read(); 90 | Serial.write((uint8_t) nibbleToHex[ch / 16]); 91 | Serial.write((uint8_t) nibbleToHex[ch % 16]); 92 | Serial.print(' '); 93 | //mySerial.write(ch); 94 | } 95 | //if (Serial.available()) 96 | //mySerial.write(Serial.read()); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /examples/button-sensor/button-sensor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Button 3 | 4 | Turns on and off a light emitting diode(LED) connected to digital 5 | pin 13, when pressing a pushbutton attached to pin 2. 6 | 7 | 8 | The circuit: 9 | * LED attached from pin 13 to ground 10 | * pushbutton attached to pin 2 from +5V 11 | * 10K resistor attached to pin 2 from ground 12 | 13 | * Note: on most Arduinos there is already an LED on the board 14 | attached to pin 13. 15 | 16 | 17 | created 2005 18 | by DojoDave 19 | modified 30 Aug 2011 20 | by Tom Igoe 21 | 22 | This example code is in the public domain. 23 | 24 | http://www.arduino.cc/en/Tutorial/Button 25 | */ 26 | 27 | // constants won't change. They're used here to 28 | // set pin numbers: 29 | const int buttonPin = 6; // the number of the pushbutton pin 30 | const int ledPin = 13; // the number of the LED pin 31 | 32 | // variables will change: 33 | int buttonState = 0; // variable for reading the pushbutton status 34 | 35 | void setup() { 36 | Serial.begin(9600); 37 | 38 | // initialize the LED pin as an output: 39 | pinMode(ledPin, OUTPUT); 40 | // initialize the pushbutton pin as an input: 41 | pinMode(buttonPin, INPUT); 42 | } 43 | 44 | void loop() { 45 | // read the state of the pushbutton value: 46 | buttonState = digitalRead(buttonPin); 47 | 48 | // check if the pushbutton is pressed. 49 | // if it is, the buttonState is HIGH: 50 | if (buttonState == HIGH) { 51 | // turn LED on: 52 | digitalWrite(ledPin, HIGH); 53 | Serial.println("Not pushed"); 54 | } else { 55 | // turn LED off: 56 | digitalWrite(ledPin, LOW); 57 | Serial.println("Pushed"); 58 | } 59 | } 60 | /* 61 | Not pushed 62 | Not pushed 63 | Not pushed 64 | Not pushed 65 | Not pushed 66 | Pushed 67 | Pushed 68 | Pushed 69 | Pushed 70 | Pushed 71 | Pushed 72 | Pushed 73 | Pushed 74 | Pushed 75 | Not pushed 76 | Not pushed 77 | Not pushed 78 | Not pushed 79 | Not pushed 80 | Not pushed 81 | Not pushed 82 | 83 | */ 84 | -------------------------------------------------------------------------------- /examples/downlink/downlink.ino: -------------------------------------------------------------------------------- 1 | // Send sample SIGFOX messages and wait for downlink with UnaBiz UnaShield V2S Arduino Shield. 2 | // This sketch includes diagnostics functions in the UnaShield. 3 | // For a simpler sample sketch, see examples/send-light-level. 4 | #include "SIGFOX.h" 5 | 6 | // IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly. 7 | static const String device = "g88pi"; // Set this to your device name if you're using UnaBiz Emulator. 8 | static const bool useEmulator = false; // Set to true if using UnaBiz Emulator. 9 | static const bool echo = true; // Set to true if the SIGFOX library should display the executed commands. 10 | static const Country country = COUNTRY_SG; // Set this to your country to configure the SIGFOX transmission frequencies. 11 | static UnaShieldV2S transceiver(country, useEmulator, device, echo); // Downlink supported only for UnaShield V2S. 12 | static String response; // Will store the downlink response from SIGFOX. 13 | 14 | void setup() { // Will be called only once. 15 | // Initialize console so we can see debug messages (9600 bits per second). 16 | Serial.begin(9600); Serial.println(F("Running setup...")); 17 | // Check whether the SIGFOX module is functioning. 18 | if (!transceiver.begin()) stop(F("Unable to init SIGFOX module, may be missing")); // Will never return. 19 | 20 | // Send a raw 12-byte message payload to SIGFOX. In the loop() function we will use the Message class, which sends structured messages. 21 | // If you don't wish to wait for downlink response from SIGFOX, call sendMessage() instead. 22 | // Warning: This may delay for about a minute. 23 | transceiver.sendMessageAndGetResponse("0102030405060708090a0b0c", response); 24 | Serial.print(F("Downlink response is ")); Serial.println(response); 25 | 26 | // Delay 10 seconds before sending next message. 27 | Serial.println(F("Waiting 10 seconds...")); 28 | delay(10000); 29 | } 30 | 31 | void loop() { // Will be called repeatedly. 32 | // Send message counter, temperature and voltage as a structured SIGFOX message, up to 10 times. 33 | static int counter = 0, successCount = 0, failCount = 0; // Count messages sent and failed. 34 | Serial.print(F("\nRunning loop #")); Serial.println(counter); 35 | 36 | // Get temperature and voltage of the SIGFOX module. 37 | float temperature; float voltage; 38 | transceiver.getTemperature(temperature); 39 | transceiver.getVoltage(voltage); 40 | 41 | // Convert the numeric counter, temperature and voltage into a compact message with binary fields. 42 | Message msg(transceiver); // Will contain the structured sensor data. 43 | msg.addField("ctr", counter); // 4 bytes for the counter. 44 | msg.addField("tmp", temperature); // 4 bytes for the temperature. 45 | msg.addField("vlt", voltage); // 4 bytes for the voltage. 46 | // Total 12 bytes out of 12 bytes used. 47 | 48 | // Send the message. If you don't wish to wait for downlink response from SIGFOX, call send() instead. 49 | // Warning: This may delay for about a minute. 50 | if (msg.sendAndGetResponse(response)) { 51 | Serial.print(F("Downlink response is ")); Serial.println(response); 52 | successCount++; // If successful, count the message sent successfully. 53 | } else { 54 | failCount++; // If failed, count the message that could not be sent. 55 | } 56 | counter++; 57 | 58 | // Send only 10 messages. 59 | if (counter >= 10) { 60 | // If more than 10 times, display the results and hang here forever. 61 | stop(String(F("Messages sent successfully: ")) + successCount + 62 | F(", failed: ") + failCount); // Will never return. 63 | } 64 | 65 | // Delay 10 seconds before sending next message. 66 | Serial.println("Waiting 10 seconds..."); 67 | delay(10000); 68 | } 69 | 70 | /* Expected output for UnaShield V2S: 71 | 72 | Running setup... 73 | - Disabling emulation mode... 74 | - Checking emulation mode (expecting 0)... 75 | - Getting SIGFOX ID... 76 | - Wisol.sendBuffer: AT$I=10 77 | 78 | >> AT$I=10 79 | << 002C30EB0x0d 80 | - Wisol.sendBuffer: response: 002C30EB 81 | - Wisol.sendBuffer: AT$I=11 82 | 83 | >> AT$I=11 84 | << A8664B5523B5405D0x0d 85 | - Wisol.sendBuffer: response: A8664B5523B5405D 86 | - Wisol.getID: returned id=002C30EB, pac=A8664B5523B5405D 87 | - SIGFOX ID = 002C30EB 88 | - PAC = A8664B5523B5405D 89 | - Wisol.setFrequencySG 90 | - Set frequency result = OK 91 | - Getting frequency (expecting 3)... 92 | - Frequency (expecting 3) = 52 93 | - Wisol.sendMessageAndGetResponse: 002C30EB,0102030405060708090a0b0c 94 | - Wisol.sendBuffer: AT$GI? 95 | 96 | >> AT$GI? 97 | 98 | << 1,5 99 | - Wisol.sendBuffer: response: 1,5 100 | - Wisol.sendBuffer: AT$SF=0102030405060708090a0b0c,1 101 | 102 | >> AT$SF=0102030405060708090a0b0c,1 103 | 104 | << OK0x0d 105 | RX=01 23 45 67 89 AB CD EF 106 | - Wisol.sendBuffer: response: OK 107 | RX=01 23 45 67 89 AB CD EF 108 | OK 109 | RX=01 23 45 67 89 AB CD EF 110 | Downlink response is 0123456789ABCDEF 111 | Waiting 10 seconds... 112 | 113 | Running loop #0 114 | - Wisol.sendBuffer: AT$T? 115 | 116 | >> AT$T? 117 | << 287 118 | - Wisol.sendBuffer: response: 287 119 | - Wisol.getTemperature: returned 28.70 120 | - Wisol.sendBuffer: AT$V? 121 | 122 | >> AT$V? 123 | << 33500x0d 124 | - Wisol.sendBuffer: response: 3350 125 | - Wisol.getVoltage: returned 3.35 126 | - Message.addField: ctr=0 127 | - Message.addField: tmp=287.7 128 | - Message.addField: vlt=33.3 129 | - Wisol.sendMessageAndGetResponse: 002C30EB,920e0000b0511f0194592100 130 | Warning: Should wait 10 mins before sending the next message 131 | - Wisol.sendBuffer: AT$GI? 132 | 133 | >> AT$GI? 134 | 135 | << 1,5 136 | - Wisol.sendBuffer: response: 1,5 137 | - Wisol.sendBuffer: AT$SF=920e0000b0511f0194592100,1 138 | 139 | >> AT$SF=920e0000b0511f0194592100,1 140 | 141 | << OK0x0d 142 | RX=01 23 45 67 89 AB CD EF 143 | - Wisol.sendBuffer: response: OK 144 | RX=01 23 45 67 89 AB CD EF 145 | OK 146 | RX=01 23 45 67 89 AB CD EF 147 | Downlink response is 0123456789ABCDEF 148 | Waiting 10 seconds... 149 | 150 | Running loop #1 151 | - Wisol.sendBuffer: AT$T? 152 | 153 | >> AT$T? 154 | << 290 155 | - Wisol.sendBuffer: response: 290 156 | - Wisol.getTemperature: returned 29.00 157 | - Wisol.sendBuffer: AT$V? 158 | 159 | >> AT$V? 160 | << 33500x0d 161 | - Wisol.sendBuffer: response: 3350 162 | - Wisol.getVoltage: returned 3.35 163 | - Message.addField: ctr=1 164 | - Message.addField: tmp=290.0 165 | - Message.addField: vlt=33.3 166 | - Wisol.sendMessageAndGetResponse: 002C30EB,920e0a00b051220194592100 167 | Warning: Should wait 10 mins before sending the next message 168 | - Wisol.sendBuffer: AT$GI? 169 | 170 | >> AT$GI? 171 | 172 | << 1,5 173 | - Wisol.sendBuffer: response: 1,5 174 | - Wisol.sendBuffer: AT$SF=920e0a00b051220194592100,1 175 | */ 176 | 177 | -------------------------------------------------------------------------------- /examples/grove-sensor/grove-sensor.ino: -------------------------------------------------------------------------------- 1 | /* Grove - Light Sensor demo v1.0 2 | * 3 | * Signal wire to A0. 4 | * By: http://www.seeedstudio.com 5 | */ 6 | #include 7 | 8 | #define LIGHT_SENSOR A3 //Grove - Light Sensor is connected to A3 of Arduino 9 | //const int ledPin=12; //Connect the LED Grove module to Pin12, Digital 12 10 | const int ledPin=13; //Use onboard LED. 11 | const int thresholdvalue=10; //The treshold for which the LED should turn on. Setting it lower will make it go on at more light, higher for more darkness 12 | float Rsensor; //Resistance of sensor in K 13 | void setup() 14 | { 15 | Serial.begin(9600); //Start the Serial connection 16 | pinMode(ledPin,OUTPUT); //Set the LED on Digital 12 as an OUTPUT 17 | } 18 | void loop() 19 | { 20 | int sensorValue = analogRead(LIGHT_SENSOR); 21 | Rsensor = (float)(1023-sensorValue)*10/sensorValue; 22 | Serial.print("the analog read data is "); 23 | Serial.print(sensorValue); 24 | Serial.print(" / the sensor resistance is "); 25 | Serial.println(Rsensor,DEC);//show the ligth intensity on the serial monitor; 26 | } 27 | /* 28 | he analog read data is 950 / the sensor resistance is 0.7684210777 29 | the analog read data is 948 / the sensor resistance is 0.7911392211 30 | the analog read data is 953 / the sensor resistance is 0.7345225811 31 | the analog read data is 955 / the sensor resistance is 0.7120419025 32 | the analog read data is 955 / the sensor resistance is 0.7120419025 33 | the analog read data is 951 / the sensor resistance is 0.7570977687 34 | the analog read data is 951 / the sensor resistance is 0.7570977687 35 | the analog read data is 955 / the sensor resistance is 0.7120419025 36 | the analog read data is 960 / the sensor resistance is 0.6562500000 37 | the analog read data is 375 / the sensor resistance is 17.2800006866 38 | the analog read data is 360 / the sensor resistance is 18.4166660308 39 | the analog read data is 343 / the sensor resistance is 19.8250732421 40 | the analog read data is 311 / the sensor resistance is 22.8938903808 41 | the analog read data is 276 / the sensor resistance is 27.0652179718 42 | the analog read data is 236 / the sensor resistance is 33.3474578857 43 | the analog read data is 197 / the sensor resistance is 41.9289321899 44 | the analog read data is 173 / the sensor resistance is 49.1329498291 45 | the analog read data is 193 / the sensor resistance is 43.0051803588 46 | the analog read data is 219 / the sensor resistance is 36.7123298645 47 | the analog read data is 212 / the sensor resistance is 38.2547187805 48 | the analog read data is 215 / the sensor resistance is 37.5813941955 49 | the analog read data is 215 / the sensor resistance is 37.5813941955 50 | the analog read data is 202 / the sensor resistance is 40.6435661315 51 | the analog read data is 196 / the sensor resistance is 42.1938781738 52 | the analog read data is 196 / the sensor resistance is 42.1938781738 53 | the analog read data is 192 / the sensor resistance is 43.2812500000 54 | the analog read data is 175 / the sensor resistance is 48.4571418762 55 | the analog read data is 175 / the sensor resistance is 48.4571418762 56 | the analog read data is 177 / the sensor resistance is 47.7966117858 57 | the analog read data is 177 / the sensor resistance is 47.7966117858 58 | the analog read data is 178 / the sensor resistance is 47.4719085693 59 | the analog read data is 180 / the sensor resistance is 46.8333320617 60 | the analog read data is 177 / the sensor resistance is 47.7966117858 61 | the analog read data is 172 / the sensor resistance is 49.4767456054 62 | the analog read data is 174 / the sensor resistance is 48.7931022644 63 | the analog read data is 177 / the sensor resistance is 47.7966117858 64 | the analog read data is 170 / the sensor resistance is 50.1764717102 65 | the analog read data is 166 / the sensor resistance is 51.6265068054 66 | the analog read data is 168 / the sensor resistance is 50.8928565979 67 | the analog read data is 165 / the sensor resistance is 52.0000000000 68 | the analog read data is 182 / the sensor resistance is 46.2087898254 69 | the analog read data is 311 / the sensor resistance is 22.8938903808 70 | the analog read data is 890 / the sensor resistance is 1.4943819999 71 | the analog read data is 941 / the sensor resistance is 0.8714134216 72 | the analog read data is 947 / the sensor resistance is 0.8025342941 73 | the analog read data is 942 / the sensor resistance is 0.8598726272 74 | the analog read data is 927 / the sensor resistance is 1.0355987548 75 | the analog read data is 915 / the sensor resistance is 1.1803278923 76 | the analog read data is 925 / the sensor resistance is 1.0594594478 77 | the analog read data is 941 / the sensor resistance is 0.8714134216 78 | the analog read data is 944 / the sensor resistance is 0.8368643760 79 | the analog read data is 939 / the sensor resistance is 0.8945686340 80 | the analog read data is 924 / the sensor resistance is 1.0714285373 81 | the analog read data is 920 / the sensor resistance is 1.1195652484 82 | the analog read data is 936 / the sensor resistance is 0.9294871330 83 | the analog read data is 945 / the sensor resistance is 0.8253968238 84 | the analog read data is 944 / the sensor resistance is 0.8368643760 85 | the analog read data is 933 / the sensor resistance is 0.9646302223 86 | the analog read data is 921 / the sensor resistance is 1.1074918508 87 | the analog read data is 930 / the sensor resistance is 1.0000000000 88 | */ 89 | -------------------------------------------------------------------------------- /examples/multiple_inputs/Fsm.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of arduino-fsm. 2 | // 3 | // arduino-fsm is free software: you can redistribute it and/or modify it under 4 | // the terms of the GNU Lesser General Public License as published by the Free 5 | // Software Foundation, either version 3 of the License, or (at your option) 6 | // any later version. 7 | // 8 | // arduino-fsm is distributed in the hope that it will be useful, but WITHOUT 9 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 11 | // for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public License 14 | // along with arduino-fsm. If not, see . 15 | 16 | #include "Fsm.h" 17 | 18 | 19 | State::State(void (*on_enter)(), void (*on_state)(), void (*on_exit)()) 20 | : on_enter(on_enter), 21 | on_state(on_state), 22 | on_exit(on_exit) 23 | { 24 | } 25 | 26 | 27 | Fsm::Fsm(State* initial_state) 28 | : m_current_state(initial_state), 29 | m_transitions(NULL), 30 | m_num_transitions(0), 31 | m_num_timed_transitions(0), 32 | m_initialized(false) 33 | { 34 | } 35 | 36 | 37 | Fsm::~Fsm() 38 | { 39 | free(m_transitions); 40 | free(m_timed_transitions); 41 | m_transitions = NULL; 42 | m_timed_transitions = NULL; 43 | } 44 | 45 | 46 | void Fsm::add_transition(State* state_from, State* state_to, int event, 47 | void (*on_transition)()) 48 | { 49 | if (state_from == NULL || state_to == NULL) 50 | return; 51 | 52 | Transition transition = Fsm::create_transition(state_from, state_to, event, 53 | on_transition); 54 | m_transitions = (Transition*) realloc(m_transitions, (m_num_transitions + 1) 55 | * sizeof(Transition)); 56 | m_transitions[m_num_transitions] = transition; 57 | m_num_transitions++; 58 | } 59 | 60 | 61 | void Fsm::add_timed_transition(State* state_from, State* state_to, 62 | unsigned long interval, void (*on_transition)()) 63 | { 64 | if (state_from == NULL || state_to == NULL) 65 | return; 66 | 67 | Transition transition = Fsm::create_transition(state_from, state_to, 0, 68 | on_transition); 69 | 70 | TimedTransition timed_transition; 71 | timed_transition.transition = transition; 72 | timed_transition.start = 0; 73 | timed_transition.interval = interval; 74 | 75 | m_timed_transitions = (TimedTransition*) realloc( 76 | m_timed_transitions, (m_num_timed_transitions + 1) * sizeof(TimedTransition)); 77 | m_timed_transitions[m_num_timed_transitions] = timed_transition; 78 | m_num_timed_transitions++; 79 | } 80 | 81 | 82 | Fsm::Transition Fsm::create_transition(State* state_from, State* state_to, 83 | int event, void (*on_transition)()) 84 | { 85 | Transition t; 86 | t.state_from = state_from; 87 | t.state_to = state_to; 88 | t.event = event; 89 | t.on_transition = on_transition; 90 | 91 | return t; 92 | } 93 | 94 | void Fsm::trigger(int event) 95 | { 96 | if (m_initialized) 97 | { 98 | // Find the transition with the current state and given event. 99 | for (int i = 0; i < m_num_transitions; ++i) 100 | { 101 | if (m_transitions[i].state_from == m_current_state && 102 | m_transitions[i].event == event) 103 | { 104 | Fsm::make_transition(&(m_transitions[i])); 105 | return; 106 | } 107 | } 108 | } 109 | } 110 | 111 | void Fsm::check_timed_transitions() 112 | { 113 | for (int i = 0; i < m_num_timed_transitions; ++i) 114 | { 115 | TimedTransition* transition = &m_timed_transitions[i]; 116 | if (transition->transition.state_from == m_current_state) 117 | { 118 | if (transition->start == 0) 119 | { 120 | transition->start = millis(); 121 | } 122 | else{ 123 | unsigned long now = millis(); 124 | if (now - transition->start >= transition->interval) 125 | { 126 | Fsm::make_transition(&(transition->transition)); 127 | transition->start = 0; 128 | } 129 | } 130 | } 131 | } 132 | } 133 | 134 | void Fsm::run_machine() 135 | { 136 | // first run must exec first state "on_enter" 137 | if (!m_initialized) 138 | { 139 | m_initialized = true; 140 | if (m_current_state->on_enter != NULL) 141 | m_current_state->on_enter(); 142 | } 143 | 144 | if (m_current_state->on_state != NULL) 145 | m_current_state->on_state(); 146 | 147 | Fsm::check_timed_transitions(); 148 | } 149 | 150 | void Fsm::make_transition(Transition* transition) 151 | { 152 | 153 | // Execute the handlers in the correct order. 154 | if (transition->state_from->on_exit != NULL) 155 | transition->state_from->on_exit(); 156 | 157 | if (transition->on_transition != NULL) 158 | transition->on_transition(); 159 | 160 | if (transition->state_to->on_enter != NULL) 161 | transition->state_to->on_enter(); 162 | 163 | m_current_state = transition->state_to; 164 | 165 | //Initialice all timed transitions from m_current_state 166 | unsigned long now = millis(); 167 | for (int i = 0; i < m_num_timed_transitions; ++i) 168 | { 169 | TimedTransition* ttransition = &m_timed_transitions[i]; 170 | if (ttransition->transition.state_from == m_current_state) 171 | ttransition->start = now; 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /examples/multiple_inputs/Fsm.h: -------------------------------------------------------------------------------- 1 | // This file is part of arduino-fsm. 2 | // 3 | // arduino-fsm is free software: you can redistribute it and/or modify it under 4 | // the terms of the GNU Lesser General Public License as published by the Free 5 | // Software Foundation, either version 3 of the License, or (at your option) 6 | // any later version. 7 | // 8 | // arduino-fsm is distributed in the hope that it will be useful, but WITHOUT 9 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 11 | // for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public License 14 | // along with arduino-fsm. If not, see . 15 | 16 | #ifndef FSM_H 17 | #define FSM_H 18 | 19 | 20 | #if defined(ARDUINO) && ARDUINO >= 100 21 | #include 22 | #else 23 | #include 24 | #endif 25 | 26 | 27 | struct State 28 | { 29 | State(void (*on_enter)(), void (*on_state)(), void (*on_exit)()); 30 | void (*on_enter)(); 31 | void (*on_state)(); 32 | void (*on_exit)(); 33 | }; 34 | 35 | 36 | class Fsm 37 | { 38 | public: 39 | Fsm(State* initial_state); 40 | ~Fsm(); 41 | 42 | void add_transition(State* state_from, State* state_to, int event, 43 | void (*on_transition)()); 44 | 45 | void add_timed_transition(State* state_from, State* state_to, 46 | unsigned long interval, void (*on_transition)()); 47 | 48 | void check_timed_transitions(); 49 | 50 | void trigger(int event); 51 | void run_machine(); 52 | 53 | private: 54 | struct Transition 55 | { 56 | State* state_from; 57 | State* state_to; 58 | int event; 59 | void (*on_transition)(); 60 | 61 | }; 62 | struct TimedTransition 63 | { 64 | Transition transition; 65 | unsigned long start; 66 | unsigned long interval; 67 | }; 68 | 69 | static Transition create_transition(State* state_from, State* state_to, 70 | int event, void (*on_transition)()); 71 | 72 | void make_transition(Transition* transition); 73 | 74 | private: 75 | State* m_current_state; 76 | Transition* m_transitions; 77 | int m_num_transitions; 78 | 79 | TimedTransition* m_timed_transitions; 80 | int m_num_timed_transitions; 81 | bool m_initialized; 82 | }; 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /examples/multiple_inputs/finite_state_machine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBiz/unabiz-arduino/b8cc57137b5debd4f29432e41d6924aa2cf9f474/examples/multiple_inputs/finite_state_machine.png -------------------------------------------------------------------------------- /examples/multiple_inputs/graphviz.dot: -------------------------------------------------------------------------------- 1 | digraph finite_state_machine { 2 | rankdir=LR; 3 | size="80,50" 4 | node [shape = doublecircle]; input1Idle input2Idle input3Idle transceiverIdle; 5 | node [shape = circle]; 6 | 7 | input1Idle -> input1Sending [ label = "INPUT_CHANGED" ]; 8 | input1Sending -> input1Idle [ label = "INPUT_SENT" ]; 9 | input1Idle -> input1Idle [ label = "INPUT_SENT" ]; 10 | 11 | input2Idle -> input2Sending [ label = "INPUT_CHANGED" ]; 12 | input2Sending -> input2Idle [ label = "INPUT_SENT" ]; 13 | input2Idle -> input2Idle [ label = "INPUT_SENT" ]; 14 | 15 | input3Idle -> input3Sending [ label = "INPUT_CHANGED" ]; 16 | input3Sending -> input3Idle [ label = "INPUT_SENT" ]; 17 | input3Idle -> input3Idle [ label = "INPUT_SENT" ]; 18 | 19 | transceiverIdle -> transceiverSending [ label = "INPUT_CHANGED" ]; 20 | transceiverSending -> transceiverSending [ label = "INPUT_CHANGED / scheduleResend" ]; 21 | transceiverSending -> transceiverSent [ label = "INPUT_SENT" ]; 22 | transceiverSent -> transceiverSent [ label = "INPUT_CHANGED / scheduleResend" ]; 23 | transceiverSent -> transceiverIdle [ label = "After 2.1 seconds" ]; 24 | transceiverIdle -> transceiverSending [ label = "After 30 seconds" ]; 25 | } 26 | -------------------------------------------------------------------------------- /examples/read-light-level/read-light-level.ino: -------------------------------------------------------------------------------- 1 | // Read data from the light sensor. 2 | // This code assumes that you are using the Grove Light Sensor v1.1: 3 | // http://wiki.seeed.cc/Grove-Light_Sensor/ 4 | // 5 | // Instructions and code based on: https://github.com/Seeed-Studio/Light_Sensor/blob/master/examples/Light_Sensor/Light_Sensor.ino 6 | // Connect the Grove Light Sensor to the Arduino as follows: 7 | // Grove Light Sensor GND (Black Wire) --> Arduino GND 8 | // Grove Light Sensor VCC (Red Wire) --> Arduino 5V 9 | // Grove Light Sensor SIG (Yellow Wire) --> Arduino A0 10 | 11 | //////////////////////////////////////////////////////////// 12 | // Begin Sensor Declaration 13 | // Don't use ports D0, D1: Reserved for viewing debug output through Arduino Serial Monitor 14 | // Don't use ports D4, D5: Reserved for serial comms with the SIGFOX module. 15 | 16 | #ifdef BEAN_BEAN_BEAN_H 17 | #define LIGHT_SENSOR A2 // For Bean+, Grove Light Sensor is connected to port A2. 18 | #else 19 | #define LIGHT_SENSOR A0 // Else Grove Light Sensor is connected to port A0. 20 | #endif // BEAN_BEAN_BEAN_H 21 | 22 | // End Sensor Declaration 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Begin SIGFOX Module Declaration 27 | 28 | // End SIGFOX Module Declaration 29 | //////////////////////////////////////////////////////////// 30 | 31 | void setup() { // Will be called only once. 32 | //////////////////////////////////////////////////////////// 33 | // Begin General Setup 34 | 35 | // Initialize console so we can see debug messages (9600 bits per second). 36 | Serial.begin(9600); Serial.println(F("Running setup...")); 37 | 38 | // End General Setup 39 | //////////////////////////////////////////////////////////// 40 | 41 | //////////////////////////////////////////////////////////// 42 | // Begin Sensor Setup 43 | 44 | // No setup needed for light sensor. 45 | 46 | // End Sensor Setup 47 | //////////////////////////////////////////////////////////// 48 | 49 | //////////////////////////////////////////////////////////// 50 | // Begin SIGFOX Module Setup 51 | 52 | // End SIGFOX Module Setup 53 | //////////////////////////////////////////////////////////// 54 | } 55 | 56 | void loop() { // Will be called repeatedly. 57 | //////////////////////////////////////////////////////////// 58 | // Begin Sensor Loop 59 | 60 | // Read the light sensor from the analog port. 61 | int light_level = analogRead(LIGHT_SENSOR); 62 | Serial.print(F("light_level=")); Serial.println(light_level); 63 | 64 | // End Sensor Loop 65 | //////////////////////////////////////////////////////////// 66 | 67 | //////////////////////////////////////////////////////////// 68 | // Begin SIGFOX Module Loop 69 | 70 | // End SIGFOX Module Loop 71 | //////////////////////////////////////////////////////////// 72 | 73 | // Wait a while before looping. 10000 milliseconds = 10 seconds. 74 | Serial.println(F("Waiting 10 seconds...")); 75 | delay(10000); 76 | } 77 | 78 | /* 79 | Expected output: 80 | 81 | Running setup... 82 | light_level=51 83 | Waiting 10 seconds... 84 | light_level=50 85 | Waiting 10 seconds... 86 | light_level=780 87 | Waiting 10 seconds... 88 | light_level=781 89 | Waiting 10 seconds... 90 | light_level=50 91 | Waiting 10 seconds... 92 | light_level=50 93 | Waiting 10 seconds... 94 | */ 95 | -------------------------------------------------------------------------------- /examples/read-temperature/read-temperature.ino: -------------------------------------------------------------------------------- 1 | // Read data from the temperature sensor. 2 | // This code assumes that you are using the Grove DHT Sensor Pro: 3 | // http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro 4 | // 5 | // You can easily adapt the code for other Grove temperature sensors: 6 | // http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_Sensor 7 | // http://wiki.seeedstudio.com/wiki/Grove_-_Tempture&Humidity_Sensor_(High-Accuracy_&Mini)_v1.0 8 | // 9 | // Instructions and code based on: http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro 10 | // 1. Connect the Temperature and Humidity Sensor Pro to Port D2 of Grove - Base Shield 11 | // 2. Download and install Seeed DHT Library: https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor 12 | // 3. Make sure the voltage on the Grove Shield matches the voltage on the Arduino board. 13 | 14 | //////////////////////////////////////////////////////////// 15 | // Begin Sensor Declaration 16 | 17 | #include "DHT.h" // From https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor 18 | 19 | #define DHTPIN 2 // UnaBiz: what pin we're connected to. 2 means Port D2. 20 | 21 | // Uncomment whatever type you're using! 22 | #define DHTTYPE DHT11 // DHT 11 23 | //#define DHTTYPE DHT22 // DHT 22 (AM2302) 24 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 25 | 26 | DHT dht(DHTPIN, DHTTYPE); 27 | 28 | // End Sensor Declaration 29 | //////////////////////////////////////////////////////////// 30 | 31 | //////////////////////////////////////////////////////////// 32 | // Begin SIGFOX Module Declaration 33 | 34 | // End SIGFOX Module Declaration 35 | //////////////////////////////////////////////////////////// 36 | 37 | void setup() 38 | { 39 | //////////////////////////////////////////////////////////// 40 | // Begin General Setup 41 | 42 | // Initialize console serial communication at 9600 bits per second: 43 | Serial.begin(9600); 44 | Serial.println(F("Demo sketch for reading temperature sensor values :)")); 45 | 46 | // End General Setup 47 | //////////////////////////////////////////////////////////// 48 | 49 | //////////////////////////////////////////////////////////// 50 | // Begin Sensor Setup 51 | 52 | dht.begin(); 53 | 54 | // End Sensor Setup 55 | //////////////////////////////////////////////////////////// 56 | 57 | //////////////////////////////////////////////////////////// 58 | // Begin SIGFOX Module Setup 59 | 60 | // End SIGFOX Module Setup 61 | //////////////////////////////////////////////////////////// 62 | } 63 | 64 | void loop() 65 | { 66 | //////////////////////////////////////////////////////////// 67 | // Begin Sensor Loop 68 | 69 | // Reading temperature or humidity takes about 250 milliseconds! 70 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 71 | float t = dht.readTemperature(); 72 | float h = dht.readHumidity(); 73 | String msg = ""; // Will contain the sensor data. 74 | 75 | // Check if returns are valid, if they are NaN (not a number) then something went wrong! 76 | if (isnan(t) || isnan(h)) { 77 | Serial.println("Failed to read from sensor"); 78 | msg = "error"; 79 | } else { 80 | Serial.println("Temperature:"); 81 | Serial.println(t); 82 | 83 | Serial.println("Humidity:"); 84 | Serial.println(h); 85 | 86 | // Convert the numeric temperature and humidity to text strings, 0 decimal places. 87 | // Concatenate them with field names, separated by comma. e.g.: 88 | // t:28,h:44 89 | msg = 90 | "t:" + String(t, 0) + "," + 91 | "h:" + String(h, 0); 92 | } 93 | Serial.println("msg:"); 94 | Serial.println(msg); 95 | 96 | // End Sensor Loop 97 | //////////////////////////////////////////////////////////// 98 | 99 | //////////////////////////////////////////////////////////// 100 | // Begin SIGFOX Module Loop 101 | 102 | // End SIGFOX Module Loop 103 | //////////////////////////////////////////////////////////// 104 | 105 | // Wait a while before looping. 10000 milliseconds = 10 seconds. 106 | delay(10000); 107 | } 108 | 109 | /* 110 | Expected output: 111 | 112 | DHTxx test! 113 | Temperature: 114 | 28.00 115 | Humidity: 116 | 44.00 117 | msg: 118 | t:28,h:44 119 | Temperature: 120 | 28.00 121 | Humidity: 122 | 44.00 123 | msg: 124 | t:28,h:44 125 | Temperature: 126 | 28.00 127 | Humidity: 128 | 44.00 129 | msg: 130 | t:28,h:44 131 | */ 132 | -------------------------------------------------------------------------------- /examples/send-altitude-structured/Adafruit_BME280.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | This is a library for the BME280 humidity, temperature & pressure sensor 3 | 4 | Designed specifically to work with the Adafruit BME280 Breakout 5 | ----> http://www.adafruit.com/products/2650 6 | 7 | These sensors use I2C or SPI to communicate, 2 or 4 pins are required 8 | to interface. 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit andopen-source hardware by purchasing products 12 | from Adafruit! 13 | 14 | Written by Limor Fried & Kevin Townsend for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ***************************************************************************/ 17 | #ifndef __BME280_H__ 18 | #define __BME280_H__ 19 | 20 | #if (ARDUINO >= 100) 21 | #include "Arduino.h" 22 | #else 23 | #include "WProgram.h" 24 | #endif 25 | 26 | #include "Adafruit_Sensor.h" 27 | #include 28 | 29 | /*========================================================================= 30 | I2C ADDRESS/BITS 31 | -----------------------------------------------------------------------*/ 32 | #define BME280_ADDRESS (0x77) 33 | /*=========================================================================*/ 34 | 35 | /*========================================================================= 36 | REGISTERS 37 | -----------------------------------------------------------------------*/ 38 | enum 39 | { 40 | BME280_REGISTER_DIG_T1 = 0x88, 41 | BME280_REGISTER_DIG_T2 = 0x8A, 42 | BME280_REGISTER_DIG_T3 = 0x8C, 43 | 44 | BME280_REGISTER_DIG_P1 = 0x8E, 45 | BME280_REGISTER_DIG_P2 = 0x90, 46 | BME280_REGISTER_DIG_P3 = 0x92, 47 | BME280_REGISTER_DIG_P4 = 0x94, 48 | BME280_REGISTER_DIG_P5 = 0x96, 49 | BME280_REGISTER_DIG_P6 = 0x98, 50 | BME280_REGISTER_DIG_P7 = 0x9A, 51 | BME280_REGISTER_DIG_P8 = 0x9C, 52 | BME280_REGISTER_DIG_P9 = 0x9E, 53 | 54 | BME280_REGISTER_DIG_H1 = 0xA1, 55 | BME280_REGISTER_DIG_H2 = 0xE1, 56 | BME280_REGISTER_DIG_H3 = 0xE3, 57 | BME280_REGISTER_DIG_H4 = 0xE4, 58 | BME280_REGISTER_DIG_H5 = 0xE5, 59 | BME280_REGISTER_DIG_H6 = 0xE7, 60 | 61 | BME280_REGISTER_CHIPID = 0xD0, 62 | BME280_REGISTER_VERSION = 0xD1, 63 | BME280_REGISTER_SOFTRESET = 0xE0, 64 | 65 | BME280_REGISTER_CAL26 = 0xE1, // R calibration stored in 0xE1-0xF0 66 | 67 | BME280_REGISTER_CONTROLHUMID = 0xF2, 68 | BME280_REGISTER_CONTROL = 0xF4, 69 | BME280_REGISTER_CONFIG = 0xF5, 70 | BME280_REGISTER_PRESSUREDATA = 0xF7, 71 | BME280_REGISTER_TEMPDATA = 0xFA, 72 | BME280_REGISTER_HUMIDDATA = 0xFD, 73 | }; 74 | 75 | /*=========================================================================*/ 76 | 77 | /*========================================================================= 78 | CALIBRATION DATA 79 | -----------------------------------------------------------------------*/ 80 | typedef struct 81 | { 82 | uint16_t dig_T1; 83 | int16_t dig_T2; 84 | int16_t dig_T3; 85 | 86 | uint16_t dig_P1; 87 | int16_t dig_P2; 88 | int16_t dig_P3; 89 | int16_t dig_P4; 90 | int16_t dig_P5; 91 | int16_t dig_P6; 92 | int16_t dig_P7; 93 | int16_t dig_P8; 94 | int16_t dig_P9; 95 | 96 | uint8_t dig_H1; 97 | int16_t dig_H2; 98 | uint8_t dig_H3; 99 | int16_t dig_H4; 100 | int16_t dig_H5; 101 | int8_t dig_H6; 102 | } bme280_calib_data; 103 | /*=========================================================================*/ 104 | 105 | /* 106 | class Adafruit_BME280_Unified : public Adafruit_Sensor 107 | { 108 | public: 109 | Adafruit_BME280_Unified(int32_t sensorID = -1); 110 | 111 | bool begin(uint8_t addr = BME280_ADDRESS); 112 | void getTemperature(float *temp); 113 | void getPressure(float *pressure); 114 | float pressureToAltitude(float seaLevel, float atmospheric, float temp); 115 | float seaLevelForAltitude(float altitude, float atmospheric, float temp); 116 | void getEvent(sensors_event_t*); 117 | void getSensor(sensor_t*); 118 | 119 | private: 120 | uint8_t _i2c_addr; 121 | int32_t _sensorID; 122 | }; 123 | 124 | */ 125 | 126 | class Adafruit_BME280 127 | { 128 | public: 129 | Adafruit_BME280(void); 130 | Adafruit_BME280(int8_t cspin); 131 | Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin); 132 | 133 | bool begin(uint8_t addr = BME280_ADDRESS); 134 | float readTemperature(void); 135 | float readPressure(void); 136 | float readHumidity(void); 137 | float readAltitude(float seaLevel); 138 | float seaLevelForAltitude(float altitude, float atmospheric); 139 | 140 | private: 141 | 142 | void readCoefficients(void); 143 | uint8_t spixfer(uint8_t x); 144 | 145 | void write8(byte reg, byte value); 146 | uint8_t read8(byte reg); 147 | uint16_t read16(byte reg); 148 | uint32_t read24(byte reg); 149 | int16_t readS16(byte reg); 150 | uint16_t read16_LE(byte reg); // little endian 151 | int16_t readS16_LE(byte reg); // little endian 152 | 153 | uint8_t _i2caddr; 154 | int32_t _sensorID; 155 | int32_t t_fine; 156 | 157 | int8_t _cs, _mosi, _miso, _sck; 158 | 159 | bme280_calib_data _bme280_calib; 160 | 161 | }; 162 | 163 | #endif 164 | -------------------------------------------------------------------------------- /examples/send-altitude-structured/Adafruit_Sensor.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBiz/unabiz-arduino/b8cc57137b5debd4f29432e41d6924aa2cf9f474/examples/send-altitude-structured/Adafruit_Sensor.h -------------------------------------------------------------------------------- /examples/send-altitude-structured/send-altitude-structured.ino: -------------------------------------------------------------------------------- 1 | // Send sensor data from the onboard temperature, humudity, barometer sensors 2 | // as a SIGFOX message, using the UnaBiz UnaShield V2S Arduino Shield. 3 | // The Arduino Uno onboard LED will flash every few seconds when the sketch is running properly. 4 | // The data is sent in the Structured Message Format, which requires a decoding function in the receiving cloud. 5 | 6 | //////////////////////////////////////////////////////////// 7 | // Begin Sensor Declaration 8 | // Don't use ports D0, D1: Reserved for viewing debug output through Arduino Serial Monitor 9 | // Don't use ports D4, D5: Reserved for serial comms with the SIGFOX module. 10 | 11 | /*************************************************************************** 12 | This is a library for the BME280 humidity, temperature & pressure sensor 13 | Mike Nguyen (Vinova) Mike Nguyen (Vinova) 14 | Designed specifically to work with the Adafruit BME280 Breakout 15 | ----> http://www.adafruit.com/products/2650 16 | 17 | These sensors use I2C or SPI to communicate, 2 or 4 pins are required 18 | to interface. 19 | 20 | Adafruit invests time and resources providing this open source code, 21 | please support Adafruit andopen-source hardware by purchasing products 22 | from Adafruit! 23 | 24 | Written by Limor Fried & Kevin Townsend for Adafruit Industries. 25 | BSD license, all text above must be included in any redistribution 26 | ***************************************************************************/ 27 | 28 | #include 29 | #include 30 | #include "Adafruit_Sensor.h" 31 | #include "Adafruit_BME280.h" 32 | 33 | #define BME_SCK 13 34 | #define BME_MISO 12 35 | #define BME_MOSI 11 36 | #define BME_CS 10 37 | 38 | #define SEALEVELPRESSURE_HPA (1013.25) 39 | 40 | Adafruit_BME280 bme; // I2C 41 | 42 | // End Sensor Declaration 43 | //////////////////////////////////////////////////////////// 44 | 45 | //////////////////////////////////////////////////////////// 46 | // Begin SIGFOX Module Declaration 47 | 48 | #include "SIGFOX.h" 49 | 50 | // IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly. 51 | static const String device = ""; // Set this to your device name if you're using SIGFOX Emulator. 52 | static const bool useEmulator = false; // Set to true if using SIGFOX Emulator. 53 | static const bool echo = true; // Set to true if the SIGFOX library should display the executed commands. 54 | static const Country country = COUNTRY_SG; // Set this to your country to configure the SIGFOX transmission frequencies. 55 | static UnaShieldV2S transceiver(country, useEmulator, device, echo); // Assumes you are using UnaBiz UnaShield V2S Dev Kit 56 | 57 | // End SIGFOX Module Declaration 58 | //////////////////////////////////////////////////////////// 59 | 60 | void setup() { // Will be called only once. 61 | //////////////////////////////////////////////////////////// 62 | // Begin General Setup 63 | 64 | // Initialize console so we can see debug messages (9600 bits per second). 65 | Serial.begin(9600); Serial.println(F("Running setup...")); 66 | 67 | // Initialize the onboard LED at D13 for output. 68 | pinMode(LED_BUILTIN, OUTPUT); 69 | 70 | // End General Setup 71 | //////////////////////////////////////////////////////////// 72 | 73 | //////////////////////////////////////////////////////////// 74 | // Begin Sensor Setup 75 | 76 | if (!bme.begin(0x76)) stop("Bosch BME280 sensor missing"); // Will never return. 77 | 78 | // End Sensor Setup 79 | //////////////////////////////////////////////////////////// 80 | 81 | //////////////////////////////////////////////////////////// 82 | // Begin SIGFOX Module Setup 83 | 84 | // Check whether the SIGFOX module is functioning. 85 | if (!transceiver.begin()) stop("Unable to init SIGFOX module, may be missing"); // Will never return. 86 | 87 | // End SIGFOX Module Setup 88 | //////////////////////////////////////////////////////////// 89 | } 90 | 91 | void loop() { // Will be called repeatedly. 92 | //////////////////////////////////////////////////////////// 93 | // Begin Sensor Loop 94 | 95 | // Read the ambient temperature, humidity, air pressure. 96 | float filteredTemp = bme.readTemperature(); 97 | float filteredPressure = bme.readPressure() / 100.0F; 98 | float filteredAltitude = bme.readAltitude(SEALEVELPRESSURE_HPA); 99 | float humidity = bme.readHumidity(); 100 | 101 | // Get temperature of the SIGFOX module. 102 | float moduleTemp; transceiver.getTemperature(moduleTemp); 103 | 104 | // Optional: We may scale the values by 100 so we can have 2 decimal places of precision. 105 | // For now we don't scale the values. 106 | float scaledTemp = filteredTemp * 1.0; 107 | float scaledHumidity = humidity * 1.0; 108 | float scaledAltitude = filteredAltitude * 1.0; 109 | float scaledModuleTemp = moduleTemp * 1.0; 110 | 111 | Serial.print("scaledTemp = "); Serial.print(scaledTemp); Serial.println(" degrees C"); 112 | Serial.print("scaledHumidity = "); Serial.print(scaledHumidity); Serial.println(" %"); 113 | Serial.print("scaledAltitude = "); Serial.print(scaledAltitude); Serial.println(" metres above sea level"); 114 | Serial.print("scaledModuleTemp = "); Serial.print(scaledModuleTemp); Serial.println(" degrees C"); 115 | 116 | // End Sensor Loop 117 | //////////////////////////////////////////////////////////// 118 | 119 | //////////////////////////////////////////////////////////// 120 | // Begin SIGFOX Module Loop 121 | 122 | // Send temperature, pressure, altitude as a SIGFOX message. 123 | static int counter = 0, successCount = 0, failCount = 0; // Count messages sent and failed. 124 | Serial.print(F("\nRunning loop #")); Serial.println(counter); 125 | 126 | // Compose the Structured Message contain field names and values, total 12 bytes. 127 | // This requires a decoding function in the receiving cloud (e.g. Google Cloud) to decode the message. 128 | // If you wish to use Sigfox Custom Payload format, look at the sample sketch "send-altitude". 129 | Message msg(transceiver); // Will contain the structured sensor data. 130 | msg.addField("tmp", scaledTemp); // 4 bytes for the temperature (1 decimal place). 131 | msg.addField("hmd", scaledHumidity); // 4 bytes for the humidity (1 decimal place). 132 | msg.addField("alt", scaledAltitude); // 4 bytes for the altitude (1 decimal place). 133 | // Total 12 bytes out of 12 bytes used. 134 | 135 | // Send the encoded structured message. 136 | if (msg.send()) { 137 | successCount++; // If successful, count the message sent successfully. 138 | } else { 139 | failCount++; // If failed, count the message that could not be sent. 140 | } 141 | counter++; 142 | 143 | // Flash the LED on and off at every iteration so we know the sketch is still running. 144 | if (counter % 2 == 0) { 145 | digitalWrite(LED_BUILTIN, HIGH); // Turn the LED on (HIGH is the voltage level). 146 | } else { 147 | digitalWrite(LED_BUILTIN, LOW); // Turn the LED off (LOW is the voltage level). 148 | } 149 | 150 | // Show updates every 10 messages. 151 | if (counter % 10 == 0) { 152 | Serial.print(F("Messages sent successfully: ")); Serial.print(successCount); 153 | Serial.print(F(", failed: ")); Serial.println(failCount); 154 | } 155 | 156 | // End SIGFOX Module Loop 157 | //////////////////////////////////////////////////////////// 158 | 159 | // Wait a while before looping. 10000 milliseconds = 10 seconds. 160 | Serial.println(F("Waiting 10 seconds...")); 161 | delay(10000); 162 | } 163 | /* Expected Output: 164 | Running setup... 165 | - Disabling SNEK emulation mode... 166 | - Wisol.sendBuffer: ATS410=0 167 | 168 | >> ATS410=0 169 | << OK0x0d 170 | - Wisol.sendBuffer: response: OK 171 | - Getting SIGFOX ID... 172 | - Wisol.sendBuffer: AT$I=10 173 | 174 | >> AT$I=10 175 | << 002C30EB0x0d 176 | - Wisol.sendBuffer: response: 002C30EB 177 | - Wisol.sendBuffer: AT$I=11 178 | 179 | >> AT$I=11 180 | << A8664B5523B5405D0x0d 181 | - Wisol.sendBuffer: response: A8664B5523B5405D 182 | - Wisol.getID: returned id=002C30EB, pac=A8664B5523B5405D 183 | - SIGFOX ID = 002C30EB 184 | - PAC = A8664B5523B5405D 185 | - Wisol.setFrequencySG 186 | - Set frequency result = OK 187 | - Getting frequency (expecting 3)... 188 | - Frequency (expecting 3) = 52 189 | - Wisol.sendBuffer: AT$T? 190 | 191 | >> AT$T? 192 | << 322 193 | - Wisol.sendBuffer: response: 322 194 | - Wisol.getTemperature: returned 32.20 195 | scaledTemp = 31.21 degrees C 196 | scaledHumidity = 49.62 % 197 | scaledAltitude = 16.58 metres above sea level 198 | scaledModuleTemp = 32.20 degrees C 199 | 200 | Running loop #0 201 | - Message.addField: tmp=31.2 202 | - Message.addField: hmd=49.6 203 | - Message.addField: alt=16.5 204 | - Wisol.sendMessage: 002C30EB,b0513801a421f0019405a500 205 | - Wisol.sendBuffer: AT$GI? 206 | 207 | >> AT$GI? 208 | << 1,0 209 | - Wisol.sendBuffer: response: 1,0 210 | - Wisol.sendBuffer: AT$RC 211 | 212 | >> AT$RC 213 | << OK0x0d 214 | - Wisol.sendBuffer: response: OK 215 | - Wisol.sendBuffer: AT$SF=b0513801a421f0019405a500 216 | 217 | >> AT$SF=b0513801a421f0019405a500 218 | << OK0x0d 219 | - Wisol.sendBuffer: response: OK 220 | OK 221 | Waiting 10 seconds... 222 | - Wisol.sendBuffer: AT$T? 223 | 224 | >> AT$T? 225 | << 326 226 | - Wisol.sendBuffer: response: 326 227 | - Wisol.getTemperature: returned 32.60 228 | scaledTemp = 31.23 degrees C 229 | scaledHumidity = 49.66 % 230 | scaledAltitude = 16.55 metres above sea level 231 | scaledModuleTemp = 32.60 degrees C 232 | 233 | Running loop #1 234 | - Message.addField: tmp=31.2 235 | - Message.addField: hmd=49.6 236 | - Message.addField: alt=16.5 237 | - Wisol.sendMessage: 002C30EB,b0513801a421f0019405a500 238 | Warning: Should wait 10 mins before sending the next message 239 | - Wisol.sendBuffer: AT$GI? 240 | 241 | >> AT$GI? 242 | << 1,3 243 | - Wisol.sendBuffer: response: 1,3 244 | - Wisol.sendBuffer: AT$SF=b0513801a421f0019405a500 245 | 246 | >> AT$SF=b0513801a421f0019405a500 247 | << OK0x0d 248 | - Wisol.sendBuffer: response: OK 249 | OK 250 | Waiting 10 seconds... 251 | - Wisol.sendBuffer: AT$T? 252 | 253 | >> AT$T? 254 | << 328 255 | - Wisol.sendBuffer: response: 328 256 | - Wisol.getTemperature: returned 32.80 257 | scaledTemp = 31.23 degrees C 258 | scaledHumidity = 49.72 % 259 | scaledAltitude = 16.64 metres above sea level 260 | scaledModuleTemp = 32.80 degrees C 261 | 262 | Running loop #2 263 | - Message.addField: tmp=31.2 264 | - Message.addField: hmd=49.7 265 | - Message.addField: alt=16.6 266 | - Wisol.sendMessage: 002C30EB,b0513801a421f1019405a600 267 | Warning: Should wait 10 mins before sending the next message 268 | - Wisol.sendBuffer: AT$GI? 269 | 270 | >> AT$GI? 271 | << 1,0 272 | - Wisol.sendBuffer: response: 1,0 273 | - Wisol.sendBuffer: AT$RC 274 | 275 | >> AT$RC 276 | << OK0x0d 277 | - Wisol.sendBuffer: response: OK 278 | - Wisol.sendBuffer: AT$SF=b0513801a421f1019405a600 279 | 280 | >> AT$SF=b0513801a421f1019405a600 281 | << OK0x0d 282 | - Wisol.sendBuffer: response: OK 283 | OK 284 | Waiting 10 seconds... 285 | 286 | */ 287 | -------------------------------------------------------------------------------- /examples/send-altitude/Adafruit_BME280.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | This is a library for the BME280 humidity, temperature & pressure sensor 3 | 4 | Designed specifically to work with the Adafruit BME280 Breakout 5 | ----> http://www.adafruit.com/products/2650 6 | 7 | These sensors use I2C or SPI to communicate, 2 or 4 pins are required 8 | to interface. 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit andopen-source hardware by purchasing products 12 | from Adafruit! 13 | 14 | Written by Limor Fried & Kevin Townsend for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ***************************************************************************/ 17 | #ifndef __BME280_H__ 18 | #define __BME280_H__ 19 | 20 | #if (ARDUINO >= 100) 21 | #include "Arduino.h" 22 | #else 23 | #include "WProgram.h" 24 | #endif 25 | 26 | #include "Adafruit_Sensor.h" 27 | #include 28 | 29 | /*========================================================================= 30 | I2C ADDRESS/BITS 31 | -----------------------------------------------------------------------*/ 32 | #define BME280_ADDRESS (0x77) 33 | /*=========================================================================*/ 34 | 35 | /*========================================================================= 36 | REGISTERS 37 | -----------------------------------------------------------------------*/ 38 | enum 39 | { 40 | BME280_REGISTER_DIG_T1 = 0x88, 41 | BME280_REGISTER_DIG_T2 = 0x8A, 42 | BME280_REGISTER_DIG_T3 = 0x8C, 43 | 44 | BME280_REGISTER_DIG_P1 = 0x8E, 45 | BME280_REGISTER_DIG_P2 = 0x90, 46 | BME280_REGISTER_DIG_P3 = 0x92, 47 | BME280_REGISTER_DIG_P4 = 0x94, 48 | BME280_REGISTER_DIG_P5 = 0x96, 49 | BME280_REGISTER_DIG_P6 = 0x98, 50 | BME280_REGISTER_DIG_P7 = 0x9A, 51 | BME280_REGISTER_DIG_P8 = 0x9C, 52 | BME280_REGISTER_DIG_P9 = 0x9E, 53 | 54 | BME280_REGISTER_DIG_H1 = 0xA1, 55 | BME280_REGISTER_DIG_H2 = 0xE1, 56 | BME280_REGISTER_DIG_H3 = 0xE3, 57 | BME280_REGISTER_DIG_H4 = 0xE4, 58 | BME280_REGISTER_DIG_H5 = 0xE5, 59 | BME280_REGISTER_DIG_H6 = 0xE7, 60 | 61 | BME280_REGISTER_CHIPID = 0xD0, 62 | BME280_REGISTER_VERSION = 0xD1, 63 | BME280_REGISTER_SOFTRESET = 0xE0, 64 | 65 | BME280_REGISTER_CAL26 = 0xE1, // R calibration stored in 0xE1-0xF0 66 | 67 | BME280_REGISTER_CONTROLHUMID = 0xF2, 68 | BME280_REGISTER_CONTROL = 0xF4, 69 | BME280_REGISTER_CONFIG = 0xF5, 70 | BME280_REGISTER_PRESSUREDATA = 0xF7, 71 | BME280_REGISTER_TEMPDATA = 0xFA, 72 | BME280_REGISTER_HUMIDDATA = 0xFD, 73 | }; 74 | 75 | /*=========================================================================*/ 76 | 77 | /*========================================================================= 78 | CALIBRATION DATA 79 | -----------------------------------------------------------------------*/ 80 | typedef struct 81 | { 82 | uint16_t dig_T1; 83 | int16_t dig_T2; 84 | int16_t dig_T3; 85 | 86 | uint16_t dig_P1; 87 | int16_t dig_P2; 88 | int16_t dig_P3; 89 | int16_t dig_P4; 90 | int16_t dig_P5; 91 | int16_t dig_P6; 92 | int16_t dig_P7; 93 | int16_t dig_P8; 94 | int16_t dig_P9; 95 | 96 | uint8_t dig_H1; 97 | int16_t dig_H2; 98 | uint8_t dig_H3; 99 | int16_t dig_H4; 100 | int16_t dig_H5; 101 | int8_t dig_H6; 102 | } bme280_calib_data; 103 | /*=========================================================================*/ 104 | 105 | /* 106 | class Adafruit_BME280_Unified : public Adafruit_Sensor 107 | { 108 | public: 109 | Adafruit_BME280_Unified(int32_t sensorID = -1); 110 | 111 | bool begin(uint8_t addr = BME280_ADDRESS); 112 | void getTemperature(float *temp); 113 | void getPressure(float *pressure); 114 | float pressureToAltitude(float seaLevel, float atmospheric, float temp); 115 | float seaLevelForAltitude(float altitude, float atmospheric, float temp); 116 | void getEvent(sensors_event_t*); 117 | void getSensor(sensor_t*); 118 | 119 | private: 120 | uint8_t _i2c_addr; 121 | int32_t _sensorID; 122 | }; 123 | 124 | */ 125 | 126 | class Adafruit_BME280 127 | { 128 | public: 129 | Adafruit_BME280(void); 130 | Adafruit_BME280(int8_t cspin); 131 | Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin); 132 | 133 | bool begin(uint8_t addr = BME280_ADDRESS); 134 | float readTemperature(void); 135 | float readPressure(void); 136 | float readHumidity(void); 137 | float readAltitude(float seaLevel); 138 | float seaLevelForAltitude(float altitude, float atmospheric); 139 | 140 | private: 141 | 142 | void readCoefficients(void); 143 | uint8_t spixfer(uint8_t x); 144 | 145 | void write8(byte reg, byte value); 146 | uint8_t read8(byte reg); 147 | uint16_t read16(byte reg); 148 | uint32_t read24(byte reg); 149 | int16_t readS16(byte reg); 150 | uint16_t read16_LE(byte reg); // little endian 151 | int16_t readS16_LE(byte reg); // little endian 152 | 153 | uint8_t _i2caddr; 154 | int32_t _sensorID; 155 | int32_t t_fine; 156 | 157 | int8_t _cs, _mosi, _miso, _sck; 158 | 159 | bme280_calib_data _bme280_calib; 160 | 161 | }; 162 | 163 | #endif 164 | -------------------------------------------------------------------------------- /examples/send-altitude/Adafruit_Sensor.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBiz/unabiz-arduino/b8cc57137b5debd4f29432e41d6924aa2cf9f474/examples/send-altitude/Adafruit_Sensor.h -------------------------------------------------------------------------------- /examples/send-altitude/send-altitude.ino: -------------------------------------------------------------------------------- 1 | // Send sensor data from the onboard temperature, humudity, barometer sensors 2 | // as a SIGFOX message, using the UnaBiz UnaShield V2S Arduino Shield. 3 | // The Arduino Uno onboard LED will flash every few seconds when the sketch is running properly. 4 | // The data is sent in the Sigfox Custom Payload Format, which will be decoded by the Sigfox cloud. 5 | 6 | //////////////////////////////////////////////////////////// 7 | // Begin Sensor Declaration 8 | // Don't use ports D0, D1: Reserved for viewing debug output through Arduino Serial Monitor 9 | // Don't use ports D4, D5: Reserved for serial comms with the SIGFOX module. 10 | 11 | /*************************************************************************** 12 | This is a library for the BME280 humidity, temperature & pressure sensor 13 | Mike Nguyen (Vinova) Mike Nguyen (Vinova) 14 | Designed specifically to work with the Adafruit BME280 Breakout 15 | ----> http://www.adafruit.com/products/2650 16 | 17 | These sensors use I2C or SPI to communicate, 2 or 4 pins are required 18 | to interface. 19 | 20 | Adafruit invests time and resources providing this open source code, 21 | please support Adafruit andopen-source hardware by purchasing products 22 | from Adafruit! 23 | 24 | Written by Limor Fried & Kevin Townsend for Adafruit Industries. 25 | BSD license, all text above must be included in any redistribution 26 | ***************************************************************************/ 27 | 28 | #include 29 | #include 30 | #include "Adafruit_Sensor.h" 31 | #include "Adafruit_BME280.h" 32 | 33 | #define BME_SCK 13 34 | #define BME_MISO 12 35 | #define BME_MOSI 11 36 | #define BME_CS 10 37 | 38 | #define SEALEVELPRESSURE_HPA (1013.25) 39 | 40 | Adafruit_BME280 bme; // I2C 41 | 42 | // End Sensor Declaration 43 | //////////////////////////////////////////////////////////// 44 | 45 | //////////////////////////////////////////////////////////// 46 | // Begin SIGFOX Module Declaration 47 | 48 | #include "SIGFOX.h" 49 | 50 | // IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly. 51 | static const String device = ""; // Set this to your device name if you're using SIGFOX Emulator. 52 | static const bool useEmulator = false; // Set to true if using SIGFOX Emulator. 53 | static const bool echo = true; // Set to true if the SIGFOX library should display the executed commands. 54 | static const Country country = COUNTRY_SG; // Set this to your country to configure the SIGFOX transmission frequencies. 55 | static UnaShieldV2S transceiver(country, useEmulator, device, echo); // Assumes you are using UnaBiz UnaShield V2S Dev Kit 56 | 57 | // End SIGFOX Module Declaration 58 | //////////////////////////////////////////////////////////// 59 | 60 | void setup() { // Will be called only once. 61 | //////////////////////////////////////////////////////////// 62 | // Begin General Setup 63 | 64 | // Initialize console so we can see debug messages (9600 bits per second). 65 | Serial.begin(9600); Serial.println(F("Running setup...")); 66 | 67 | // Initialize the onboard LED at D13 for output. 68 | pinMode(LED_BUILTIN, OUTPUT); 69 | 70 | // End General Setup 71 | //////////////////////////////////////////////////////////// 72 | 73 | //////////////////////////////////////////////////////////// 74 | // Begin Sensor Setup 75 | 76 | if (!bme.begin(0x76)) stop("Bosch BME280 sensor missing"); // Will never return. 77 | 78 | // End Sensor Setup 79 | //////////////////////////////////////////////////////////// 80 | 81 | //////////////////////////////////////////////////////////// 82 | // Begin SIGFOX Module Setup 83 | 84 | // Check whether the SIGFOX module is functioning. 85 | if (!transceiver.begin()) stop("Unable to init SIGFOX module, may be missing"); // Will never return. 86 | 87 | // End SIGFOX Module Setup 88 | //////////////////////////////////////////////////////////// 89 | } 90 | 91 | void loop() { // Will be called repeatedly. 92 | //////////////////////////////////////////////////////////// 93 | // Begin Sensor Loop 94 | 95 | // Read the ambient temperature, humidity, air pressure. 96 | float filteredTemp = bme.readTemperature(); 97 | float filteredPressure = bme.readPressure() / 100.0F; 98 | float filteredAltitude = bme.readAltitude(SEALEVELPRESSURE_HPA); 99 | float humidity = bme.readHumidity(); 100 | 101 | // Get temperature of the SIGFOX module. 102 | float moduleTemp; transceiver.getTemperature(moduleTemp); 103 | 104 | // Optional: We may scale the values by 100 so we can have 2 decimal places of precision. 105 | // For now we don't scale the values. 106 | unsigned int scaledTemp = filteredTemp * 1.0; 107 | unsigned int scaledHumidity = humidity * 1.0; 108 | unsigned int scaledAltitude = filteredAltitude * 1.0; 109 | unsigned int scaledModuleTemp = moduleTemp * 1.0; 110 | 111 | Serial.print("scaledTemp = "); Serial.print(scaledTemp); Serial.println(" degrees C"); 112 | Serial.print("scaledHumidity = "); Serial.print(scaledHumidity); Serial.println(" %"); 113 | Serial.print("scaledAltitude = "); Serial.print(scaledAltitude); Serial.println(" metres above sea level"); 114 | Serial.print("scaledModuleTemp = "); Serial.print(scaledModuleTemp); Serial.println(" degrees C"); 115 | 116 | // End Sensor Loop 117 | //////////////////////////////////////////////////////////// 118 | 119 | //////////////////////////////////////////////////////////// 120 | // Begin SIGFOX Module Loop 121 | 122 | // Send temperature, pressure, altitude, module temperature as a SIGFOX message. 123 | static int counter = 0, successCount = 0, failCount = 0; // Count messages sent and failed. 124 | Serial.print(F("\nRunning loop #")); Serial.println(counter); 125 | 126 | // Compose the message, total 4 bytes. (char) forces the value to be 8 bit. 127 | // Note this doesn't use the Structured Message Format like in previous examples. 128 | // It uses the Sigfox Custom Payload format: temp::int:8 humid::int:8 alt::int:8 modtemp::int:8 129 | String msg = transceiver.toHex((char) scaledTemp) // int 1 byte: temperature * 1 130 | + transceiver.toHex((char) scaledHumidity) // int 1 byte: humidity * 1 131 | + transceiver.toHex((char) scaledAltitude) // int 1 byte: altitude * 1 132 | + transceiver.toHex((char) scaledModuleTemp); // int 1 byte: module temperature * 1 133 | 134 | // Send the message. 135 | if (transceiver.sendMessage(msg)) { 136 | successCount++; // If successful, count the message sent successfully. 137 | } else { 138 | failCount++; // If failed, count the message that could not be sent. 139 | } 140 | counter++; 141 | 142 | // Flash the LED on and off at every iteration so we know the sketch is still running. 143 | if (counter % 2 == 0) { 144 | digitalWrite(LED_BUILTIN, HIGH); // Turn the LED on (HIGH is the voltage level). 145 | } else { 146 | digitalWrite(LED_BUILTIN, LOW); // Turn the LED off (LOW is the voltage level). 147 | } 148 | 149 | // Show updates every 10 messages. 150 | if (counter % 10 == 0) { 151 | Serial.print(F("Messages sent successfully: ")); Serial.print(successCount); 152 | Serial.print(F(", failed: ")); Serial.println(failCount); 153 | } 154 | 155 | // End SIGFOX Module Loop 156 | //////////////////////////////////////////////////////////// 157 | 158 | // Wait a while before looping. 10000 milliseconds = 10 seconds. 159 | Serial.println(F("Waiting 10 seconds...")); 160 | delay(10000); 161 | } 162 | /* Expected Output: 163 | Running setup... 164 | - Disabling SNEK emulation mode... 165 | - Wisol.sendBuffer: ATS410=0 166 | 167 | >> ATS410=0 168 | << OK0x0d 169 | - Wisol.sendBuffer: response: OK 170 | - Getting SIGFOX ID... 171 | - Wisol.sendBuffer: AT$I=10 172 | 173 | >> AT$I=10 174 | << 002C30EB0x0d 175 | - Wisol.sendBuffer: response: 002C30EB 176 | - Wisol.sendBuffer: AT$I=11 177 | 178 | >> AT$I=11 179 | << A8664B5523B5405D0x0d 180 | - Wisol.sendBuffer: response: A8664B5523B5405D 181 | - Wisol.getID: returned id=002C30EB, pac=A8664B5523B5405D 182 | - SIGFOX ID = 002C30EB 183 | - PAC = A8664B5523B5405D 184 | - Wisol.setFrequencySG 185 | - Set frequency result = OK 186 | - Getting frequency (expecting 3)... 187 | - Frequency (expecting 3) = 52 188 | - Wisol.sendBuffer: AT$T? 189 | 190 | >> AT$T? 191 | << 291 192 | - Wisol.sendBuffer: response: 291 193 | - Wisol.getTemperature: returned 29.10 194 | scaledTemp = 28 degrees C 195 | scaledHumidity = 48 % 196 | scaledAltitude = 54 metres above sea level 197 | scaledModuleTemp = 29 degrees C 198 | 199 | Running loop #0 200 | - Wisol.sendMessage: 002C30EB,1c30361d 201 | - Wisol.sendBuffer: AT$GI? 202 | 203 | >> AT$GI? 204 | << 1,0 205 | - Wisol.sendBuffer: response: 1,0 206 | - Wisol.sendBuffer: AT$RC 207 | 208 | >> AT$RC 209 | << OK0x0d 210 | - Wisol.sendBuffer: response: OK 211 | - Wisol.sendBuffer: AT$SF=1c30361d 212 | 213 | >> AT$SF=1c30361d 214 | << OK0x0d 215 | - Wisol.sendBuffer: response: OK 216 | OK 217 | Waiting 10 seconds... 218 | - Wisol.sendBuffer: AT$T? 219 | 220 | >> AT$T? 221 | << 291 222 | - Wisol.sendBuffer: response: 291 223 | - Wisol.getTemperature: returned 29.10 224 | scaledTemp = 28 degrees C 225 | scaledHumidity = 47 % 226 | scaledAltitude = 55 metres above sea level 227 | scaledModuleTemp = 29 degrees C 228 | 229 | Running loop #1 230 | - Wisol.sendMessage: 002C30EB,1c2f371d 231 | Warning: Should wait 10 mins before sending the next message 232 | - Wisol.sendBuffer: AT$GI? 233 | 234 | >> AT$GI? 235 | << 1,3 236 | - Wisol.sendBuffer: response: 1,3 237 | - Wisol.sendBuffer: AT$SF=1c2f371d 238 | 239 | >> AT$SF=1c2f371d 240 | << OK0x0d 241 | - Wisol.sendBuffer: response: OK 242 | OK 243 | Waiting 10 seconds... 244 | */ 245 | -------------------------------------------------------------------------------- /examples/send-light-level/send-light-level.ino: -------------------------------------------------------------------------------- 1 | // Send sensor data from the light sensor as SIGFOX messages with UnaBiz UnaShield Arduino Shield. 2 | // This code assumes that you are using the Grove Light Sensor v1.1: 3 | // http://wiki.seeed.cc/Grove-Light_Sensor/ 4 | // 5 | // Instructions and code based on: https://github.com/Seeed-Studio/Light_Sensor/blob/master/examples/Light_Sensor/Light_Sensor.ino 6 | // Connect the Grove Light Sensor to the Arduino as follows: 7 | // Grove Light Sensor GND (Black Wire) --> Arduino GND 8 | // Grove Light Sensor VCC (Red Wire) --> Arduino 5V 9 | // Grove Light Sensor SIG (Yellow Wire) --> Arduino A0 10 | 11 | //////////////////////////////////////////////////////////// 12 | // Begin Sensor Declaration 13 | // Don't use ports D0, D1: Reserved for viewing debug output through Arduino Serial Monitor 14 | // Don't use ports D4, D5: Reserved for serial comms with the SIGFOX module. 15 | 16 | #ifdef BEAN_BEAN_BEAN_H 17 | #define LIGHT_SENSOR A2 // For Bean+, Grove Light Sensor is connected to port A2. 18 | #else 19 | #define LIGHT_SENSOR A0 // Else Grove Light Sensor is connected to port A0. 20 | #endif // BEAN_BEAN_BEAN_H 21 | 22 | // End Sensor Declaration 23 | //////////////////////////////////////////////////////////// 24 | 25 | //////////////////////////////////////////////////////////// 26 | // Begin SIGFOX Module Declaration 27 | 28 | #include "SIGFOX.h" 29 | 30 | // IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly. 31 | static const String device = "g88pi"; // Set this to your device name if you're using UnaBiz Emulator. 32 | static const bool useEmulator = false; // Set to true if using UnaBiz Emulator. 33 | static const bool echo = true; // Set to true if the SIGFOX library should display the executed commands. 34 | static const Country country = COUNTRY_SG; // Set this to your country to configure the SIGFOX transmission frequencies. 35 | // static UnaShieldV2S transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V2S Dev Kit 36 | static UnaShieldV1 transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V1 Dev Kit 37 | 38 | // End SIGFOX Module Declaration 39 | //////////////////////////////////////////////////////////// 40 | 41 | void setup() { // Will be called only once. 42 | //////////////////////////////////////////////////////////// 43 | // Begin General Setup 44 | 45 | // Initialize console so we can see debug messages (9600 bits per second). 46 | Serial.begin(9600); Serial.println(F("Running setup...")); 47 | 48 | // End General Setup 49 | //////////////////////////////////////////////////////////// 50 | 51 | //////////////////////////////////////////////////////////// 52 | // Begin Sensor Setup 53 | 54 | // No setup needed for light sensor. 55 | 56 | // End Sensor Setup 57 | //////////////////////////////////////////////////////////// 58 | 59 | //////////////////////////////////////////////////////////// 60 | // Begin SIGFOX Module Setup 61 | 62 | // Check whether the SIGFOX module is functioning. 63 | if (!transceiver.begin()) stop("Unable to init SIGFOX module, may be missing"); // Will never return. 64 | 65 | // End SIGFOX Module Setup 66 | //////////////////////////////////////////////////////////// 67 | } 68 | 69 | void loop() { // Will be called repeatedly. 70 | //////////////////////////////////////////////////////////// 71 | // Begin Sensor Loop 72 | 73 | // Read the light sensor from the analog port. 74 | int light_level = analogRead(LIGHT_SENSOR); 75 | Serial.print(F("light_level=")); Serial.println(light_level); 76 | 77 | // End Sensor Loop 78 | //////////////////////////////////////////////////////////// 79 | 80 | //////////////////////////////////////////////////////////// 81 | // Begin SIGFOX Module Loop 82 | 83 | // Send message counter, light level and temperature as a SIGFOX message. 84 | static int counter = 0, successCount = 0, failCount = 0; // Count messages sent and failed. 85 | Serial.print(F("\nRunning loop #")); Serial.println(counter); 86 | 87 | // Get temperature of the SIGFOX module. 88 | int temperature; transceiver.getTemperature(temperature); 89 | 90 | // Convert the numeric counter, light level and temperature into a compact message with binary fields. 91 | Message msg(transceiver); // Will contain the structured sensor data. 92 | msg.addField("ctr", counter); // 4 bytes for the counter. 93 | msg.addField("lig", light_level); // 4 bytes for the light level. 94 | msg.addField("tmp", temperature); // 4 bytes for the temperature. 95 | // Total 12 bytes out of 12 bytes used. 96 | 97 | // Send the message. 98 | if (msg.send()) { 99 | successCount++; // If successful, count the message sent successfully. 100 | } else { 101 | failCount++; // If failed, count the message that could not be sent. 102 | } 103 | counter++; 104 | 105 | // Show updates every 10 messages. 106 | if (counter % 10 == 0) { 107 | Serial.print(F("Messages sent successfully: ")); Serial.print(successCount); 108 | Serial.print(F(", failed: ")); Serial.println(failCount); 109 | } 110 | 111 | // End SIGFOX Module Loop 112 | //////////////////////////////////////////////////////////// 113 | 114 | // Wait a while before looping. 10000 milliseconds = 10 seconds. 115 | Serial.println(F("Waiting 10 seconds...")); 116 | delay(10000); 117 | } 118 | 119 | /* 120 | Expected output for Non-Emulation Mode: 121 | 122 | Running setup... 123 | - Disabling emulation mode... 124 | - Entering command mode... 125 | - Radiocrafts.sendBuffer: 00 126 | >> 00 127 | << 3E 128 | - Radiocrafts.sendBuffer: response: 129 | - Radiocrafts.enterCommandMode: OK 130 | - Radiocrafts.sendBuffer: 4d2800 131 | >> 4d 28 00 132 | << 3E 133 | - Radiocrafts.sendBuffer: response: 134 | - Radiocrafts.sendBuffer: ff 135 | >> ff 136 | << 3E 137 | - Radiocrafts.sendBuffer: response: 138 | - Checking emulation mode (expecting 0)... 139 | - Radiocrafts.getParameter: address=0x28 140 | - Radiocrafts.sendBuffer: 5928 141 | >> 59 28 142 | << 3E 00 3E 143 | - Radiocrafts.sendBuffer: response: 00 144 | - Radiocrafts.getParameter: address=0x28 returned 00 145 | - Getting SIGFOX ID... 146 | - Radiocrafts.sendBuffer: 39 147 | >> 39 148 | << 52 86 1c 00 c5 81 90 5c 81 2b a6 81 3E 149 | - Radiocrafts.sendBuffer: response: 52861c00c581905c812ba681 150 | - Radiocrafts.getID: returned id=001c8652, pac=c581905c812ba681 151 | - SIGFOX ID = 001c8652 152 | - PAC = c581905c812ba681 153 | - Setting frequency for country -26112 154 | - Radiocrafts.setFrequencySG 155 | - Radiocrafts.sendBuffer: 4d0003 156 | >> 4d 00 03 157 | << 3E 158 | - Radiocrafts.sendBuffer: response: 159 | - Radiocrafts.sendBuffer: ff 160 | >> ff 161 | << 3E 162 | - Radiocrafts.sendBuffer: response: 163 | - Set frequency result = 164 | - Getting frequency (expecting 3)... 165 | - Radiocrafts.sendBuffer: 5900 166 | >> 59 00 167 | << 3E 168 | - Radiocrafts.sendBuffer: response: 169 | - Frequency (expecting 3) = 170 | light_level=512 171 | 172 | Running loop #0 173 | - Radiocrafts.sendBuffer: 55 174 | >> 55 175 | << 00 3E 176 | - Radiocrafts.sendBuffer: response: 00 177 | - Radiocrafts.getTemperature: returned -128 178 | - Message.addField: ctr=0 179 | - Message.addField: lig=512 180 | - Message.addField: tmp=-128 181 | - Radiocrafts.sendMessage: 001c8652,920e000027310014b05100fb 182 | - Radiocrafts.sendBuffer: 58 183 | >> 58 184 | << 185 | - Radiocrafts.sendBuffer: response: 186 | - Radiocrafts.exitCommandMode: OK 187 | - Radiocrafts.sendBuffer: 0c920e000027310014b05100fb 188 | >> 0c 92 0e 00 00 27 31 00 14 b0 51 00 fb 189 | << 190 | - Radiocrafts.sendBuffer: response: 191 | 192 | Waiting 10 seconds... 193 | light_level=285 194 | 195 | Running loop #1 196 | - Entering command mode... 197 | - Radiocrafts.sendBuffer: 00 198 | >> 00 199 | << 3E 200 | - Radiocrafts.sendBuffer: response: 201 | - Radiocrafts.enterCommandMode: OK 202 | - Radiocrafts.sendBuffer: 55 203 | >> 55 204 | << 98 3E 205 | - Radiocrafts.sendBuffer: response: 98 206 | - Radiocrafts.getTemperature: returned 24 207 | - Message.addField: ctr=1 208 | - Message.addField: lig=285 209 | - Message.addField: tmp=24 210 | - Radiocrafts.sendMessage: 001c8652,920e0a002731220bb051f000 211 | Warning: Should wait 10 mins before sending the next message 212 | - Radiocrafts.sendBuffer: 58 213 | >> 58 214 | << 215 | - Radiocrafts.sendBuffer: response: 216 | - Radiocrafts.exitCommandMode: OK 217 | - Radiocrafts.sendBuffer: 0c920e0a002731220bb051f000 218 | >> 0c 92 0e 0a 00 27 31 22 0b b0 51 f0 00 219 | << 220 | - Radiocrafts.sendBuffer: response: 221 | 222 | Waiting 10 seconds... 223 | light_level=328 224 | 225 | Running loop #2 226 | - Entering command mode... 227 | - Radiocrafts.sendBuffer: 00 228 | >> 00 229 | << 3E 230 | - Radiocrafts.sendBuffer: response: 231 | - Radiocrafts.enterCommandMode: OK 232 | - Radiocrafts.sendBuffer: 55 233 | >> 55 234 | << 98 3E 235 | - Radiocrafts.sendBuffer: response: 98 236 | - Radiocrafts.getTemperature: returned 24 237 | - Message.addField: ctr=2 238 | - Message.addField: lig=328 239 | - Message.addField: tmp=24 240 | - Radiocrafts.sendMessage: 001c8652,920e14002731d00cb051f000 241 | Warning: Should wait 10 mins before sending the next message 242 | - Radiocrafts.sendBuffer: 58 243 | >> 58 244 | << 245 | - Radiocrafts.sendBuffer: response: 246 | - Radiocrafts.exitCommandMode: OK 247 | - Radiocrafts.sendBuffer: 0c920e14002731d00cb051f000 248 | >> 0c 92 0e 14 00 27 31 d0 0c b0 51 f0 00 249 | << 250 | - Radiocrafts.sendBuffer: response: 251 | 252 | Waiting 10 seconds... 253 | light_level=288 254 | 255 | Running loop #3 256 | - Entering command mode... 257 | - Radiocrafts.sendBuffer: 00 258 | >> 00 259 | << 3E 260 | - Radiocrafts.sendBuffer: response: 261 | - Radiocrafts.enterCommandMode: OK 262 | - Radiocrafts.sendBuffer: 55 263 | >> 55 264 | << 98 3E 265 | - Radiocrafts.sendBuffer: response: 98 266 | - Radiocrafts.getTemperature: returned 24 267 | - Message.addField: ctr=3 268 | - Message.addField: lig=288 269 | - Message.addField: tmp=24 270 | - Radiocrafts.sendMessage: 001c8652,920e1e002731400bb051f000 271 | Warning: Should wait 10 mins before sending the next message 272 | - Radiocrafts.sendBuffer: 58 273 | >> 58 274 | << 275 | - Radiocrafts.sendBuffer: response: 276 | - Radiocrafts.exitCommandMode: OK 277 | - Radiocrafts.sendBuffer: 0c920e1e002731400bb051f000 278 | >> 0c 92 0e 1e 00 27 31 40 0b b0 51 f0 00 279 | << 280 | - Radiocrafts.sendBuffer: response: 281 | 282 | Waiting 10 seconds... 283 | light_level=325 284 | */ 285 | 286 | /* 287 | Expected output for Emulation Mode: 288 | 289 | Running setup... 290 | - Entering command mode... 291 | - Radiocrafts.sendBuffer: 00 292 | - Radiocrafts.enterCommandMode: OK 293 | - Radiocrafts.sendBuffer: 4d2801 294 | - Radiocrafts.sendBuffer: ff 295 | - Getting SIGFOX ID... 296 | - Radiocrafts.sendBuffer: 39 297 | - SIGFOX ID = g88pi 298 | - PAC = 299 | - Setting frequency for country -26112 300 | - Radiocrafts.setFrequencySG 301 | - Radiocrafts.sendBuffer: 4d0003 302 | - Radiocrafts.sendBuffer: ff 303 | - Set frequency result = 304 | - Getting frequency (expecting 3)... 305 | - Radiocrafts.sendBuffer: 5900 306 | - Frequency (expecting 3) = 307 | light_level=54 308 | 309 | Running loop #0 310 | - Radiocrafts.sendBuffer: 55 311 | - Message.addField: ctr=0 312 | - Message.addField: lig=54 313 | - Message.addField: tmp=36 314 | - Radiocrafts.sendMessage: g88pi,920e000027311c02b0516801 315 | - Radiocrafts.sendBuffer: 58 316 | - Radiocrafts.exitCommandMode: OK 317 | - Radiocrafts.sendBuffer: 0c920e000027311c02b0516801 318 | 319 | Waiting 10 seconds... 320 | light_level=53 321 | 322 | Running loop #1 323 | - Entering command mode... 324 | - Radiocrafts.sendBuffer: 00 325 | - Radiocrafts.enterCommandMode: OK 326 | - Radiocrafts.sendBuffer: 55 327 | - Message.addField: ctr=1 328 | - Message.addField: lig=53 329 | - Message.addField: tmp=36 330 | - Radiocrafts.sendMessage: g88pi,920e0a0027311202b0516801 331 | Warning: Should wait 10 mins before sending the next message 332 | - Radiocrafts.sendBuffer: 58 333 | - Radiocrafts.exitCommandMode: OK 334 | - Radiocrafts.sendBuffer: 0c920e0a0027311202b0516801 335 | 336 | Waiting 10 seconds... 337 | light_level=780 338 | 339 | Running loop #2 340 | - Entering command mode... 341 | - Radiocrafts.sendBuffer: 00 342 | - Radiocrafts.enterCommandMode: OK 343 | - Radiocrafts.sendBuffer: 55 344 | - Message.addField: ctr=2 345 | - Message.addField: lig=780 346 | - Message.addField: tmp=36 347 | - Radiocrafts.sendMessage: g88pi,920e14002731781eb0516801 348 | Warning: Should wait 10 mins before sending the next message 349 | - Radiocrafts.sendBuffer: 58 350 | - Radiocrafts.exitCommandMode: OK 351 | - Radiocrafts.sendBuffer: 0c920e14002731781eb0516801 352 | 353 | Waiting 10 seconds... 354 | light_level=781 355 | 356 | Running loop #3 357 | - Entering command mode... 358 | - Radiocrafts.sendBuffer: 00 359 | - Radiocrafts.enterCommandMode: OK 360 | - Radiocrafts.sendBuffer: 55 361 | - Message.addField: ctr=3 362 | - Message.addField: lig=781 363 | - Message.addField: tmp=36 364 | - Radiocrafts.sendMessage: g88pi,920e1e002731821eb0516801 365 | Warning: Should wait 10 mins before sending the next message 366 | - Radiocrafts.sendBuffer: 58 367 | - Radiocrafts.exitCommandMode: OK 368 | - Radiocrafts.sendBuffer: 0c920e1e002731821eb0516801 369 | 370 | Waiting 10 seconds... 371 | */ 372 | -------------------------------------------------------------------------------- /examples/send-temperature/send-temperature.ino: -------------------------------------------------------------------------------- 1 | // Send the sensor data from the temperature sensor to the SIGFOX cloud. 2 | // This code assumes that you are using the Grove DHT Sensor Pro: 3 | // http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro 4 | // 5 | // You can easily adapt the code for other Grove temperature sensors: 6 | // http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_Sensor 7 | // http://wiki.seeedstudio.com/wiki/Grove_-_Tempture&Humidity_Sensor_(High-Accuracy_&Mini)_v1.0 8 | // 9 | // Instructions and code based on: http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro 10 | // 1. Connect the Temperature and Humidity Sensor Pro to Port D2 of Grove - Base Shield 11 | // 2. Download and install Seeed DHT Library: https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor 12 | // 3. Make sure the voltage on the Grove Shield matches the voltage on the Arduino board. 13 | 14 | //////////////////////////////////////////////////////////// 15 | // Begin Sensor Declaration 16 | 17 | #include "DHT.h" // From https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor 18 | #define DHTPIN 2 // What pin we're connected to. 2 means Port D2. 19 | // Uncomment whatever type you're using! 20 | #define DHTTYPE DHT11 // DHT 11 21 | //#define DHTTYPE DHT22 // DHT 22 (AM2302) 22 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 23 | DHT dht(DHTPIN, DHTTYPE); 24 | 25 | // End Sensor Declaration 26 | //////////////////////////////////////////////////////////// 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Begin SIGFOX Module Declaration 30 | 31 | #include "SIGFOX.h" 32 | 33 | // IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly. 34 | static const String device = "g88pi"; // Set this to your device name if you're using UnaBiz Emulator. 35 | static const bool useEmulator = false; // Set to true if using UnaBiz Emulator. 36 | static const bool echo = true; // Set to true if the SIGFOX library should display the executed commands. 37 | static const Country country = COUNTRY_SG; // Set this to your country to configure the SIGFOX transmission frequencies. 38 | // static UnaShieldV2S transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V2S Dev Kit 39 | static UnaShieldV1 transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V1 Dev Kit 40 | 41 | // End SIGFOX Module Declaration 42 | //////////////////////////////////////////////////////////// 43 | 44 | void setup() 45 | { 46 | //////////////////////////////////////////////////////////// 47 | // Begin General Setup 48 | 49 | // Initialize console serial communication at 9600 bits per second: 50 | Serial.begin(9600); 51 | Serial.println(F("Demo sketch for sending temperature sensor values to SIGFOX cloud :)")); 52 | 53 | // End General Setup 54 | //////////////////////////////////////////////////////////// 55 | 56 | //////////////////////////////////////////////////////////// 57 | // Begin Sensor Setup 58 | 59 | dht.begin(); 60 | 61 | // End Sensor Setup 62 | //////////////////////////////////////////////////////////// 63 | 64 | //////////////////////////////////////////////////////////// 65 | // Begin SIGFOX Module Setup 66 | 67 | String result = ""; 68 | // Enter command mode. 69 | Serial.println(F("\nEntering command mode...")); 70 | transceiver.enterCommandMode(); 71 | 72 | if (useEmulator) { 73 | // Emulation mode. 74 | transceiver.enableEmulator(result); 75 | } else { 76 | // Disable emulation mode. 77 | Serial.println(F("\nDisabling emulation mode...")); 78 | transceiver.disableEmulator(result); 79 | 80 | // Check whether emulator is used for transmission. 81 | Serial.println(F("\nChecking emulation mode (expecting 0)...")); int emulator = 0; 82 | transceiver.getEmulator(emulator); 83 | } 84 | 85 | // Set the frequency of SIGFOX module to SG/TW. 86 | Serial.println(F("\nSetting frequency...")); result = ""; 87 | transceiver.setFrequencySG(result); 88 | Serial.print(F("Set frequency result = ")); Serial.println(result); 89 | 90 | // Get and display the frequency used by the SIGFOX module. Should return 3 for RCZ4 (SG/TW). 91 | Serial.println(F("\nGetting frequency (expecting 3)...")); String frequency = ""; 92 | transceiver.getFrequency(frequency); 93 | Serial.print(F("Frequency (expecting 3) = ")); Serial.println(frequency); 94 | 95 | // Read SIGFOX ID and PAC from module. 96 | Serial.println(F("\nGetting SIGFOX ID...")); String id = "", pac = ""; 97 | if (transceiver.getID(id, pac)) { 98 | Serial.print(F("SIGFOX ID = ")); Serial.println(id); 99 | Serial.print(F("PAC = ")); Serial.println(pac); 100 | } else { 101 | Serial.println(F("ID KO")); 102 | } 103 | 104 | // Exit command mode and prepare to send message. 105 | transceiver.exitCommandMode(); 106 | 107 | // End SIGFOX Module Setup 108 | //////////////////////////////////////////////////////////// 109 | } 110 | 111 | void loop() 112 | { 113 | //////////////////////////////////////////////////////////// 114 | // Begin Sensor Loop 115 | 116 | // Reading temperature or humidity takes about 250 milliseconds! 117 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 118 | float tmp = dht.readTemperature(); 119 | float hmd = dht.readHumidity(); 120 | Message msg(transceiver); // Will contain the structured sensor data. 121 | 122 | // Check if returns are valid, if they are NaN (not a number) then something went wrong! 123 | if (isnan(tmp) || isnan(hmd)) { 124 | Serial.println(F("Failed to read from sensor")); 125 | msg.addField("err", 1); // 4 bytes 126 | } else { 127 | Serial.print(F("Temperature: ")); Serial.println(tmp); 128 | Serial.print(F("Humidity:")); Serial.println(hmd); 129 | 130 | // Convert the numeric temperature and humidity to binary fields. 131 | // Field names must have 3 letters, no digits. Field names occupy 2 bytes. 132 | // Numeric fields occupy 2 bytes, with 1 decimal place. 133 | msg.addField("tmp", tmp); // 4 bytes 134 | msg.addField("hmd", hmd); // 4 bytes 135 | // Total 8 bytes out of 12 bytes used. 136 | } 137 | 138 | // End Sensor Loop 139 | //////////////////////////////////////////////////////////// 140 | 141 | //////////////////////////////////////////////////////////// 142 | // Begin SIGFOX Module Loop 143 | 144 | // Send the message. 145 | Serial.print(F("\n>> Device sending message ")); Serial.print(msg.getEncodedMessage() + "..."); 146 | transceiver.echoOn(); 147 | if (msg.send()) { 148 | Serial.println(F("Message sent")); 149 | } else { 150 | Serial.println(F("Message not sent")); 151 | } 152 | 153 | // End SIGFOX Module Loop 154 | //////////////////////////////////////////////////////////// 155 | 156 | // Wait a while before looping. 10000 milliseconds = 10 seconds. 157 | delay(10000); 158 | } 159 | 160 | /* 161 | Expected output: 162 | 163 | Demo sketch for Akeru library :) 164 | Temperature: 165 | 28.00 166 | Humidity: 167 | 44.00 168 | msg: 169 | t:28,h:44 170 | 171 | >> AT$SS=743a32382c683a3434 172 | << 173 | OK 174 | 175 | Message sent ! 176 | Temperature: 177 | 28.00 178 | Humidity: 179 | 44.00 180 | msg: 181 | t:28,h:44 182 | 183 | >> AT$SS=743a32382c683a3434 184 | << 185 | OK 186 | 187 | Message sent ! 188 | */ 189 | -------------------------------------------------------------------------------- /examples/send-temperature/send-temperature.old: -------------------------------------------------------------------------------- 1 | // Send the sensor data from the temperature sensor to the SIGFOX cloud. 2 | // This code assumes that you are using the Grove DHT Sensor Pro: 3 | // http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro 4 | // 5 | // You can easily adapt the code for other Grove temperature sensors: 6 | // http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_Sensor 7 | // http://wiki.seeedstudio.com/wiki/Grove_-_Tempture&Humidity_Sensor_(High-Accuracy_&Mini)_v1.0 8 | // 9 | // Instructions and code based on: http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro 10 | // 1. Connect the Temperature and Humidity Sensor Pro to Port D2 of Grove - Base Shield 11 | // 2. Download and install Seeed DHT Library: https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor 12 | // 3. Make sure the voltage on the Grove Shield matches the voltage on the Arduino board. 13 | 14 | //////////////////////////////////////////////////////////// 15 | // Begin Sensor Declaration 16 | 17 | #include "DHT.h" // From https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor 18 | #define DHTPIN 2 // What pin we're connected to. 2 means Port D2. 19 | // Uncomment whatever type you're using! 20 | #define DHTTYPE DHT11 // DHT 11 21 | //#define DHTTYPE DHT22 // DHT 22 (AM2302) 22 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 23 | DHT dht(DHTPIN, DHTTYPE); 24 | 25 | // End Sensor Declaration 26 | //////////////////////////////////////////////////////////// 27 | 28 | //////////////////////////////////////////////////////////// 29 | // Begin SIGFOX Module Declaration 30 | 31 | #include "SIGFOX.h" 32 | 33 | // IMPORTANT: Check these settings with UnaBiz to use the right SIGFOX library. 34 | const bool useEmulator = false; // Set to true if using UnaBiz Emulator. 35 | // Akeru transceiver; // Uncomment this for UnaBiz Akene Dev Kit. Default to pin D4 for receive, pin D5 for transmit. 36 | Radiocrafts transceiver; // Uncomment this for UnaBiz Radiocrafts Dev Kit. Default to pin D4 for transmit, pin D5 for receive. 37 | 38 | // End SIGFOX Module Declaration 39 | //////////////////////////////////////////////////////////// 40 | 41 | void setup() 42 | { 43 | //////////////////////////////////////////////////////////// 44 | // Begin General Setup 45 | 46 | // Initialize console serial communication at 9600 bits per second: 47 | Serial.begin(9600); 48 | Serial.println(F("Demo sketch for sending temperature sensor values to SIGFOX cloud :)")); 49 | 50 | // End General Setup 51 | //////////////////////////////////////////////////////////// 52 | 53 | //////////////////////////////////////////////////////////// 54 | // Begin Sensor Setup 55 | 56 | dht.begin(); 57 | 58 | // End Sensor Setup 59 | //////////////////////////////////////////////////////////// 60 | 61 | //////////////////////////////////////////////////////////// 62 | // Begin SIGFOX Module Setup 63 | 64 | String result = ""; 65 | // Enter command mode. 66 | Serial.println(F("\nEntering command mode...")); 67 | transceiver.enterCommandMode(); 68 | 69 | if (useEmulator) { 70 | // Emulation mode. 71 | transceiver.enableEmulator(result); 72 | } else { 73 | // Disable emulation mode. 74 | Serial.println(F("\nDisabling emulation mode...")); 75 | transceiver.disableEmulator(result); 76 | 77 | // Check whether emulator is used for transmission. 78 | Serial.println(F("\nChecking emulation mode (expecting 0)...")); int emulator = 0; 79 | transceiver.getEmulator(emulator); 80 | } 81 | 82 | // Set the frequency of SIGFOX module to SG/TW. 83 | Serial.println(F("\nSetting frequency...")); result = ""; 84 | transceiver.setFrequencySG(result); 85 | Serial.print(F("Set frequency result = ")); Serial.println(result); 86 | 87 | // Get and display the frequency used by the SIGFOX module. Should return 3 for RCZ4 (SG/TW). 88 | Serial.println(F("\nGetting frequency (expecting 3)...")); String frequency = ""; 89 | transceiver.getFrequency(frequency); 90 | Serial.print(F("Frequency (expecting 3) = ")); Serial.println(frequency); 91 | 92 | // Read SIGFOX ID and PAC from module. 93 | Serial.println(F("\nGetting SIGFOX ID...")); String id = "", pac = ""; 94 | if (transceiver.getID(id, pac)) { 95 | Serial.print(F("SIGFOX ID = ")); Serial.println(id); 96 | Serial.print(F("PAC = ")); Serial.println(pac); 97 | } else { 98 | Serial.println(F("ID KO")); 99 | } 100 | 101 | // Exit command mode and prepare to send message. 102 | transceiver.exitCommandMode(); 103 | 104 | // End SIGFOX Module Setup 105 | //////////////////////////////////////////////////////////// 106 | } 107 | 108 | void loop() 109 | { 110 | //////////////////////////////////////////////////////////// 111 | // Begin Sensor Loop 112 | 113 | // Reading temperature or humidity takes about 250 milliseconds! 114 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 115 | float tmp = dht.readTemperature(); 116 | float hmd = dht.readHumidity(); 117 | Message msg(transceiver); // Will contain the structured sensor data. 118 | 119 | // Check if returns are valid, if they are NaN (not a number) then something went wrong! 120 | if (isnan(tmp) || isnan(hmd)) { 121 | Serial.println(F("Failed to read from sensor")); 122 | msg.addField("err", 1); // 4 bytes 123 | } else { 124 | Serial.print(F("Temperature: ")); Serial.println(tmp); 125 | Serial.print(F("Humidity:")); Serial.println(hmd); 126 | 127 | // Convert the numeric temperature and humidity to binary fields. 128 | // Field names must have 3 letters, no digits. Field names occupy 2 bytes. 129 | // Numeric fields occupy 2 bytes, with 1 decimal place. 130 | msg.addField("tmp", tmp); // 4 bytes 131 | msg.addField("hmd", hmd); // 4 bytes 132 | // Total 8 bytes out of 12 bytes used. 133 | } 134 | 135 | // End Sensor Loop 136 | //////////////////////////////////////////////////////////// 137 | 138 | //////////////////////////////////////////////////////////// 139 | // Begin SIGFOX Module Loop 140 | 141 | // Send the message. 142 | Serial.print(F("\n>> Device sending message ")); Serial.print(msg.getEncodedMessage() + "..."); 143 | transceiver.echoOn(); 144 | if (msg.send()) { 145 | Serial.println(F("Message sent")); 146 | } else { 147 | Serial.println(F("Message not sent")); 148 | } 149 | 150 | // End SIGFOX Module Loop 151 | //////////////////////////////////////////////////////////// 152 | 153 | // Wait a while before looping. 10000 milliseconds = 10 seconds. 154 | delay(10000); 155 | } 156 | 157 | /* 158 | Expected output: 159 | 160 | Demo sketch for Akeru library :) 161 | Temperature: 162 | 28.00 163 | Humidity: 164 | 44.00 165 | msg: 166 | t:28,h:44 167 | 168 | >> AT$SS=743a32382c683a3434 169 | << 170 | OK 171 | 172 | Message sent ! 173 | Temperature: 174 | 28.00 175 | Humidity: 176 | 44.00 177 | msg: 178 | t:28,h:44 179 | 180 | >> AT$SS=743a32382c683a3434 181 | << 182 | OK 183 | 184 | Message sent ! 185 | */ 186 | -------------------------------------------------------------------------------- /examples/send-test/send-test.ino: -------------------------------------------------------------------------------- 1 | /* 2 | This sample sketch is being updated. Meanwhile please refer to 3 | https://github.com/UnaBiz/unabiz-arduino/tree/master/examples/send-light-level 4 | */ 5 | -------------------------------------------------------------------------------- /examples/send-test/send-test.old: -------------------------------------------------------------------------------- 1 | // Send test sensor data to the SIGFOX cloud. 2 | 3 | //////////////////////////////////////////////////////////// 4 | // Begin Sensor Declaration 5 | 6 | // End Sensor Declaration 7 | //////////////////////////////////////////////////////////// 8 | 9 | //////////////////////////////////////////////////////////// 10 | // Begin SIGFOX Module Declaration 11 | 12 | #include "SIGFOX.h" 13 | 14 | // IMPORTANT: Check these settings with UnaBiz to use the right SIGFOX library. 15 | const bool useEmulator = false; // Set to true if using UnaBiz Emulator. 16 | // Akeru transceiver; // Uncomment this for UnaBiz Akene Dev Kit. Default to pin D4 for receive, pin D5 for transmit. 17 | Radiocrafts transceiver; // Uncomment this for UnaBiz Radiocrafts Dev Kit. Default to pin D4 for transmit, pin D5 for receive. 18 | 19 | // End SIGFOX Module Declaration 20 | //////////////////////////////////////////////////////////// 21 | 22 | void setup() 23 | { 24 | //////////////////////////////////////////////////////////// 25 | // Begin General Setup 26 | 27 | // Initialize console serial communication at 9600 bits per second: 28 | Serial.begin(9600); 29 | Serial.println(F("Demo sketch for sending test sensor values to SIGFOX cloud :)")); 30 | 31 | // End General Setup 32 | //////////////////////////////////////////////////////////// 33 | 34 | //////////////////////////////////////////////////////////// 35 | // Begin Sensor Setup 36 | 37 | // End Sensor Setup 38 | //////////////////////////////////////////////////////////// 39 | 40 | //////////////////////////////////////////////////////////// 41 | // Begin SIGFOX Module Setup 42 | 43 | String result = ""; 44 | // Enter command mode. 45 | Serial.println(F("\nEntering command mode...")); 46 | transceiver.enterCommandMode(); 47 | 48 | if (useEmulator) { 49 | // Emulation mode. 50 | transceiver.enableEmulator(result); 51 | } else { 52 | // Disable emulation mode. 53 | Serial.println(F("\nDisabling emulation mode...")); 54 | transceiver.disableEmulator(result); 55 | 56 | // Check whether emulator is used for transmission. 57 | Serial.println(F("\nChecking emulation mode (expecting 0)...")); int emulator = 0; 58 | transceiver.getEmulator(emulator); 59 | } 60 | 61 | // Set the frequency of SIGFOX module to SG/TW. 62 | Serial.println(F("\nSetting frequency...")); result = ""; 63 | transceiver.setFrequencySG(result); 64 | Serial.print(F("Set frequency result = ")); Serial.println(result); 65 | 66 | // Get and display the frequency used by the SIGFOX module. Should return 3 for RCZ4 (SG/TW). 67 | Serial.println(F("\nGetting frequency (expecting 3)...")); String frequency = ""; 68 | transceiver.getFrequency(frequency); 69 | Serial.print(F("Frequency (expecting 3) = ")); Serial.println(frequency); 70 | 71 | // Read SIGFOX ID and PAC from module. 72 | Serial.println(F("\nGetting SIGFOX ID...")); String id = "", pac = ""; 73 | if (transceiver.getID(id, pac)) { 74 | Serial.print(F("SIGFOX ID = ")); Serial.println(id); 75 | Serial.print(F("PAC = ")); Serial.println(pac); 76 | } else { 77 | Serial.println(F("ID KO")); 78 | } 79 | 80 | // Exit command mode and prepare to send message. 81 | transceiver.exitCommandMode(); 82 | 83 | // End SIGFOX Module Setup 84 | //////////////////////////////////////////////////////////// 85 | } 86 | 87 | void loop() 88 | { 89 | //////////////////////////////////////////////////////////// 90 | // Begin Sensor Loop 91 | 92 | // Prepare sample sensor data. Must not exceed 12 characters. 93 | // Convert the numeric temperature and humidity to binary fields. 94 | // Field names must have 3 letters, no digits. Field names occupy 2 bytes. 95 | // Numeric fields occupy 2 bytes, with 1 decimal place. 96 | Message msg(transceiver); // Will contain the structured sensor data. 97 | msg.addField("tmp", 30.1); // 4 bytes 98 | msg.addField("hmd", 98.7); // 4 bytes 99 | // Total 8 bytes out of 12 bytes used. 100 | 101 | // End Sensor Loop 102 | //////////////////////////////////////////////////////////// 103 | 104 | //////////////////////////////////////////////////////////// 105 | // Begin SIGFOX Module Loop 106 | 107 | // Send sensor data. 108 | // Send the message. 109 | Serial.print(F("\n>> Device sending message ")); Serial.print(msg.getEncodedMessage() + "..."); 110 | if (msg.send()) { 111 | Serial.println(F("Message sent")); 112 | } else { 113 | Serial.println(F("Message not sent")); 114 | } 115 | 116 | // End SIGFOX Module Loop 117 | //////////////////////////////////////////////////////////// 118 | 119 | // Wait a while before looping. 10000 milliseconds = 10 seconds. 120 | delay(10000); 121 | } 122 | 123 | /* 124 | Expected output: 125 | 126 | Message sent ! 127 | */ 128 | -------------------------------------------------------------------------------- /examples/temperature-sensor/temperature-sensor.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /*************************************************************************** 4 | This is a library for the BME280 humidity, temperature & pressure sensor 5 | Mike Nguyen (Vinova) Mike Nguyen (Vinova) 6 | Designed specifically to work with the Adafruit BME280 Breakout 7 | ----> http://www.adafruit.com/products/2650 8 | 9 | These sensors use I2C or SPI to communicate, 2 or 4 pins are required 10 | to interface. 11 | 12 | Adafruit invests time and resources providing this open source code, 13 | please support Adafruit andopen-source hardware by purchasing products 14 | from Adafruit! 15 | 16 | Written by Limor Fried & Kevin Townsend for Adafruit Industries. 17 | BSD license, all text above must be included in any redistribution 18 | ***************************************************************************/ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define BME_SCK 13 26 | #define BME_MISO 12 27 | #define BME_MOSI 11 28 | #define BME_CS 10 29 | 30 | #define SEALEVELPRESSURE_HPA (1013.25) 31 | 32 | Adafruit_BME280 bme; // I2C 33 | //Adafruit_BME280 bme(BME_CS); // hardware SPI 34 | //Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); 35 | 36 | void setup() { 37 | Serial.begin(9600); 38 | Serial.println(F("BME280 test")); 39 | 40 | if (!bme.begin(0x76)) { //// NOTE: Must use 0x76 for UnaShield V2S 41 | Serial.println("Could not find a valid BME280 sensor, check wiring!"); 42 | while (1); 43 | } 44 | } 45 | 46 | void loop() { 47 | Serial.print("Temperature = "); 48 | Serial.print(bme.readTemperature()); 49 | Serial.println(" *C"); 50 | 51 | Serial.print("Pressure = "); 52 | 53 | Serial.print(bme.readPressure() / 100.0F); 54 | Serial.println(" hPa"); 55 | 56 | Serial.print("Approx. Altitude = "); 57 | Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); 58 | Serial.println(" m"); 59 | 60 | Serial.print("Humidity = "); 61 | Serial.print(bme.readHumidity()); 62 | Serial.println(" %"); 63 | 64 | Serial.println(); 65 | delay(2000); 66 | } 67 | 68 | /* 69 | BME280 test 70 | Temperature = 21.95 *C 71 | Pressure = 646.19 hPa 72 | Approx. Altitude = 3636.79 m 73 | Humidity = 78.81 % 74 | 75 | Temperature = 27.42 *C 76 | Pressure = 1002.60 hPa 77 | Approx. Altitude = 89.02 m 78 | Humidity = 55.44 % 79 | 80 | Temperature = 27.44 *C 81 | Pressure = 1002.62 hPa 82 | Approx. Altitude = 88.84 m 83 | Humidity = 55.46 % 84 | 85 | Temperature = 27.46 *C 86 | Pressure = 1002.65 hPa 87 | Approx. Altitude = 88.67 m 88 | Humidity = 55.55 % 89 | 90 | Temperature = 27.47 *C 91 | Pressure = 1002.63 hPa 92 | Approx. Altitude = 88.77 m 93 | Humidity = 55.47 % 94 | 95 | Temperature = 27.48 *C 96 | Pressure = 1002.61 hPa 97 | Approx. Altitude = 88.98 m 98 | Humidity = 55.69 % 99 | 100 | Temperature = 27.50 *C 101 | Pressure = 1002.61 hPa 102 | Approx. Altitude = 88.94 m 103 | Humidity = 55.69 % 104 | 105 | Temperature = 27.51 *C 106 | Pressure = 1002.65 hPa 107 | Approx. Altitude = 88.66 m 108 | Humidity = 55.28 % 109 | 110 | Temperature = 27.51 *C 111 | Pressure = 1002.66 hPa 112 | Approx. Altitude = 88.57 m 113 | Humidity = 54.98 % 114 | 115 | Temperature = 27.52 *C 116 | Pressure = 1002.63 hPa 117 | Approx. Altitude = 88.83 m 118 | Humidity = 54.81 % 119 | 120 | Temperature = 27.53 *C 121 | Pressure = 1002.61 hPa 122 | Approx. Altitude = 88.97 m 123 | Humidity = 54.72 % 124 | 125 | Temperature = 27.54 *C 126 | Pressure = 1002.62 hPa 127 | Approx. Altitude = 88.87 m 128 | Humidity = 54.68 % 129 | 130 | Temperature = 27.54 *C 131 | Pressure = 1002.61 hPa 132 | Approx. Altitude = 88.99 m 133 | Humidity = 54.62 % 134 | 135 | Temperature = 27.55 *C 136 | Pressure = 1002.60 hPa 137 | Approx. Altitude = 89.07 m 138 | Humidity = 54.62 % 139 | 140 | Temperature = 27.56 *C 141 | Pressure = 1002.60 hPa 142 | Approx. Altitude = 89.02 m 143 | Humidity = 54.69 % 144 | 145 | Temperature = 27.57 *C 146 | Pressure = 1002.59 hPa 147 | Approx. Altitude = 89.16 m 148 | Humidity = 54.69 % 149 | 150 | Temperature = 27.58 *C 151 | Pressure = 1002.60 hPa 152 | Approx. Altitude = 89.02 m 153 | Humidity = 54.67 % 154 | 155 | Temperature = 27.58 *C 156 | Pressure = 1002.62 hPa 157 | Approx. Altitude = 88.87 m 158 | Humidity = 54.63 % 159 | 160 | Temperature = 27.58 *C 161 | Pressure = 1002.63 hPa 162 | Approx. Altitude = 88.82 m 163 | Humidity = 54.63 % 164 | 165 | Temperature = 27.58 *C 166 | Pressure = 1002.63 hPa 167 | Approx. Altitude = 88.79 m 168 | Humidity = 54.71 % 169 | 170 | Temperature = 27.59 *C 171 | Pressure = 1002.65 hPa 172 | Approx. Altitude = 88.60 m 173 | Humidity = 54.75 % 174 | 175 | Temperature = 27.60 *C 176 | Pressure = 1002.63 hPa 177 | Approx. Altitude = 88.76 m 178 | Humidity = 54.77 % 179 | 180 | Temperature = 27.60 *C 181 | Pressure = 1002.63 hPa 182 | Approx. Altitude = 88.79 m 183 | Humidity = 54.70 % 184 | 185 | Temperature = 27.60 *C 186 | Pressure = 1002.66 hPa 187 | Approx. Altitude = 88.73 m 188 | Humidity = 54.68 % 189 | 190 | Temperature = 27.61 *C 191 | Pressure = 1002.64 hPa 192 | Approx. Altitude = 88.68 m 193 | Humidity = 54.65 % 194 | 195 | Temperature = 27.62 *C 196 | Pressure = 1002.65 hPa 197 | Approx. Altitude = 88.62 m 198 | Humidity = 54.59 % 199 | 200 | Temperature = 27.63 *C 201 | Pressure = 1002.65 hPa 202 | Approx. Altitude = 88.61 m 203 | Humidity = 54.58 % 204 | 205 | Temperature = 27.63 *C 206 | Pressure = 1002.61 hPa 207 | Approx. Altitude = 89.00 m 208 | Humidity = 54.78 % 209 | 210 | Temperature = 27.62 *C 211 | Pressure = 1002.62 hPa 212 | Approx. Altitude = 88.89 m 213 | Humidity = 54.97 % 214 | 215 | Temperature = 27.63 *C 216 | Pressure = 1002.65 hPa 217 | Approx. Altitude = 88.63 m 218 | Humidity = 54.95 % 219 | 220 | Temperature = 27.63 *C 221 | Pressure = 1002.64 hPa 222 | Approx. Altitude = 88.68 m 223 | Humidity = 54.85 % 224 | 225 | Temperature = 27.63 *C 226 | Pressure = 1002.63 hPa 227 | Approx. Altitude = 88.77 m 228 | Humidity = 54.85 % 229 | 230 | Temperature = 27.64 *C 231 | Pressure = 1002.62 hPa 232 | Approx. Altitude = 88.88 m 233 | Humidity = 54.89 % 234 | 235 | Temperature = 27.64 *C 236 | Pressure = 1002.62 hPa 237 | Approx. Altitude = 88.91 m 238 | Humidity = 54.93 % 239 | 240 | Temperature = 27.64 *C 241 | Pressure = 1002.61 hPa 242 | Approx. Altitude = 88.99 m 243 | Humidity = 54.92 % 244 | 245 | Temperature = 27.64 *C 246 | Pressure = 1002.62 hPa 247 | Approx. Altitude = 88.91 m 248 | Humidity = 54.88 % 249 | 250 | Temperature = 27.64 *C 251 | Pressure = 1002.63 hPa 252 | Approx. Altitude = 88.82 m 253 | Humidity = 54.86 % 254 | 255 | Temperature = 27.65 *C 256 | Pressure = 1002.62 hPa 257 | Approx. Altitude = 88.85 m 258 | Humidity = 54.81 % 259 | 260 | Temperature = 27.66 *C 261 | Pressure = 1002.59 hPa 262 | Approx. Altitude = 89.09 m 263 | Humidity = 54.80 % 264 | 265 | Temperature = 27.66 *C 266 | Pressure = 1002.61 hPa 267 | Approx. Altitude = 88.97 m 268 | Humidity = 54.95 % 269 | 270 | Temperature = 27.66 *C 271 | Pressure = 1002.65 hPa 272 | Approx. Altitude = 88.67 m 273 | Humidity = 54.95 % 274 | 275 | Temperature = 27.65 *C 276 | Pressure = 1002.63 hPa 277 | Approx. Altitude = 88.78 m 278 | Humidity = 54.99 % 279 | 280 | Temperature = 27.67 *C 281 | Pressure = 1002.64 hPa 282 | Approx. Altitude = 88.70 m 283 | Humidity = 55.07 % 284 | 285 | Temperature = 27.67 *C 286 | Pressure = 1002.61 hPa 287 | Approx. Altitude = 88.93 m 288 | Humidity = 54.97 % 289 | 290 | Temperature = 27.66 *C 291 | Pressure = 1002.63 hPa 292 | Approx. Altitude = 88.79 m 293 | Humidity = 54.91 % 294 | 295 | Temperature = 27.66 *C 296 | Pressure = 1002.65 hPa 297 | Approx. Altitude = 88.61 m 298 | Humidity = 54.86 % 299 | 300 | Temperature = 27.67 *C 301 | Pressure = 1002.65 hPa 302 | Approx. Altitude = 88.66 m 303 | Humidity = 54.72 % 304 | 305 | Temperature = 27.67 *C 306 | Pressure = 1002.64 hPa 307 | Approx. Altitude = 88.71 m 308 | Humidity = 54.67 % 309 | 310 | Temperature = 27.68 *C 311 | Pressure = 1002.62 hPa 312 | Approx. Altitude = 88.86 m 313 | Humidity = 54.45 % 314 | 315 | Temperature = 27.68 *C 316 | Pressure = 1002.61 hPa 317 | Approx. Altitude = 88.95 m 318 | Humidity = 54.50 % 319 | 320 | Temperature = 27.67 *C 321 | Pressure = 1002.59 hPa 322 | Approx. Altitude = 89.15 m 323 | Humidity = 54.66 % 324 | 325 | Temperature = 27.67 *C 326 | Pressure = 1002.62 hPa 327 | Approx. Altitude = 88.86 m 328 | Humidity = 54.68 % 329 | 330 | Temperature = 27.67 *C 331 | Pressure = 1002.60 hPa 332 | Approx. Altitude = 89.01 m 333 | Humidity = 54.55 % 334 | 335 | Temperature = 27.68 *C 336 | Pressure = 1002.59 hPa 337 | Approx. Altitude = 89.11 m 338 | Humidity = 54.51 % 339 | 340 | Temperature = 27.68 *C 341 | Pressure = 1002.62 hPa 342 | Approx. Altitude = 88.89 m 343 | Humidity = 54.42 % 344 | 345 | Temperature = 27.68 *C 346 | Pressure = 1002.63 hPa 347 | Approx. Altitude = 88.84 m 348 | Humidity = 54.33 % 349 | 350 | Temperature = 27.69 *C 351 | Pressure = 1002.62 hPa 352 | Approx. Altitude = 88.85 m 353 | Humidity = 54.36 % 354 | 355 | */ 356 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map Akeru 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Akeru KEYWORD1 10 | Akene KEYWORD1 11 | 12 | ####################################### 13 | # Methods and Functions (KEYWORD2) 14 | ####################################### 15 | 16 | echoOn KEYWORD2 17 | echoOff KEYWORD2 18 | begin KEYWORD2 19 | isReady KEYWORD2 20 | sendAT KEYWORD2 21 | sendPayload KEYWORD2 22 | getTemperature KEYWORD2 23 | getID KEYWORD2 24 | getVoltage KEYWORD2 25 | getHardware KEYWORD2 26 | getFirmware KEYWORD2 27 | getPower KEYWORD2 28 | setPower KEYWORD2 29 | receive KEYWORD2 30 | toHex KEYWORD2 31 | 32 | ####################################### 33 | # Constants (LITERAL1) 34 | ####################################### 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Unabiz Arduino 2 | version=1.0.0 3 | author=UnaBiz 4 | maintainer=UnaBiz 5 | sentence=Arduino library for connecting UnaShield to SIGFOX network 6 | paragraph=Arduino library for connecting UnaShield to SIGFOX network https://unabiz.github.io/unashield/ 7 | category=Communication 8 | url=https://github.com/UnaBiz/unabiz-arduino 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/Akeru.h: -------------------------------------------------------------------------------- 1 | /* Akeru.h - v4 [2016.07.29] 2 | * 3 | * Copyleft Snootlab 2016 - inspired by TD1208 lib by IoTHerd (C) 2016 4 | * 5 | * Akeru is a library for Sigfox TD1208 use with the Arduino platform. 6 | * The library is designed to use SoftwareSerial library for serial communication between TD1208 module and Arduino. 7 | * Current library coverage is: 8 | * - AT command 9 | * - Sigfox payload transfer 10 | * - TD1208 temperature read 11 | * - TD1208 ID read 12 | * - TD1208 supply voltage read 13 | * - TD1208 hardware version read 14 | * - TD1208 firmware version read 15 | * - TD1208 power read 16 | * - TD1208 power set 17 | * - TD1208 downlink request 18 | * - Data conversion in hexadecimal 19 | */ 20 | 21 | #ifndef BEAN_BEAN_BEAN_H // Not supported on Bean+ 22 | #ifndef AKERU_H 23 | #define AKERU_H 24 | 25 | #ifdef ARDUINO 26 | #if (ARDUINO >= 100) 27 | #include 28 | #else // ARDUINO >= 100 29 | #include 30 | #endif // ARDUINO >= 100 31 | 32 | #ifdef CLION 33 | #include 34 | #else // CLION 35 | #if defined(ARDUINO_ARCH_SAMD) 36 | // SAMD boards do not have a standard SoftwareSerial library, but we can 37 | // import a 3rd party one 38 | #include "SamdSoftwareSerial.h" 39 | #elif defined(BEAN_BEAN_BEAN_H) 40 | // Bean+ firmware 0.6.1 can't receive serial data properly. We provide 41 | // an alternative class BeanSoftwareSerial to work around this. 42 | // See SIGFOX.h. 43 | #else 44 | #include 45 | #endif // BEAN_BEAN_BEAN_H 46 | #endif // CLION 47 | 48 | #else // ARDUINO 49 | #endif // ARDUINO 50 | 51 | #define ATOK "OK" 52 | #define ATCOMMAND "AT" 53 | #define ATID "ATI7" 54 | #define ATHARDWARE "ATI11" 55 | #define ATFIRMWARE "ATI13" 56 | #define ATTEMPERATURE "ATI26" 57 | #define ATVOLTAGE "ATI27" 58 | #define ATPOWER "ATS302" 59 | #define ATDOWNLINK "AT$SB=1,2,1" 60 | #define ATSIGFOXTX "AT$SS=" 61 | #define ATTDLANTX "AT$SL=" 62 | #define DOWNLINKEND "+RX END" 63 | 64 | const unsigned int AKERU_RX = 4; // Receive port for UnaBiz / Akene Dev Kit 65 | const unsigned int AKERU_TX = 5; // Transmit port for UnaBiz / Akene Dev Kit 66 | 67 | // Set frequency of the SIGFOX module to Singapore and Taiwan (920.8 MHz): 68 | #define ATSET_FREQUENCY_SG "AT$IF=920800000" 69 | 70 | // Set frequency of the SIGFOX module to ETSI (Europe, 868.2 MHz): 71 | #define ATSET_FREQUENCY_ETSI "AT$IF=868200000" 72 | 73 | // Get frequency used by the SIGFOX module. 74 | #define ATGET_FREQUENCY "AT$IF?" 75 | 76 | // Write settings to Flash memory of the SIGFOX module. 77 | #define ATWRITE_SETTINGS "AT&W" 78 | 79 | // Reboot the SIGFOX module. 80 | #define ATREBOOT "ATZ" 81 | 82 | #define ATMODEL "ATI0" // Get manufacturer and model. 83 | #define ATRELEASE "ATI5" // Get firmware release date. 84 | #define ATBASEBAND "ATI10" // Get baseband unique ID. 85 | #define ATRF_PART "ATI21" // Get RF chip part number. 86 | #define ATRF_REVISION "ATI25" // Get RF chip revision number. 87 | #define ATPOWER_ACTIVE "ATI28" // Get module RF active power supply voltage 88 | #define ATLIBRARY "ATI30" // Get RF library version. 89 | 90 | #define ATCOMMAND_TIMEOUT (3000) 91 | #define ATSIGFOXTX_TIMEOUT (30000) 92 | #define ATDOWNLINK_TIMEOUT (45000) 93 | 94 | // Set to 1 if you want to print the AT commands and answers 95 | // on the serial monitor, set to 0 otherwise. 96 | //#define _cmdEcho 1 97 | 98 | class Akeru 99 | { 100 | public: 101 | Akeru(); 102 | Akeru(unsigned int rx, unsigned int tx); 103 | bool begin(); 104 | void echoOn(); // Turn on send/receive echo. 105 | void echoOff(); // Turn off send/receive echo. 106 | void setEchoPort(Print *port); // Set the port for sending echo output. 107 | void echo(String msg); // Echo the debug message. 108 | bool isReady(); 109 | bool sendMessage(const String payload); // Send the payload of hex digits to the network, max 12 bytes. 110 | bool sendString(const String str); // Sending a text string, max 12 characters allowed. 111 | bool receive(String &data); // Receive a message. 112 | bool enterCommandMode() {} // Enter Command Mode for sending module commands, not data. 113 | bool exitCommandMode() {} // Exit Command Mode so we can send data. 114 | 115 | // Commands for the module, must be run in Command Mode. 116 | bool getEmulator(int &result) // Return 0 if emulator mode disabled, else return 1. 117 | { result = _emulationMode ? 1 : 0; return true; } 118 | bool enableEmulator(String &result); // Enable emulator mode. 119 | bool disableEmulator(String &result); // Disable emulator mode. 120 | // Get the frequency used for the SIGFOX module. 121 | bool getFrequency(String &result); 122 | // Set the frequency for the SIGFOX module to Singapore frequency (RCZ4). 123 | bool setFrequencySG(String &result); 124 | // Set the frequency for the SIGFOX module to Taiwan frequency (RCZ4). 125 | bool setFrequencyTW(String &result); 126 | // Set the frequency for the SIGFOX module to ETSI frequency for Europe (RCZ1). 127 | bool setFrequencyETSI(String &result); 128 | // Set the frequency for the SIGFOX module to US frequency (RCZ2). 129 | bool setFrequencyUS(String &result); 130 | bool writeSettings(String &result); // Write frequency and other settings to flash memory of the module. 131 | bool reboot(String &result); // Reboot the SIGFOX module. 132 | bool getTemperature(int &temperature); 133 | bool getID(String &id, String &pac); // Get the SIGFOX ID and PAC for the module. 134 | bool getVoltage(float &voltage); 135 | bool getHardware(String &hardware); 136 | bool getFirmware(String &firmware); 137 | bool getPower(int &power); 138 | bool setPower(int power); 139 | bool getParameter(uint8_t address, String &value) { 140 | // Return the parameter at that address. Not used for Akene. 141 | value = ""; 142 | return false; 143 | } 144 | 145 | // Message conversion functions. 146 | String toHex(int i); 147 | String toHex(unsigned int i); 148 | String toHex(long l); 149 | String toHex(unsigned long ul); 150 | String toHex(float f); 151 | String toHex(double d); 152 | String toHex(char c); 153 | String toHex(char *c, int length); 154 | 155 | bool getModel(String &model); // Get manufacturer and model. 156 | bool getRelease(String &release); // Get firmware release date. 157 | bool getBaseband(String &baseband); // Get baseband unique ID. 158 | bool getRFPart(String &part); // Get RF chip part number. 159 | bool getRFRevision(String &revision); // Get RF chip revision number. 160 | bool getPowerActive(String &power); // Get module RF active power supply voltage 161 | bool getLibraryVersion(String &version); // Get RF library version. 162 | 163 | private: 164 | bool sendAT(); 165 | bool sendATCommand(const String command, const int timeout, String &dataOut); 166 | SoftwareSerial* serialPort; 167 | Print *echoPort; // Port for sending echo output. Defaults to Serial. 168 | Print *lastEchoPort; // Last port used for sending echo output. 169 | bool _emulationMode = false; // True if using emulation (TD LAN) mode. 170 | unsigned long _lastSend; // Timestamp of last send. 171 | unsigned int _sequenceNumber; // Sequence number for the message. 172 | String _id = ""; // SIGFOX device ID. 173 | String _pac = ""; // SIGFOX PAC. 174 | }; 175 | 176 | #endif // AKERU_H 177 | #endif // BEAN_BEAN_BEAN_H // Not supported on Bean+ 178 | -------------------------------------------------------------------------------- /src/BeanSoftwareSerial.h: -------------------------------------------------------------------------------- 1 | // Bean+ firmware 0.6.1 can't receive serial data properly. We provide 2 | // an alternative class BeanSoftwareSerial to work around this. 3 | // Fixes the interrupt handlers used by SoftwareSerial. Based on 4 | // http://beantalk.punchthrough.com/t/rfidd-bean-pronounced-refried-bean/1776 5 | /* 6 | SoftwareSerial.h (formerly NewSoftSerial.h) - 7 | Multi-instance software serial library for Arduino/Wiring 8 | -- Interrupt-driven receive and other improvements by ladyada 9 | (http://ladyada.net) 10 | -- Tuning, circular buffer, derivation from class Print/Stream, 11 | multi-instance support, porting to 8MHz processors, 12 | various optimizations, PROGMEM delay tables, inverse logic and 13 | direct port writing by Mikal Hart (http://www.arduiniana.org) 14 | -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com) 15 | -- 20MHz processor support by Garrett Mace (http://www.macetech.com) 16 | -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/) 17 | 18 | This library is free software; you can redistribute it and/or 19 | modify it under the terms of the GNU Lesser General Public 20 | License as published by the Free Software Foundation; either 21 | version 2.1 of the License, or (at your option) any later version. 22 | 23 | This library is distributed in the hope that it will be useful, 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 26 | Lesser General Public License for more details. 27 | 28 | You should have received a copy of the GNU Lesser General Public 29 | License along with this library; if not, write to the Free Software 30 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 31 | 32 | The latest version of this library can always be found at 33 | http://arduiniana.org. 34 | */ 35 | 36 | #ifdef BEAN_BEAN_BEAN_H // Only used by Bean to fix Serial receive issue. 37 | 38 | #ifndef BeanSoftwareSerial_h 39 | #define BeanSoftwareSerial_h 40 | 41 | #include 42 | #include 43 | 44 | /****************************************************************************** 45 | * Definitions 46 | ******************************************************************************/ 47 | 48 | #define _SS_MAX_RX_BUFF 64 // RX buffer size 49 | #ifndef GCC_VERSION 50 | #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 51 | #endif 52 | 53 | class BeanSoftwareSerial : public Stream 54 | { 55 | private: 56 | // per object data 57 | uint8_t _receivePin; 58 | uint8_t _receiveBitMask; 59 | volatile uint8_t *_receivePortRegister; 60 | uint8_t _transmitBitMask; 61 | volatile uint8_t *_transmitPortRegister; 62 | volatile uint8_t *_pcint_maskreg; 63 | uint8_t _pcint_maskvalue; 64 | 65 | // Expressed as 4-cycle delays (must never be 0!) 66 | uint16_t _rx_delay_centering; 67 | uint16_t _rx_delay_intrabit; 68 | uint16_t _rx_delay_stopbit; 69 | uint16_t _tx_delay; 70 | 71 | uint16_t _buffer_overflow:1; 72 | uint16_t _inverse_logic:1; 73 | 74 | // static data 75 | static char _receive_buffer[_SS_MAX_RX_BUFF]; 76 | static volatile uint8_t _receive_buffer_tail; 77 | static volatile uint8_t _receive_buffer_head; 78 | static BeanSoftwareSerial *active_object; 79 | 80 | // private methods 81 | void recv() __attribute__((__always_inline__)); 82 | uint8_t rx_pin_read(); 83 | void tx_pin_write(uint8_t pin_state) __attribute__((__always_inline__)); 84 | void setTX(uint8_t transmitPin); 85 | void setRX(uint8_t receivePin); 86 | void setRxIntMsk(bool enable) __attribute__((__always_inline__)); 87 | 88 | // Return num - sub, or 1 if the result would be < 1 89 | static uint16_t subtract_cap(uint16_t num, uint16_t sub); 90 | 91 | // private static method for timing 92 | static inline void tunedDelay(uint16_t delay); 93 | 94 | public: 95 | // public methods 96 | BeanSoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false); 97 | ~BeanSoftwareSerial(); 98 | void begin(long speed); 99 | bool listen(); 100 | void end(); 101 | bool isListening() { return this == active_object; } 102 | bool stopListening(); 103 | bool overflow() { bool ret = _buffer_overflow; if (ret) _buffer_overflow = false; return ret; } 104 | int peek(); 105 | 106 | virtual size_t write(uint8_t byte); 107 | virtual int read(); 108 | virtual int available(); 109 | virtual void flush(); 110 | operator bool() { return true; } 111 | 112 | using Print::write; 113 | 114 | // public only for easy access by interrupt handlers 115 | static inline void handle_interrupt() __attribute__((__always_inline__)); 116 | }; 117 | 118 | // Arduino 0012 workaround 119 | #undef int 120 | #undef char 121 | #undef long 122 | #undef byte 123 | #undef float 124 | #undef abs 125 | #undef round 126 | 127 | #endif 128 | 129 | #endif // BEAN_BEAN_BEAN_H 130 | -------------------------------------------------------------------------------- /src/Message.cpp: -------------------------------------------------------------------------------- 1 | // Library for sending and receiving structured SIGFOX messages 2 | #ifdef ARDUINO 3 | #if (ARDUINO >= 100) 4 | #include 5 | #else // ARDUINO >= 100 6 | #include 7 | #endif // ARDUINO >= 100 8 | #endif // ARDUINO 9 | 10 | #include "SIGFOX.h" 11 | #include "Message.h" 12 | 13 | // Encode each letter (lowercase only) in 5 bits: 14 | // 0 = End of name/value or can't be encoded. 15 | // 1 = a, 2 = b, ..., 26 = z, 16 | // 27 = 0, 28 = 1, ..., 31 = 4 17 | // 5 to 9 cannot be encoded. 18 | 19 | static const uint8_t firstLetter = 1; 20 | static const uint8_t firstDigit = 27; 21 | 22 | static uint8_t encodeLetter(char ch) { 23 | // Convert character ch to the 5-bit equivalent. 24 | // Convert to lowercase. 25 | if (ch >= 'A' && ch <= 'Z') ch = ch - 'A' + 'a'; 26 | if (ch >= 'a' && ch <= 'z') return ch - 'a' + firstLetter; 27 | // For 1, 2, ... return the digit 28 | if (ch >= '0' && ch <= '4') return (ch - '0') + 27; 29 | // Can't encode. 30 | return 0; 31 | } 32 | 33 | static char decodeLetter(uint8_t code) { 34 | // Convert the 5-bit code to a letter. 35 | if (code == 0) return 0; 36 | if (code >= firstLetter && code < firstDigit) return code - firstLetter + 'a'; 37 | if (code >= firstDigit) return code - firstDigit + '0'; 38 | return 0; 39 | } 40 | 41 | static String doubleToString(double d) { 42 | // Convert double to string, since Bean+ doesn't support double in Strings. 43 | // Assume 1 decimal place. 44 | String result = String((int) (d)) + '.' + String(((int) (d * 10.0)) % 10); 45 | return result; 46 | } 47 | 48 | void Message::echo(String msg) { 49 | if (wisol) wisol->echo(msg); 50 | else if (radiocrafts) radiocrafts->echo(msg); 51 | } 52 | 53 | Message::Message(Radiocrafts &transceiver) { 54 | // Construct a message for Radiocrafts. 55 | radiocrafts = &transceiver; 56 | } 57 | 58 | Message::Message(Wisol &transceiver) { 59 | // Construct a message for Wisol. 60 | wisol = &transceiver; 61 | } 62 | 63 | // TODO: Move these messages to Flash memory. 64 | static String addFieldHeader = "Message.addField: "; 65 | static String tooLong = "****ERROR: Message too long, already "; 66 | 67 | bool Message::addField(const String name, int value) { 68 | // Add an integer field scaled by 10. 2 bytes. 69 | echo(addFieldHeader + name + '=' + value); 70 | int val = value * 10; 71 | return addIntField(name, val); 72 | } 73 | 74 | bool Message::addField(const String name, float value) { 75 | // Add a float field with 1 decimal place. 2 bytes. 76 | echo(addFieldHeader + name + '=' + doubleToString(value)); 77 | int val = (int) (value * 10.0); 78 | return addIntField(name, val); 79 | } 80 | 81 | bool Message::addField(const String name, double value) { 82 | // Add a double field with 1 decimal place. 2 bytes. 83 | echo(addFieldHeader + name + '=' + doubleToString(value)); 84 | int val = (int) (value * 10.0); 85 | return addIntField(name, val); 86 | } 87 | 88 | bool Message::addIntField(const String name, int value) { 89 | // Add an int field that is already scaled. 2 bytes for name, 2 bytes for value. 90 | if (encodedMessage.length() + (4 * 2) > MAX_BYTES_PER_MESSAGE * 2) { 91 | echo(tooLong + (encodedMessage.length() / 2) + " bytes"); 92 | return false; 93 | } 94 | addName(name); 95 | if (wisol) encodedMessage.concat(wisol->toHex(value)); 96 | else if (radiocrafts) encodedMessage.concat(radiocrafts->toHex(value)); 97 | return true; 98 | } 99 | 100 | bool Message::addField(const String name, const String value) { 101 | // Add a string field with max 3 chars. 2 bytes for name, 2 bytes for value. 102 | echo(addFieldHeader + name + '=' + value); 103 | if (encodedMessage.length() + (4 * 2) > MAX_BYTES_PER_MESSAGE * 2) { 104 | echo(tooLong + (encodedMessage.length() / 2) + " bytes"); 105 | return false; 106 | } 107 | addName(name); 108 | addName(value); 109 | return true; 110 | } 111 | 112 | bool Message::addName(const String name) { 113 | // Add the encoded field name with 3 letters. 114 | // 1 header bit + 5 bits for each letter, total 16 bits. 115 | // TODO: Assert name has 3 letters. 116 | // TODO: Assert encodedMessage is less than 12 bytes. 117 | // Convert 3 letters to 3 bytes. 118 | uint8_t buffer[] = {0, 0, 0}; 119 | for (int i = 0; i <= 2 && i <= name.length(); i++) { 120 | // 5 bits for each letter. 121 | char ch = name.charAt(i); 122 | buffer[i] = encodeLetter(ch); 123 | } 124 | // [x000] [0011] [1112] [2222] 125 | // [x012] [3401] [2340] [1234] 126 | unsigned int result = 127 | (buffer[0] << 10) + 128 | (buffer[1] << 5) + 129 | (buffer[2]); 130 | if (wisol) encodedMessage.concat(wisol->toHex(result)); 131 | else if (radiocrafts) encodedMessage.concat(radiocrafts->toHex(result)); 132 | return true; 133 | } 134 | 135 | bool Message::send() { 136 | // Send the encoded message to SIGFOX. 137 | String msg = getEncodedMessage(); 138 | if (msg.length() == 0) { 139 | echo("****ERROR: Nothing to send"); // TODO: Move to Flash. 140 | return false; 141 | } 142 | if (msg.length() > MAX_BYTES_PER_MESSAGE * 2) { 143 | echo(tooLong + (encodedMessage.length() / 2) + " bytes"); 144 | return false; 145 | } 146 | if (wisol) return wisol->sendMessage(msg); 147 | else if (radiocrafts) return radiocrafts->sendMessage(msg); 148 | return false; 149 | } 150 | 151 | bool Message::sendAndGetResponse(String &response) { 152 | // Send the structured message and get the downlink response. 153 | String msg = getEncodedMessage(); 154 | if (msg.length() == 0) { 155 | echo("****ERROR: Nothing to send"); // TODO: Move to Flash. 156 | return false; 157 | } 158 | if (msg.length() > MAX_BYTES_PER_MESSAGE * 2) { 159 | echo(tooLong + (encodedMessage.length() / 2) + " bytes"); 160 | return false; 161 | } 162 | if (wisol) return wisol->sendMessageAndGetResponse(msg, response); 163 | else if (radiocrafts) return radiocrafts->sendMessage(msg); 164 | return false; 165 | } 166 | 167 | String Message::getEncodedMessage() { 168 | // Return the encoded message to be transmitted. 169 | return encodedMessage; 170 | } 171 | 172 | static uint8_t hexDigitToDecimal(char ch) { 173 | // Convert 0..9, a..f, A..F to decimal. 174 | if (ch >= '0' && ch <= '9') return (uint8_t) ch - '0'; 175 | if (ch >= 'a' && ch <= 'z') return (uint8_t) ch - 'a' + 10; 176 | if (ch >= 'A' && ch <= 'Z') return (uint8_t) ch - 'A' + 10; 177 | return 0; 178 | } 179 | 180 | String Message::decodeMessage(String msg) { 181 | // Decode the encoded message. 182 | // 2 bytes name, 2 bytes float * 10, 2 bytes name, 2 bytes float * 10, ... 183 | String result = "{"; 184 | for (int i = 0; i < msg.length(); i = i + 8) { 185 | String name = msg.substring(i, i + 4); 186 | String val = msg.substring(i + 4, i + 8); 187 | unsigned long name2 = 188 | (hexDigitToDecimal(name.charAt(2)) << 12) + 189 | (hexDigitToDecimal(name.charAt(3)) << 8) + 190 | (hexDigitToDecimal(name.charAt(0)) << 4) + 191 | hexDigitToDecimal(name.charAt(1)); 192 | unsigned long val2 = 193 | (hexDigitToDecimal(val.charAt(2)) << 12) + 194 | (hexDigitToDecimal(val.charAt(3)) << 8) + 195 | (hexDigitToDecimal(val.charAt(0)) << 4) + 196 | hexDigitToDecimal(val.charAt(1)); 197 | if (i > 0) result.concat(','); 198 | result.concat('"'); 199 | // Decode name. 200 | char name3[] = {0, 0, 0, 0}; 201 | for (int j = 0; j < 3; j++) { 202 | uint8_t code = name2 & 31; 203 | char ch = decodeLetter(code); 204 | if (ch > 0) name3[2 - j] = ch; 205 | name2 = name2 >> 5; 206 | } 207 | name3[3] = 0; 208 | result.concat(name3); 209 | // Decode value. 210 | result.concat("\":"); result.concat((int)(val2 / 10)); 211 | result.concat('.'); result.concat((int)(val2 % 10)); 212 | } 213 | result.concat('}'); 214 | return result; 215 | } 216 | 217 | void stop(const String msg) { 218 | // Call this function if we need to stop. This informs the emulator to stop listening. 219 | for (;;) { 220 | Serial.print(F("STOPSTOPSTOP: ")); 221 | Serial.println(msg); 222 | delay(10000); 223 | // Loop forever since we can't continue 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /src/Message.h: -------------------------------------------------------------------------------- 1 | // Library for sending and receiving structured SIGFOX messages 2 | #ifndef UNABIZ_ARDUINO_MESSAGE_H 3 | #define UNABIZ_ARDUINO_MESSAGE_H 4 | 5 | #ifdef ARDUINO 6 | #if (ARDUINO >= 100) 7 | #include 8 | #else // ARDUINO >= 100 9 | #include 10 | #endif // ARDUINO >= 100 11 | #endif // ARDUINO 12 | 13 | class Message 14 | { 15 | public: 16 | Message(Radiocrafts &transceiver); // Construct a message for Radiocrafts. 17 | Message(Wisol &transceiver); // Construct a message for Wisol. 18 | bool addField(const String name, int value); // Add an integer field scaled by 10. 19 | bool addField(const String name, float value); // Add a float field with 1 decimal place. 20 | bool addField(const String name, double value); // Add a double field with 1 decimal place. 21 | bool addField(const String name, const String value); // Add a string field with max 3 chars. 22 | bool send(); // Send the structured message. 23 | bool sendAndGetResponse(String &response); // Send the structured message and get the downlink response. 24 | String getEncodedMessage(); // Return the encoded message to be transmitted. 25 | static String decodeMessage(String msg); // Decode the encoded message. 26 | 27 | private: 28 | bool addIntField(const String name, int value); // Add an integer field already scaled. 29 | bool addName(const String name); // Encode and add the 3-letter name. 30 | void echo(String msg); 31 | String encodedMessage; // Encoded message. 32 | Radiocrafts *radiocrafts = 0; // Reference to Radiocrafts transceiver for sending the message. 33 | Wisol *wisol = 0; // Reference to Wisol transceiver for sending the message. 34 | }; 35 | 36 | #endif // UNABIZ_ARDUINO_MESSAGE_H 37 | -------------------------------------------------------------------------------- /src/Radiocrafts.h: -------------------------------------------------------------------------------- 1 | // Library for sending and receiving SIGFOX messages with Arduino shield based on Radiocrafts RC1692HP-SIG. 2 | #ifndef UNABIZ_ARDUINO_RADIOCRAFTS_H 3 | #define UNABIZ_ARDUINO_RADIOCRAFTS_H 4 | 5 | #ifdef ARDUINO 6 | #if (ARDUINO >= 100) 7 | #include 8 | #else // ARDUINO >= 100 9 | #include 10 | #endif // ARDUINO >= 100 11 | 12 | #ifdef CLION 13 | #include 14 | #else // CLION 15 | #if defined(ARDUINO_ARCH_SAMD) 16 | // SAMD boards do not have a standard SoftwareSerial library, but we can 17 | // import a 3rd party one 18 | #include "SamdSoftwareSerial.h" 19 | #elif defined(BEAN_BEAN_BEAN_H) 20 | // Bean+ firmware 0.6.1 can't receive serial data properly. We provide 21 | // an alternative class BeanSoftwareSerial to work around this. 22 | // See SIGFOX.h. 23 | #else 24 | #include 25 | #endif // BEAN_BEAN_BEAN_H 26 | #endif // CLION 27 | 28 | #else // ARDUINO 29 | #endif // ARDUINO 30 | 31 | const uint8_t RADIOCRAFTS_TX = 4; // Transmit port for For UnaBiz / Radiocrafts Dev Kit 32 | const uint8_t RADIOCRAFTS_RX = 5; // Receive port for UnaBiz / Radiocrafts Dev Kit 33 | 34 | enum Mode { 35 | SEND_MODE = 0, 36 | COMMAND_MODE = 1, 37 | CONFIG_MODE = 2, 38 | }; 39 | 40 | class Radiocrafts 41 | { 42 | public: 43 | Radiocrafts(Country country, bool useEmulator, const String device, bool echo); 44 | Radiocrafts(Country country, bool useEmulator, const String device, bool echo, 45 | uint8_t rx, uint8_t tx); 46 | bool begin(); 47 | void echoOn(); // Turn on send/receive echo. 48 | void echoOff(); // Turn off send/receive echo. 49 | void setEchoPort(Print *port); // Set the port for sending echo output. 50 | void echo(const String &msg); // Echo the debug message. 51 | bool isReady(); 52 | bool sendMessage(const String &payload); // Send the payload of hex digits to the network, max 12 bytes. 53 | bool sendString(const String &str); // Sending a text string, max 12 characters allowed. 54 | bool receive(String &data); // Receive a message. 55 | bool enterCommandMode(); // Enter Command Mode for sending module commands, not data. 56 | bool exitCommandMode(); // Exit Command Mode and return to Send Mode so we can send data. 57 | 58 | // Commands for the module, must be run in Command Mode. 59 | bool getEmulator(int &result); // Return 0 if emulator mode disabled, else return 1. 60 | bool enableEmulator(String &result); // Enable emulator mode. 61 | bool disableEmulator(String &result); // Disable emulator mode. 62 | // Get the frequency used for the SIGFOX module. 63 | bool getFrequency(String &result); 64 | // Set the frequency for the SIGFOX module to Singapore frequency (RCZ4). 65 | bool setFrequencySG(String &result); 66 | // Set the frequency for the SIGFOX module to Taiwan frequency (RCZ4). 67 | bool setFrequencyTW(String &result); 68 | // Set the frequency for the SIGFOX module to ETSI frequency for Europe (RCZ1). 69 | bool setFrequencyETSI(String &result); 70 | // Set the frequency for the SIGFOX module to US frequency (RCZ2). 71 | bool setFrequencyUS(String &result); 72 | bool writeSettings(String &result); // Write frequency and other settings to flash memory of the module. 73 | bool reboot(String &result); // Reboot the SIGFOX module. 74 | bool getTemperature(int &temperature); 75 | bool getID(String &id, String &pac); // Get the SIGFOX ID and PAC for the module. 76 | bool getVoltage(float &voltage); 77 | bool getHardware(String &hardware); 78 | bool getFirmware(String &firmware); 79 | bool getPower(int &power); 80 | bool setPower(int power); 81 | bool getParameter(uint8_t address, String &value); // Return the parameter at that address. 82 | 83 | // Message conversion functions. 84 | String toHex(int i); 85 | String toHex(unsigned int i); 86 | String toHex(long l); 87 | String toHex(unsigned long ul); 88 | String toHex(float f); 89 | String toHex(double d); 90 | String toHex(char c); 91 | String toHex(char *c, int length); 92 | 93 | private: 94 | bool sendCommand(const String &cmd, uint8_t expectedMarkers, 95 | String &result, uint8_t &actualMarkers); 96 | bool sendConfigCommand(const String &cmd, String &result); 97 | bool sendBuffer(const String &buffer, int timeout, uint8_t expectedMarkers, 98 | String &dataOut, uint8_t &actualMarkers); 99 | bool setFrequency(int zone, String &result); 100 | bool enterConfigMode(); // Enter Config Mode for setting config. 101 | bool exitConfigMode(); // Exit Config Mode and return to Send Mode so we can send data. 102 | uint8_t hexDigitToDecimal(char ch); 103 | void logBuffer(const __FlashStringHelper *prefix, const char *buffer, 104 | uint8_t markerPos[], uint8_t markerCount); 105 | 106 | Mode mode; // Current mode: command or send mode. 107 | Country country; // Country to be set for SIGFOX transmission frequencies. 108 | bool useEmulator; // Set to true if using UnaBiz Emulator. 109 | String device; // Name of device if using UnaBiz Emulator. 110 | SoftwareSerial *serialPort; // Serial port for the SIGFOX module. 111 | Print *echoPort; // Port for sending echo output. Defaults to Serial. 112 | Print *lastEchoPort; // Last port used for sending echo output. 113 | unsigned long lastSend; // Timestamp of last send. 114 | }; 115 | 116 | #endif // UNABIZ_ARDUINO_RADIOCRAFTS_H 117 | -------------------------------------------------------------------------------- /src/SIGFOX.h: -------------------------------------------------------------------------------- 1 | // Declare all Arduino-based SIGFOX transceivers here so that 2 | // we may switch tranceivers easily. 3 | #ifndef UNABIZ_ARDUINO_SIGFOX_H 4 | #define UNABIZ_ARDUINO_SIGFOX_H 5 | 6 | // According to regulation, messages should be sent only every 10 minutes. 7 | const unsigned long SEND_DELAY = (unsigned long) 10 * 60 * 1000; 8 | const unsigned int MAX_BYTES_PER_MESSAGE = 12; // Only 12 bytes per message. 9 | const unsigned int COMMAND_TIMEOUT = 1000; // Wait up to 1 second for response from SIGFOX module. 10 | 11 | // Define the countries that are supported. 12 | enum Country { 13 | COUNTRY_AU = 'A'+('U' << 8), // Australia: RCZ4 14 | COUNTRY_BR = 'B'+('R' << 8), // Brazil: RCZ4 15 | COUNTRY_FR = 'F'+('R' << 8), // France: RCZ1 16 | COUNTRY_JP = 'J'+('P' << 8), // Japan: RCZ3 17 | COUNTRY_OM = 'O'+('M' << 8), // Oman: RCZ1 18 | COUNTRY_NZ = 'N'+('Z' << 8), // New Zealand: RCZ4 19 | COUNTRY_ZA = 'Z'+('A' << 8), // South Africa: RCZ1 20 | COUNTRY_SG = 'S'+('G' << 8), // Singapore: RCZ4 21 | COUNTRY_US = 'U'+('S' << 8), // USA: RCZ2 22 | COUNTRY_TW = 'T'+('W' << 8), // Taiwan: RCZ4 23 | }; 24 | 25 | #ifdef BEAN_BEAN_BEAN_H 26 | // Bean+ firmware 0.6.1 can't receive serial data properly. We provide 27 | // an alternative class BeanSoftwareSerial to work around this. 28 | #define SoftwareSerial BeanSoftwareSerial 29 | #include "BeanSoftwareSerial.h" 30 | #endif // BEAN_BEAN_BEAN_H 31 | 32 | // Library for UnaShield V2S Shield by UnaBiz. Uses pin D4 for transmit, pin D5 for receive. 33 | #include "Wisol.h" 34 | 35 | // Library for UnaShield V1 Shield by UnaBiz. Uses pin D4 for transmit, pin D5 for receive. 36 | #include "Radiocrafts.h" 37 | 38 | // Send structured messages to SIGFOX cloud. 39 | #include "Message.h" 40 | 41 | // Define aliases for each UnaShield and the transceiver it uses. 42 | #define UnaShieldV1 Radiocrafts 43 | #define UnaShieldV2S Wisol 44 | 45 | // Drop all data passed to this port. Used to suppress echo output. 46 | class NullPort: public Print { 47 | virtual size_t write(uint8_t) {} 48 | }; 49 | 50 | // Call this function if we need to stop. This informs the emulator to stop listening. 51 | void stop(const String msg); 52 | 53 | #endif // UNABIZ_ARDUINO_SIGFOX_H 54 | -------------------------------------------------------------------------------- /src/SamdSoftwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SoftwareSerial.cpp - library for Arduino M0/M0 pro 3 | Copyright (c) 2016 Arduino Srl. All rights reserved. 4 | Written by Chiara Ruggeri (chiara@arduino.org) 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | Enjoy! 21 | */ 22 | 23 | #if defined(ARDUINO_ARCH_SAMD) 24 | 25 | #include 26 | #include "SamdSoftwareSerial.h" 27 | #include 28 | #include 29 | 30 | SoftwareSerial *SoftwareSerial::active_object = 0; 31 | char SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF]; 32 | volatile uint8_t SoftwareSerial::_receive_buffer_tail = 0; 33 | volatile uint8_t SoftwareSerial::_receive_buffer_head = 0; 34 | 35 | 36 | bool SoftwareSerial::listen() 37 | { 38 | if (!_rx_delay_stopbit) 39 | return false; 40 | 41 | if (active_object != this) 42 | { 43 | if (active_object) 44 | active_object->stopListening(); 45 | 46 | _buffer_overflow = false; 47 | _receive_buffer_head = _receive_buffer_tail = 0; 48 | active_object = this; 49 | 50 | if(_inverse_logic) 51 | //Start bit high 52 | attachInterrupt(_receivePin, handle_interrupt, RISING); 53 | else 54 | //Start bit low 55 | attachInterrupt(_receivePin, handle_interrupt, FALLING); 56 | 57 | 58 | return true; 59 | } 60 | return false; 61 | } 62 | 63 | bool SoftwareSerial::stopListening() 64 | { 65 | if (active_object == this) 66 | { 67 | EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT( 1 << digitalPinToInterrupt( _receivePin )) ; 68 | active_object = NULL; 69 | return true; 70 | } 71 | return false; 72 | } 73 | 74 | 75 | void SoftwareSerial::recv() 76 | { 77 | 78 | uint8_t d = 0; 79 | 80 | // If RX line is high, then we don't see any start bit 81 | // so interrupt is probably not for us 82 | if (_inverse_logic ? rx_pin_read() : !rx_pin_read()) 83 | { 84 | 85 | EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT( 1 << digitalPinToInterrupt(_receivePin)); 86 | 87 | // Wait approximately 1/2 of a bit width to "center" the sample 88 | delayMicroseconds(_rx_delay_centering); 89 | 90 | // Read each of the 8 bits 91 | for (uint8_t i=8; i > 0; --i) 92 | { 93 | 94 | delayMicroseconds(_rx_delay_intrabit); 95 | d >>= 1; 96 | if (rx_pin_read()){ 97 | d |= 0x80; 98 | } 99 | 100 | } 101 | if (_inverse_logic){ 102 | d = ~d; 103 | } 104 | 105 | // if buffer full, set the overflow flag and return 106 | uint8_t next = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF; 107 | if (next != _receive_buffer_head) 108 | { 109 | // save new data in buffer: tail points to where byte goes 110 | _receive_buffer[_receive_buffer_tail] = d; // save new byte 111 | _receive_buffer_tail = next; 112 | } 113 | else 114 | { 115 | _buffer_overflow = true; 116 | } 117 | 118 | // skip the stop bit 119 | delayMicroseconds(_rx_delay_stopbit); 120 | 121 | EIC->INTENSET.reg = EIC_INTENSET_EXTINT( 1 << digitalPinToInterrupt(_receivePin)); 122 | } 123 | } 124 | 125 | 126 | uint32_t SoftwareSerial::rx_pin_read() 127 | { 128 | return _receivePortRegister->reg & digitalPinToBitMask(_receivePin); 129 | } 130 | 131 | /* static */ 132 | inline void SoftwareSerial::handle_interrupt() 133 | { 134 | if (active_object) 135 | { 136 | active_object->recv(); 137 | } 138 | } 139 | 140 | 141 | // Constructor 142 | SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) : 143 | _rx_delay_centering(0), 144 | _rx_delay_intrabit(0), 145 | _rx_delay_stopbit(0), 146 | _tx_delay(0), 147 | _buffer_overflow(false), 148 | _inverse_logic(inverse_logic) 149 | { 150 | _receivePin = receivePin; 151 | _transmitPin = transmitPin; 152 | } 153 | 154 | // Destructor 155 | SoftwareSerial::~SoftwareSerial() 156 | { 157 | end(); 158 | } 159 | 160 | void SoftwareSerial::setTX(uint8_t tx) 161 | { 162 | // First write, then set output. If we do this the other way around, 163 | // the pin would be output low for a short while before switching to 164 | // output hihg. Now, it is input with pullup for a short while, which 165 | // is fine. With inverse logic, either order is fine. 166 | digitalWrite(tx, _inverse_logic ? LOW : HIGH); 167 | pinMode(tx, OUTPUT); 168 | _transmitBitMask = digitalPinToBitMask(tx); 169 | PortGroup * port = digitalPinToPort(tx); 170 | _transmitPortRegister = (volatile PORT_OUT_Type*)portOutputRegister(port); 171 | 172 | } 173 | 174 | void SoftwareSerial::setRX(uint8_t rx) 175 | { 176 | pinMode(rx, INPUT); 177 | if (!_inverse_logic) 178 | digitalWrite(rx, HIGH); // pullup for normal logic! 179 | _receivePin = rx; 180 | _receiveBitMask = digitalPinToBitMask(rx); 181 | PortGroup * port = digitalPinToPort(rx); 182 | _receivePortRegister = (volatile PORT_IN_Type*)portInputRegister(port); 183 | 184 | } 185 | 186 | 187 | void SoftwareSerial::begin(long speed) 188 | { 189 | setTX(_transmitPin); 190 | setRX(_receivePin); 191 | // Precalculate the various delays 192 | //Calculate the distance between bit in micro seconds 193 | uint32_t bit_delay = (float(1)/speed)*1000000; 194 | 195 | _tx_delay = bit_delay; 196 | 197 | // Only setup rx when we have a valid PCINT for this pin 198 | if (digitalPinToInterrupt(_receivePin)!=NOT_AN_INTERRUPT) { 199 | //Wait 1/2 bit - 2 micro seconds (time for interrupt to be served) 200 | _rx_delay_centering = (bit_delay/2) - 2; 201 | //Wait 1 bit - 2 micro seconds (time in each loop iteration) 202 | _rx_delay_intrabit = bit_delay - 2; 203 | //Wait 1 bit (the stop one) 204 | _rx_delay_stopbit = bit_delay; 205 | 206 | 207 | delayMicroseconds(_tx_delay); 208 | } 209 | listen(); 210 | } 211 | 212 | void SoftwareSerial::end() 213 | { 214 | stopListening(); 215 | } 216 | 217 | int SoftwareSerial::read() 218 | { 219 | if (!isListening()){ 220 | return -1;} 221 | 222 | 223 | // Empty buffer? 224 | if (_receive_buffer_head == _receive_buffer_tail){ 225 | return -1;} 226 | 227 | // Read from "head" 228 | uint8_t d = _receive_buffer[_receive_buffer_head]; // grab next byte 229 | _receive_buffer_head = (_receive_buffer_head + 1) % _SS_MAX_RX_BUFF; 230 | return d; 231 | } 232 | 233 | 234 | int SoftwareSerial::available() 235 | { 236 | if (!isListening()) 237 | return 0; 238 | 239 | return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF; 240 | } 241 | 242 | 243 | size_t SoftwareSerial::write(uint8_t b) 244 | { 245 | if (_tx_delay == 0) { 246 | setWriteError(); 247 | return 0; 248 | } 249 | 250 | // By declaring these as local variables, the compiler will put them 251 | // in registers _before_ disabling interrupts and entering the 252 | // critical timing sections below, which makes it a lot easier to 253 | // verify the cycle timings 254 | volatile PORT_OUT_Type *reg = _transmitPortRegister; 255 | uint32_t reg_mask = _transmitBitMask; 256 | uint32_t inv_mask = ~_transmitBitMask; 257 | bool inv = _inverse_logic; 258 | uint16_t delay = _tx_delay; 259 | 260 | if (inv) 261 | b = ~b; 262 | // turn off interrupts for a clean txmit 263 | EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT( 1 << digitalPinToInterrupt( _receivePin )); 264 | 265 | // Write the start bit 266 | if (inv) 267 | reg->reg |= reg_mask; 268 | else 269 | reg->reg &= inv_mask; 270 | 271 | delayMicroseconds(delay); 272 | 273 | 274 | // Write each of the 8 bits 275 | for (uint8_t i = 8; i > 0; --i) 276 | { 277 | if (b & 1) // choose bit 278 | reg->reg |= reg_mask; // send 1 279 | else 280 | reg->reg &= inv_mask; // send 0 281 | 282 | delayMicroseconds(delay); 283 | b >>= 1; 284 | } 285 | 286 | // restore pin to natural state 287 | if (inv) 288 | reg->reg &= inv_mask; 289 | else 290 | reg->reg |= reg_mask; 291 | 292 | 293 | EIC->INTENSET.reg = EIC_INTENSET_EXTINT( 1 << digitalPinToInterrupt( _receivePin ) ) ; 294 | 295 | delayMicroseconds(delay); 296 | 297 | return 1; 298 | } 299 | 300 | void SoftwareSerial::flush() 301 | { 302 | if (!isListening()) 303 | return; 304 | 305 | EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT( 1 << digitalPinToInterrupt( _receivePin ) ) ; 306 | 307 | _receive_buffer_head = _receive_buffer_tail = 0; 308 | 309 | EIC->INTENSET.reg = EIC_INTENSET_EXTINT( 1 << digitalPinToInterrupt( _receivePin ) ) ; 310 | 311 | } 312 | 313 | int SoftwareSerial::peek() 314 | { 315 | if (!isListening()) 316 | return -1; 317 | 318 | // Empty buffer? 319 | if (_receive_buffer_head == _receive_buffer_tail) 320 | return -1; 321 | 322 | // Read from "head" 323 | return _receive_buffer[_receive_buffer_head]; 324 | } 325 | 326 | 327 | 328 | #endif // defined(ARDUINO_ARCH_SAMD) -------------------------------------------------------------------------------- /src/SamdSoftwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoftwareSerial.cpp - library for Arduino M0/M0 pro 3 | Copyright (c) 2016 Arduino Srl. All rights reserved. 4 | Written by Chiara Ruggeri (chiara@arduino.org) 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | Enjoy! 21 | */ 22 | 23 | #if defined(ARDUINO_ARCH_SAMD) 24 | 25 | #ifndef SoftwareSerial_h 26 | #define SoftwareSerial_h 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | /****************************************************************************** 33 | * Definitions 34 | ******************************************************************************/ 35 | 36 | #define _SS_MAX_RX_BUFF 64 // RX buffer size 37 | #ifndef GCC_VERSION 38 | #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 39 | #endif 40 | 41 | class SoftwareSerial : public Stream 42 | { 43 | private: 44 | // per object data 45 | uint8_t _transmitPin; 46 | uint8_t _receivePin; 47 | uint32_t _receiveBitMask; 48 | volatile PORT_IN_Type *_receivePortRegister; 49 | uint32_t _transmitBitMask; 50 | volatile PORT_OUT_Type *_transmitPortRegister; 51 | 52 | // Expressed as 4-cycle delays (must never be 0!) 53 | uint16_t _rx_delay_centering; 54 | uint16_t _rx_delay_intrabit; 55 | uint16_t _rx_delay_stopbit; 56 | uint16_t _tx_delay; 57 | 58 | uint16_t _buffer_overflow:1; 59 | uint16_t _inverse_logic:1; 60 | 61 | // static data 62 | static char _receive_buffer[_SS_MAX_RX_BUFF]; 63 | static volatile uint8_t _receive_buffer_tail; 64 | static volatile uint8_t _receive_buffer_head; 65 | static SoftwareSerial *active_object; 66 | 67 | // private methods 68 | void recv() __attribute__((__always_inline__)); 69 | uint32_t rx_pin_read(); 70 | void tx_pin_write(uint8_t pin_state) __attribute__((__always_inline__)); 71 | void setTX(uint8_t transmitPin); 72 | void setRX(uint8_t receivePin); 73 | void setRxIntMsk(bool enable) __attribute__((__always_inline__)); 74 | 75 | 76 | public: 77 | // public methods 78 | SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false); 79 | ~SoftwareSerial(); 80 | void begin(long speed); 81 | bool listen(); 82 | void end(); 83 | bool isListening() { return this == active_object; } 84 | bool stopListening(); 85 | bool overflow() { bool ret = _buffer_overflow; if (ret) _buffer_overflow = false; return ret; } 86 | int peek(); 87 | 88 | virtual size_t write(uint8_t byte); 89 | virtual int read(); 90 | virtual int available(); 91 | virtual void flush(); 92 | operator bool() { return true; } 93 | 94 | using Print::write; 95 | 96 | // public only for easy access by interrupt handlers 97 | static inline void handle_interrupt() __attribute__((__always_inline__)); 98 | }; 99 | 100 | // Arduino 0012 workaround 101 | #undef int 102 | #undef char 103 | #undef long 104 | #undef byte 105 | #undef float 106 | #undef abs 107 | #undef round 108 | 109 | #endif 110 | 111 | #endif // defined(ARDUINO_ARCH_SAMD) -------------------------------------------------------------------------------- /src/Wisol.h: -------------------------------------------------------------------------------- 1 | // Library for sending and receiving SIGFOX messages with Arduino shield based on Wisol WSSFM10R. 2 | #ifndef UNABIZ_ARDUINO_WISOL_H 3 | #define UNABIZ_ARDUINO_WISOL_H 4 | 5 | #ifdef ARDUINO 6 | #if (ARDUINO >= 100) 7 | #include 8 | #else // ARDUINO >= 100 9 | #include 10 | #endif // ARDUINO >= 100 11 | 12 | #ifdef CLION 13 | #include 14 | #else // CLION 15 | #if defined(ARDUINO_ARCH_SAMD) 16 | // SAMD boards do not have a standard SoftwareSerial library, but we can 17 | // import a 3rd party one 18 | #include "SamdSoftwareSerial.h" 19 | #elif defined(BEAN_BEAN_BEAN_H) 20 | // Bean+ firmware 0.6.1 can't receive serial data properly. We provide 21 | // an alternative class BeanSoftwareSerial to work around this. 22 | // See SIGFOX.h. 23 | #else 24 | #include 25 | #endif // BEAN_BEAN_BEAN_H 26 | #endif // CLION 27 | 28 | #else // ARDUINO 29 | #endif // ARDUINO 30 | 31 | const uint8_t WISOL_TX = 4; // Transmit port for For UnaBiz / Wisol Dev Kit 32 | const uint8_t WISOL_RX = 5; // Receive port for UnaBiz / Wisol Dev Kit 33 | const unsigned long WISOL_COMMAND_TIMEOUT = 60000; // Wait up to 60 seconds for response from SIGFOX module. Includes downlink response. 34 | 35 | class Wisol 36 | { 37 | public: 38 | Wisol(Country country, bool useEmulator, const String device, bool echo); 39 | Wisol(Country country, bool useEmulator, const String device, bool echo, 40 | uint8_t rx, uint8_t tx); 41 | Wisol(Country country, bool useEmulator, const String device, bool echo, 42 | HardwareSerial *serial); 43 | bool begin(); 44 | void echoOn(); // Turn on send/receive echo. 45 | void echoOff(); // Turn off send/receive echo. 46 | void setEchoPort(Print *port); // Set the port for sending echo output. 47 | void echo(const String &msg); // Echo the debug message. 48 | bool isReady(); 49 | bool sendMessage(const String &payload); // Send the payload of hex digits to the network, max 12 bytes. 50 | bool sendMessageAndGetResponse(const String &payload, String &response); // Send the payload of hex digits to the network and get response. 51 | bool sendString(const String &str); // Sending a text string, max 12 characters allowed. 52 | bool receive(String &data); // Receive a message. 53 | bool enterCommandMode(); // Enter Command Mode for sending module commands, not data. 54 | bool exitCommandMode(); // Exit Command Mode so we can send data. 55 | 56 | // Commands for the module, must be run in Command Mode. 57 | bool getEmulator(int &result); // Return 0 if emulator mode disabled, else return 1. 58 | bool enableEmulator(String &result); // Enable emulator mode. 59 | bool disableEmulator(String &result); // Disable emulator mode. 60 | // Get the frequency used for the SIGFOX module. 61 | bool getFrequency(String &result); 62 | // Set the frequency for the SIGFOX module to Singapore frequency (RCZ4). 63 | bool setFrequencySG(String &result); 64 | // Set the frequency for the SIGFOX module to Taiwan frequency (RCZ4). 65 | bool setFrequencyTW(String &result); 66 | // Set the frequency for the SIGFOX module to ETSI frequency for Europe (RCZ1). 67 | bool setFrequencyETSI(String &result); 68 | // Set the frequency for the SIGFOX module to US frequency (RCZ2). 69 | bool setFrequencyUS(String &result); 70 | // Set the frequency for the SIGFOX module to Japan frequency (RCZ3). 71 | bool setFrequencyJP(String &result); 72 | bool writeSettings(String &result); // Write frequency and other settings to flash memory of the module. 73 | bool reboot(String &result); // Reboot the SIGFOX module. 74 | bool getTemperature(float &temperature); 75 | bool getID(String &id, String &pac); // Get the SIGFOX ID and PAC for the module. 76 | bool getVoltage(float &voltage); 77 | 78 | bool setSleep(); 79 | bool setWakeup(); 80 | 81 | bool getHardware(String &hardware); 82 | bool getFirmware(String &firmware); 83 | bool getPower(int &power); 84 | bool setPower(int power); 85 | bool getParameter(uint8_t address, String &value); // Return the parameter at that address. 86 | 87 | // Message conversion functions. 88 | String toHex(int i); 89 | String toHex(unsigned int i); 90 | String toHex(long l); 91 | String toHex(unsigned long ul); 92 | String toHex(float f); 93 | String toHex(double d); 94 | String toHex(char c); 95 | String toHex(char *c, int length); 96 | 97 | private: 98 | bool sendCommand(const String &cmd, uint8_t expectedMarkers, 99 | String &result, uint8_t &actualMarkers); 100 | bool sendBuffer(const String &buffer, unsigned long timeout, uint8_t expectedMarkers, 101 | String &dataOut, uint8_t &actualMarkers); 102 | bool setFrequency(int zone, String &result); 103 | uint8_t hexDigitToDecimal(char ch); 104 | void logBuffer(const __FlashStringHelper *prefix, const char *buffer, 105 | uint8_t markerPos[], uint8_t markerCount); 106 | 107 | int zone; // 1 to 4 representing SIGFOX frequencies RCZ 1 to 4. 108 | Country country; // Country to be set for SIGFOX transmission frequencies. 109 | bool useEmulator; // Set to true if using UnaBiz Emulator. 110 | String device; // Name of device if using UnaBiz Emulator. 111 | Stream *serialPort; // Serial port for the SIGFOX module. 112 | SoftwareSerial *swSerialPort; 113 | HardwareSerial *hwSerialPort; 114 | Print *echoPort; // Port for sending echo output. Defaults to Serial. 115 | Print *lastEchoPort; // Last port used for sending echo output. 116 | unsigned long lastSend; // Timestamp of last send. 117 | bool setOutputPower(); 118 | }; 119 | 120 | #endif // UNABIZ_ARDUINO_WISOL_H 121 | -------------------------------------------------------------------------------- /test/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | project(test) 3 | 4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 5 | 6 | set(SOURCE_FILES test.cpp) 7 | add_executable(testexec ${SOURCE_FILES}) 8 | -------------------------------------------------------------------------------- /test/LocalDHT.cpp: -------------------------------------------------------------------------------- 1 | #ifndef ARDUINO 2 | /* DHT library 3 | 4 | MIT license 5 | written by Adafruit Industries 6 | */ 7 | 8 | #include "DHT.h" 9 | #define NAN 0 10 | 11 | DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) { 12 | _pin = pin; 13 | _type = type; 14 | _count = count; 15 | firstreading = true; 16 | } 17 | 18 | void DHT::begin(void) { 19 | // set up the pins! 20 | pinMode(_pin, INPUT); 21 | digitalWrite(_pin, HIGH); 22 | _lastreadtime = 0; 23 | } 24 | 25 | //boolean S == Scale. True == Farenheit; False == Celcius 26 | float DHT::readTemperature(bool S) { 27 | float f; 28 | 29 | if (read()) { 30 | switch (_type) { 31 | case DHT11: 32 | f = data[2]; 33 | if(S) 34 | f = convertCtoF(f); 35 | 36 | return f; 37 | case DHT22: 38 | case DHT21: 39 | f = data[2] & 0x7F; 40 | f *= 256; 41 | f += data[3]; 42 | f /= 10; 43 | if (data[2] & 0x80) 44 | f *= -1; 45 | if(S) 46 | f = convertCtoF(f); 47 | 48 | return f; 49 | } 50 | } 51 | Serial.print("Read fail"); 52 | return NAN; 53 | } 54 | 55 | float DHT::convertCtoF(float c) { 56 | return c * 9 / 5 + 32; 57 | } 58 | 59 | float DHT::readHumidity(void) { 60 | float f; 61 | if (read()) { 62 | switch (_type) { 63 | case DHT11: 64 | f = data[0]; 65 | return f; 66 | case DHT22: 67 | case DHT21: 68 | f = data[0]; 69 | f *= 256; 70 | f += data[1]; 71 | f /= 10; 72 | return f; 73 | } 74 | } 75 | Serial.print("Read fail"); 76 | return NAN; 77 | } 78 | 79 | 80 | boolean DHT::read(void) { 81 | uint8_t laststate = HIGH; 82 | uint8_t counter = 0; 83 | uint8_t j = 0, i; 84 | unsigned long currenttime; 85 | 86 | // pull the pin high and wait 250 milliseconds 87 | digitalWrite(_pin, HIGH); 88 | delay(250); 89 | 90 | currenttime = millis(); 91 | if (currenttime < _lastreadtime) { 92 | // ie there was a rollover 93 | _lastreadtime = 0; 94 | } 95 | if (!firstreading && ((currenttime - _lastreadtime) < 2000)) { 96 | return true; // return last correct measurement 97 | //delay(2000 - (currenttime - _lastreadtime)); 98 | } 99 | firstreading = false; 100 | /* 101 | Serial.print("Currtime: "); Serial.print(currenttime); 102 | Serial.print(" Lasttime: "); Serial.print(_lastreadtime); 103 | */ 104 | _lastreadtime = millis(); 105 | 106 | data[0] = data[1] = data[2] = data[3] = data[4] = 0; 107 | 108 | // now pull it low for ~20 milliseconds 109 | pinMode(_pin, OUTPUT); 110 | digitalWrite(_pin, LOW); 111 | delay(20); 112 | //cli(); 113 | digitalWrite(_pin, HIGH); 114 | delayMicroseconds(40); 115 | pinMode(_pin, INPUT); 116 | 117 | // read in timings 118 | for ( i=0; i< MAXTIMINGS; i++) { 119 | counter = 0; 120 | while (digitalRead(_pin) == laststate) { 121 | counter++; 122 | delayMicroseconds(1); 123 | if (counter == 255) { 124 | break; 125 | } 126 | } 127 | laststate = digitalRead(_pin); 128 | 129 | if (counter == 255) break; 130 | 131 | // ignore first 3 transitions 132 | if ((i >= 4) && (i%2 == 0)) { 133 | // shove each bit into the storage bytes 134 | data[j/8] <<= 1; 135 | if (counter > _count) 136 | data[j/8] |= 1; 137 | j++; 138 | } 139 | 140 | } 141 | 142 | //sei(); 143 | 144 | /* 145 | Serial.println(j, DEC); 146 | Serial.print(data[0], HEX); Serial.print(", "); 147 | Serial.print(data[1], HEX); Serial.print(", "); 148 | Serial.print(data[2], HEX); Serial.print(", "); 149 | Serial.print(data[3], HEX); Serial.print(", "); 150 | Serial.print(data[4], HEX); Serial.print(" =? "); 151 | Serial.println(data[0] + data[1] + data[2] + data[3], HEX); 152 | */ 153 | 154 | // check we read 40 bits and that the checksum matches 155 | if ((j >= 40) && 156 | (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) ) { 157 | return true; 158 | } 159 | 160 | 161 | return false; 162 | 163 | } 164 | #endif // ARDUINO 165 | -------------------------------------------------------------------------------- /test/LocalDHT.h: -------------------------------------------------------------------------------- 1 | #ifndef ARDUINO 2 | #ifndef DHT_H 3 | #define DHT_H 4 | #if ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | // 8 MHz(ish) AVR --------------------------------------------------------- 11 | #if (F_CPU >= 7400000UL) && (F_CPU <= 9500000UL) 12 | #define COUNT 3 13 | // 16 MHz(ish) AVR -------------------------------------------------------- 14 | #elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) 15 | #define COUNT 6 16 | #else 17 | #error "CPU SPEED NOT SUPPORTED" 18 | #endif 19 | 20 | /* DHT library 21 | 22 | MIT license 23 | written by Adafruit Industries 24 | */ 25 | 26 | // how many timing transitions we need to keep track of. 2 * number bits + extra 27 | #define MAXTIMINGS 85 28 | 29 | #define DHT11 11 30 | #define DHT22 22 31 | #define DHT21 21 32 | #define AM2301 21 33 | 34 | class DHT { 35 | private: 36 | uint8_t data[6]; 37 | uint8_t _pin, _type, _count; 38 | boolean read(void); 39 | unsigned long _lastreadtime; 40 | boolean firstreading; 41 | 42 | public: 43 | DHT(uint8_t pin, uint8_t type, uint8_t count=COUNT); 44 | void begin(void); 45 | float readTemperature(bool S=false); 46 | float convertCtoF(float); 47 | float readHumidity(void); 48 | 49 | }; 50 | #endif 51 | #endif // ARDUINO 52 | -------------------------------------------------------------------------------- /test/LocalWString.h: -------------------------------------------------------------------------------- 1 | /* 2 | WString.h - String library for Wiring & Arduino 3 | ...mostly rewritten by Paul Stoffregen... 4 | Copyright (c) 2009-10 Hernando Barragan. All right reserved. 5 | Copyright 2011, Paul Stoffregen, paul@pjrc.com 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef String_class_h 23 | #define String_class_h 24 | #ifdef __cplusplus 25 | 26 | #include 27 | #include 28 | #include 29 | #ifdef ARDUINO //// 30 | #include 31 | #endif //// 32 | 33 | // When compiling programs with this class, the following gcc parameters 34 | // dramatically increase performance and memory (RAM) efficiency, typically 35 | // with little or no increase in code size. 36 | // -felide-constructors 37 | // -std=c++0x 38 | 39 | class __FlashStringHelper; 40 | #define F(string_literal) (reinterpret_cast(PSTR(string_literal))) 41 | 42 | // An inherited class for holding the result of a concatenation. These 43 | // result objects are assumed to be writable by subsequent concatenations. 44 | class StringSumHelper; 45 | 46 | // The string class 47 | class String 48 | { 49 | // use a function pointer to allow for "if (s)" without the 50 | // complications of an operator bool(). for more information, see: 51 | // http://www.artima.com/cppsource/safebool.html 52 | typedef void (String::*StringIfHelperType)() const; 53 | void StringIfHelper() const {} 54 | 55 | public: 56 | // constructors 57 | // creates a copy of the initial value. 58 | // if the initial value is null or invalid, or if memory allocation 59 | // fails, the string will be marked as invalid (i.e. "if (s)" will 60 | // be false). 61 | String(const char *cstr = ""); 62 | String(const String &str); 63 | String(const __FlashStringHelper *str); 64 | #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) 65 | String(String &&rval); 66 | String(StringSumHelper &&rval); 67 | #endif 68 | explicit String(char c); 69 | explicit String(unsigned char, unsigned char base=10); 70 | explicit String(int, unsigned char base=10); 71 | explicit String(unsigned int, unsigned char base=10); 72 | explicit String(long, unsigned char base=10); 73 | explicit String(unsigned long, unsigned char base=10); 74 | explicit String(float, unsigned char decimalPlaces=2); 75 | explicit String(double, unsigned char decimalPlaces=2); 76 | ~String(void); 77 | 78 | // memory management 79 | // return true on success, false on failure (in which case, the string 80 | // is left unchanged). reserve(0), if successful, will validate an 81 | // invalid string (i.e., "if (s)" will be true afterwards) 82 | unsigned char reserve(unsigned int size); 83 | inline unsigned int length(void) const {return len;} 84 | 85 | // creates a copy of the assigned value. if the value is null or 86 | // invalid, or if the memory allocation fails, the string will be 87 | // marked as invalid ("if (s)" will be false). 88 | String & operator = (const String &rhs); 89 | String & operator = (const char *cstr); 90 | String & operator = (const __FlashStringHelper *str); 91 | #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) 92 | String & operator = (String &&rval); 93 | String & operator = (StringSumHelper &&rval); 94 | #endif 95 | 96 | // concatenate (works w/ built-in types) 97 | 98 | // returns true on success, false on failure (in which case, the string 99 | // is left unchanged). if the argument is null or invalid, the 100 | // concatenation is considered unsucessful. 101 | unsigned char concat(const String &str); 102 | unsigned char concat(const char *cstr); 103 | unsigned char concat(char c); 104 | unsigned char concat(unsigned char c); 105 | unsigned char concat(int num); 106 | unsigned char concat(unsigned int num); 107 | unsigned char concat(long num); 108 | unsigned char concat(unsigned long num); 109 | unsigned char concat(float num); 110 | unsigned char concat(double num); 111 | unsigned char concat(const __FlashStringHelper * str); 112 | 113 | // if there's not enough memory for the concatenated value, the string 114 | // will be left unchanged (but this isn't signalled in any way) 115 | String & operator += (const String &rhs) {concat(rhs); return (*this);} 116 | String & operator += (const char *cstr) {concat(cstr); return (*this);} 117 | String & operator += (char c) {concat(c); return (*this);} 118 | String & operator += (unsigned char num) {concat(num); return (*this);} 119 | String & operator += (int num) {concat(num); return (*this);} 120 | String & operator += (unsigned int num) {concat(num); return (*this);} 121 | String & operator += (long num) {concat(num); return (*this);} 122 | String & operator += (unsigned long num) {concat(num); return (*this);} 123 | String & operator += (float num) {concat(num); return (*this);} 124 | String & operator += (double num) {concat(num); return (*this);} 125 | String & operator += (const __FlashStringHelper *str){concat(str); return (*this);} 126 | 127 | friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); 128 | friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); 129 | friend StringSumHelper & operator + (const StringSumHelper &lhs, char c); 130 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num); 131 | friend StringSumHelper & operator + (const StringSumHelper &lhs, int num); 132 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num); 133 | friend StringSumHelper & operator + (const StringSumHelper &lhs, long num); 134 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num); 135 | friend StringSumHelper & operator + (const StringSumHelper &lhs, float num); 136 | friend StringSumHelper & operator + (const StringSumHelper &lhs, double num); 137 | friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs); 138 | 139 | // comparison (only works w/ Strings and "strings") 140 | operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } 141 | int compareTo(const String &s) const; 142 | unsigned char equals(const String &s) const; 143 | unsigned char equals(const char *cstr) const; 144 | unsigned char operator == (const String &rhs) const {return equals(rhs);} 145 | unsigned char operator == (const char *cstr) const {return equals(cstr);} 146 | unsigned char operator != (const String &rhs) const {return !equals(rhs);} 147 | unsigned char operator != (const char *cstr) const {return !equals(cstr);} 148 | unsigned char operator < (const String &rhs) const; 149 | unsigned char operator > (const String &rhs) const; 150 | unsigned char operator <= (const String &rhs) const; 151 | unsigned char operator >= (const String &rhs) const; 152 | unsigned char equalsIgnoreCase(const String &s) const; 153 | unsigned char startsWith( const String &prefix) const; 154 | unsigned char startsWith(const String &prefix, unsigned int offset) const; 155 | unsigned char endsWith(const String &suffix) const; 156 | 157 | // character acccess 158 | char charAt(unsigned int index) const; 159 | void setCharAt(unsigned int index, char c); 160 | char operator [] (unsigned int index) const; 161 | char& operator [] (unsigned int index); 162 | void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; 163 | void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const 164 | {getBytes((unsigned char *)buf, bufsize, index);} 165 | const char * c_str() const { return buffer; } 166 | const char* begin() { return c_str(); } 167 | const char* end() { return c_str() + length(); } 168 | 169 | // search 170 | int indexOf( char ch ) const; 171 | int indexOf( char ch, unsigned int fromIndex ) const; 172 | int indexOf( const String &str ) const; 173 | int indexOf( const String &str, unsigned int fromIndex ) const; 174 | int lastIndexOf( char ch ) const; 175 | int lastIndexOf( char ch, unsigned int fromIndex ) const; 176 | int lastIndexOf( const String &str ) const; 177 | int lastIndexOf( const String &str, unsigned int fromIndex ) const; 178 | String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); }; 179 | String substring( unsigned int beginIndex, unsigned int endIndex ) const; 180 | 181 | // modification 182 | void replace(char find, char replace); 183 | void replace(const String& find, const String& replace); 184 | void remove(unsigned int index); 185 | void remove(unsigned int index, unsigned int count); 186 | void toLowerCase(void); 187 | void toUpperCase(void); 188 | void trim(void); 189 | 190 | // parsing/conversion 191 | long toInt(void) const; 192 | float toFloat(void) const; 193 | 194 | protected: 195 | char *buffer; // the actual char array 196 | unsigned int capacity; // the array length minus one (for the '\0') 197 | unsigned int len; // the String length (not counting the '\0') 198 | protected: 199 | void init(void); 200 | void invalidate(void); 201 | unsigned char changeBuffer(unsigned int maxStrLen); 202 | unsigned char concat(const char *cstr, unsigned int length); 203 | 204 | // copy and move 205 | String & copy(const char *cstr, unsigned int length); 206 | String & copy(const __FlashStringHelper *pstr, unsigned int length); 207 | #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) 208 | void move(String &rhs); 209 | #endif 210 | }; 211 | 212 | class StringSumHelper : public String 213 | { 214 | public: 215 | StringSumHelper(const String &s) : String(s) {} 216 | StringSumHelper(const char *p) : String(p) {} 217 | StringSumHelper(char c) : String(c) {} 218 | StringSumHelper(unsigned char num) : String(num) {} 219 | StringSumHelper(int num) : String(num) {} 220 | StringSumHelper(unsigned int num) : String(num) {} 221 | StringSumHelper(long num) : String(num) {} 222 | StringSumHelper(unsigned long num) : String(num) {} 223 | StringSumHelper(float num) : String(num) {} 224 | StringSumHelper(double num) : String(num) {} 225 | }; 226 | 227 | #endif // __cplusplus 228 | #endif // String_class_h 229 | -------------------------------------------------------------------------------- /test/test.cpp: -------------------------------------------------------------------------------- 1 | // Test the transceiver functions under Windows or Mac without Arduino. 2 | #ifndef ARDUINO 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "util.cpp" 9 | #include "../Radiocrafts.cpp" 10 | #include "../Akeru.cpp" 11 | #include "../Message.cpp" 12 | 13 | int main() { 14 | puts("test"); 15 | 16 | static const String device = "g88pi"; // Set this to your device name if you're using UnaBiz Emulator. 17 | static const bool useEmulator = false; // Set to true if using UnaBiz Emulator. 18 | static const bool echo = true; // Set to true if the SIGFOX library should display the executed commands. 19 | static const Country country = COUNTRY_SG; // Set this to your country to configure the SIGFOX transmission frequencies. 20 | static Radiocrafts transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield Dev Kit with Radiocrafts module. 21 | 22 | Message msg(transceiver); 23 | msg.addField("ctr", 123); 24 | msg.addField("tmp", 30.1); 25 | msg.addField("hmd", 98.7); 26 | String encodedMsg = msg.getEncodedMessage(); 27 | printf("encodedMsg=%s\n", encodedMsg.c_str()); 28 | String decodedMsg = Message::decodeMessage(encodedMsg); 29 | printf("decodedMsg=%s\n", decodedMsg.c_str()); 30 | msg.send(); 31 | 32 | #if NOTUSED 33 | setup(); 34 | for (;;) { 35 | loop(); 36 | break; 37 | } 38 | #endif 39 | return 0; 40 | } 41 | #endif // ARDUINO 42 | -------------------------------------------------------------------------------- /test/unabiz-arduino.ino: -------------------------------------------------------------------------------- 1 | // The demo sketch has been moved to 2 | // https://github.com/UnaBiz/unabiz-arduino/blob/master/examples/DemoTest/DemoTest.ino 3 | 4 | #ifdef CLION 5 | // Test the build of each example with CLion. 6 | //#include "examples/DemoTest/DemoTest.ino" 7 | //#include "examples/send-test/send-test.ino" 8 | //#include "examples/read-temperature/read-temperature.ino" 9 | //#include "examples/send-temperature/send-temperature.ino" 10 | //#include "examples/read-light-level/read-light-level.ino" 11 | #include "examples/send-light-level/send-light-level.ino" 12 | #endif // CLION 13 | -------------------------------------------------------------------------------- /test/util.cpp: -------------------------------------------------------------------------------- 1 | // Util functions available on Arduino but missing on Windows/Mac. 2 | #ifndef ARDUINO 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | char *ltoa(long num, char *str, int radix) { 10 | char sign = 0; 11 | char temp[33]; //an int can only be 32 bits long 12 | //at radix 2 (binary) the string 13 | //is at most 16 + 1 null long. 14 | int temp_loc = 0; 15 | int digit; 16 | int str_loc = 0; 17 | 18 | //save sign for radix 10 conversion 19 | if (radix == 10 && num < 0) { 20 | sign = 1; 21 | num = -num; 22 | } 23 | 24 | //construct a backward string of the number. 25 | do { 26 | digit = (unsigned long)num % radix; 27 | if (digit < 10) 28 | temp[temp_loc++] = digit + '0'; 29 | else 30 | temp[temp_loc++] = digit - 10 + 'A'; 31 | num = ((unsigned long)num) / radix; 32 | } while ((unsigned long)num > 0); 33 | 34 | //now add the sign for radix 10 35 | if (radix == 10 && sign) { 36 | temp[temp_loc] = '-'; 37 | } else { 38 | temp_loc--; 39 | } 40 | 41 | 42 | //now reverse the string. 43 | while ( temp_loc >=0 ) {// while there are still chars 44 | str[str_loc++] = temp[temp_loc--]; 45 | } 46 | str[str_loc] = 0; // add null termination. 47 | 48 | return str; 49 | } 50 | 51 | char *utoa(unsigned num, char *str, int radix) { 52 | char temp[17]; //an int can only be 16 bits long 53 | //at radix 2 (binary) the string 54 | //is at most 16 + 1 null long. 55 | int temp_loc = 0; 56 | int digit; 57 | int str_loc = 0; 58 | 59 | //construct a backward string of the number. 60 | do { 61 | digit = (unsigned int)num % radix; 62 | if (digit < 10) 63 | temp[temp_loc++] = digit + '0'; 64 | else 65 | temp[temp_loc++] = digit - 10 + 'A'; 66 | num = ((unsigned int)num) / radix; 67 | } while ((unsigned int)num > 0); 68 | 69 | temp_loc--; 70 | 71 | 72 | //now reverse the string. 73 | while ( temp_loc >=0 ) {// while there are still chars 74 | str[str_loc++] = temp[temp_loc--]; 75 | } 76 | str[str_loc] = 0; // add null termination. 77 | 78 | return str; 79 | } 80 | 81 | char *itoa(int num, char *str, int radix) { 82 | char sign = 0; 83 | char temp[17]; //an int can only be 16 bits long 84 | //at radix 2 (binary) the string 85 | //is at most 16 + 1 null long. 86 | int temp_loc = 0; 87 | int digit; 88 | int str_loc = 0; 89 | 90 | //save sign for radix 10 conversion 91 | if (radix == 10 && num < 0) { 92 | sign = 1; 93 | num = -num; 94 | } 95 | 96 | //construct a backward string of the number. 97 | do { 98 | digit = (unsigned int)num % radix; 99 | if (digit < 10) 100 | temp[temp_loc++] = digit + '0'; 101 | else 102 | temp[temp_loc++] = digit - 10 + 'A'; 103 | num = (((unsigned int)num) / radix); 104 | } while ((unsigned int)num > 0); 105 | 106 | //now add the sign for radix 10 107 | if (radix == 10 && sign) { 108 | temp[temp_loc] = '-'; 109 | } else { 110 | temp_loc--; 111 | } 112 | 113 | 114 | //now reverse the string. 115 | while ( temp_loc >=0 ) {// while there are still chars 116 | str[str_loc++] = temp[temp_loc--]; 117 | } 118 | str[str_loc] = 0; // add null termination. 119 | 120 | return str; 121 | } 122 | 123 | char *ultoa(unsigned long num, char *str, int radix) { 124 | char temp[33]; //an int can only be 16 bits long 125 | //at radix 2 (binary) the string 126 | //is at most 16 + 1 null long. 127 | int temp_loc = 0; 128 | int digit; 129 | int str_loc = 0; 130 | 131 | //construct a backward string of the number. 132 | do { 133 | digit = (unsigned long)num % radix; 134 | if (digit < 10) 135 | temp[temp_loc++] = digit + '0'; 136 | else 137 | temp[temp_loc++] = digit - 10 + 'A'; 138 | num = ((unsigned long)num) / radix; 139 | } while ((unsigned long)num > 0); 140 | 141 | temp_loc--; 142 | 143 | 144 | //now reverse the string. 145 | while ( temp_loc >=0 ) {// while there are still chars 146 | str[str_loc++] = temp[temp_loc--]; 147 | } 148 | str[str_loc] = 0; // add null termination. 149 | 150 | return str; 151 | } 152 | 153 | char *dtostrf(double value, unsigned char d1, unsigned char d2, char *buf) { 154 | return (char *) "888"; 155 | } 156 | 157 | #define strcpy_P strcpy 158 | #define strlen_P strlen 159 | typedef const char *PSTR; 160 | typedef const char *PGM_P; 161 | #include "LocalWString.cpp" 162 | 163 | class Print { 164 | public: 165 | Print() {} 166 | Print(unsigned rx, unsigned tx) {} 167 | void begin(int i) {} 168 | void print(const char *s) { printf(s); } 169 | void print(const String &s) { printf(s.c_str()); } 170 | void print(int i) { printf("%d", i); } 171 | void print(float f) { printf("%f", f); } 172 | void println(const char *s) { puts(s); } 173 | void println(const String &s) { puts(s.c_str()); } 174 | void println(int i) { printf("%d\n", i); } 175 | void println(float f) { printf("%f\n", f); } 176 | void flush() {} 177 | void listen() {} 178 | void write(uint8_t ch) { putchar(ch); } 179 | int read() { return -1; } 180 | bool available() { return false; } 181 | void end() {} 182 | }; 183 | Print Serial; 184 | 185 | class SoftwareSerial: public Print { 186 | public: 187 | SoftwareSerial(unsigned rx, unsigned tx): Print(rx, tx) {} 188 | }; 189 | 190 | unsigned long millis() { 191 | return (unsigned long) clock(); 192 | } 193 | 194 | void delay(long i) { // Milliseconds. 195 | const unsigned long start = millis(); 196 | for (;;) { 197 | if (millis() - start > i) return; 198 | } 199 | } 200 | 201 | typedef uint8_t byte; 202 | 203 | #endif // ARDUINO 204 | --------------------------------------------------------------------------------