| 
 | 1 | +/***********************************  | 
 | 2 | + * AntPlus Environment Display example  | 
 | 3 | + *  | 
 | 4 | + * Finds a nearby environment monitor, pairs  | 
 | 5 | + * to it and then reads the information  | 
 | 6 | + * out via the serial port.  | 
 | 7 | + *  | 
 | 8 | + * Author Curtis Malainey  | 
 | 9 | + ************************************/  | 
 | 10 | +#include <Arduino.h>  | 
 | 11 | +#include "ANT.h"  | 
 | 12 | +#include "ANTPLUS.h"  | 
 | 13 | + | 
 | 14 | +#define BAUD_RATE 9600  | 
 | 15 | +#define CHANNEL_0 0  | 
 | 16 | + | 
 | 17 | +const uint8_t NETWORK_KEY[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; // get this from thisisant.com  | 
 | 18 | + | 
 | 19 | +AntWithCallbacks ant = AntWithCallbacks();  | 
 | 20 | +AntPlusRouter router = AntPlusRouter();  | 
 | 21 | +ProfileEnvironmentDisplay env = ProfileEnvironmentDisplay();  | 
 | 22 | + | 
 | 23 | +void generalInformationDataPageHandler(EnvironmentGeneralInformation& msg, uintptr_t data);  | 
 | 24 | +void temperatureDataPageHandler(EnvironmentTemperature& msg, uintptr_t data);  | 
 | 25 | +void manufacturersInformationDataPageHandler(ManufacturersInformation& msg, uintptr_t data);  | 
 | 26 | +void productInformationDataPageHandler(ProductInformation& msg, uintptr_t data);  | 
 | 27 | + | 
 | 28 | +void printStatus(uint8_t status);  | 
 | 29 | + | 
 | 30 | +void setup() {  | 
 | 31 | + Serial1.begin(BAUD_RATE);  | 
 | 32 | + ant.setSerial(Serial1);  | 
 | 33 | + delay(15000);  | 
 | 34 | + | 
 | 35 | + router.setDriver(&ant); // never touch ant again  | 
 | 36 | + router.setAntPlusNetworkKey(NETWORK_KEY);  | 
 | 37 | + router.setProfile(CHANNEL_0, &env);  | 
 | 38 | + // Delay after initial setup to wait for user to connect on serial  | 
 | 39 | + | 
 | 40 | + Serial.begin(BAUD_RATE);  | 
 | 41 | + Serial.println("Running");  | 
 | 42 | + env.onEnvironmentGeneralInformation(generalInformationDataPageHandler);  | 
 | 43 | + env.onEnvironmentTemperature(temperatureDataPageHandler);  | 
 | 44 | + env.onManufacturersInformation(manufacturersInformationDataPageHandler);  | 
 | 45 | + env.onProductInformation(productInformationDataPageHandler);  | 
 | 46 | + env.begin();  | 
 | 47 | + // wait for pair to complete  | 
 | 48 | + uint8_t status = env.waitForPair();  | 
 | 49 | + // print channel status  | 
 | 50 | + Serial.println("===========================");  | 
 | 51 | + printStatus(status);  | 
 | 52 | + Serial.print("Device Number: ");  | 
 | 53 | + Serial.println(env.getDeviceNumber());  | 
 | 54 | + Serial.print("Transmisison Type: ");  | 
 | 55 | + Serial.println(env.getTransmissionType());  | 
 | 56 | +}  | 
 | 57 | + | 
 | 58 | +void loop() {  | 
 | 59 | + router.loop();  | 
 | 60 | +}  | 
 | 61 | + | 
 | 62 | +void generalInformationDataPageHandler(EnvironmentGeneralInformation& msg, uintptr_t data) {  | 
 | 63 | + Serial.println("===========================");  | 
 | 64 | + Serial.print("Local Time: ");  | 
 | 65 | + Serial.println(msg.getTransmissionInfoLocalTime());  | 
 | 66 | + Serial.print("UTC Time: ");  | 
 | 67 | + Serial.println(msg.getTransmissionInfoUtcTime());  | 
 | 68 | + Serial.print("Default Transmisison Rate: ");  | 
 | 69 | + if (msg.getTransmissionInfoDefaultTransmissionRate() == 0) {  | 
 | 70 | + Serial.println("0.5Hz");  | 
 | 71 | + } else if (msg.getTransmissionInfoDefaultTransmissionRate() == 1) {  | 
 | 72 | + Serial.println("4Hz");  | 
 | 73 | + } else {  | 
 | 74 | + Serial.println("Unknown");  | 
 | 75 | + }  | 
 | 76 | + Serial.println("Supported Pages: ");  | 
 | 77 | + if (msg.getSupportedPages() & ANTPLUS_ENVIRONMENT_DATAPAGE_GENERALINFORMATION_SUPPORTEDPAGES_PAGE0SUPPORT) {  | 
 | 78 | + Serial.println("Page 0 Supported");  | 
 | 79 | + }  | 
 | 80 | + if (msg.getSupportedPages() & ANTPLUS_ENVIRONMENT_DATAPAGE_GENERALINFORMATION_SUPPORTEDPAGES_PAGE1SUPPORT) {  | 
 | 81 | + Serial.println("Page 1 Supported");  | 
 | 82 | + }  | 
 | 83 | +}  | 
 | 84 | + | 
 | 85 | +void temperatureDataPageHandler(EnvironmentTemperature& msg, uintptr_t data) {  | 
 | 86 | + Serial.println("===========================");  | 
 | 87 | + Serial.print("Event Count: ");  | 
 | 88 | + Serial.println(msg.getEventCount());  | 
 | 89 | + Serial.print("24h Low (C): ");  | 
 | 90 | + Serial.println(msg.get24HourLow()*0.1);  | 
 | 91 | + Serial.print("24h High (C): ");  | 
 | 92 | + Serial.println(msg.get24HourHigh()*0.1);  | 
 | 93 | + Serial.print("Current Temp (C): ");  | 
 | 94 | + Serial.println(msg.getCurrentTemp()*0.01);  | 
 | 95 | +}  | 
 | 96 | + | 
 | 97 | +void manufacturersInformationDataPageHandler(ManufacturersInformation& msg, uintptr_t data) {  | 
 | 98 | + Serial.println("===========================");  | 
 | 99 | + Serial.print("HW Revision: ");  | 
 | 100 | + Serial.println(msg.getHWRevision());  | 
 | 101 | + Serial.print("ManufacturerID: ");  | 
 | 102 | + Serial.println(msg.getManufacturerID());  | 
 | 103 | + Serial.print("Model Number: ");  | 
 | 104 | + Serial.println(msg.getModelNumber());  | 
 | 105 | +}  | 
 | 106 | + | 
 | 107 | +void productInformationDataPageHandler(ProductInformation& msg, uintptr_t data) {  | 
 | 108 | + Serial.println("===========================");  | 
 | 109 | + Serial.print("SW Revision Supplemental: ");  | 
 | 110 | + Serial.println(msg.getSWRevisionSupplemental());  | 
 | 111 | + Serial.print("SW Revision Main: ");  | 
 | 112 | + Serial.println(msg.getSWRevisionMain());  | 
 | 113 | + Serial.print("Serial Number: ");  | 
 | 114 | + Serial.println(msg.getSerialNumber());  | 
 | 115 | +}  | 
 | 116 | + | 
 | 117 | +void printStatus(uint8_t status) {  | 
 | 118 | + Serial.print("Channel Status: ");  | 
 | 119 | + switch (status) {  | 
 | 120 | + case CHANNEL_STATUS_UNASSIGNED:  | 
 | 121 | + Serial.println("Unassigned");  | 
 | 122 | + break;  | 
 | 123 | + case CHANNEL_STATUS_ASSIGNED:  | 
 | 124 | + Serial.println("Assigned");  | 
 | 125 | + break;  | 
 | 126 | + case CHANNEL_STATUS_SEARCHING:  | 
 | 127 | + Serial.println("Searching");  | 
 | 128 | + break;  | 
 | 129 | + case CHANNEL_STATUS_TRACKING:  | 
 | 130 | + Serial.println("Tracking");  | 
 | 131 | + break;  | 
 | 132 | + }  | 
 | 133 | +}  | 
0 commit comments