AllWize Library
wize.cpp
Go to the documentation of this file.
1 /*
2 
3 WIZE MODULE
4 
5 */
6 
7 #include "wize.h"
8 #include "debug.h"
9 #include "forwarder.h"
10 #include "configuration.h"
11 
12 #include "AllWize_LoRaWAN.h"
13 
15 
16 double wizeFrequency(uint8_t channel) {
17  return allwize.getFrequency(channel);
18 }
19 
20 uint16_t wizeDataRateSpeed(uint8_t dr) {
21  return allwize.getDataRateSpeed(dr);
22 }
23 
24 void wizeSetup() {
25 
26  // Init AllWize object
27  allwize.begin();
28  if (!allwize.waitForReady()) {
29  DEBUG_MSG("[WIZE] Error connecting to the module, check your wiring!");
30  while (true);
31  }
32 
33  allwize.master();
36 
37  #if defined(DEBUG_PORT)
38  //allwize.dump(DEBUG_PORT);
39  #endif
40 
41  DEBUG_MSG("[WIZE] Listening... CH %d, DR %d\n", allwize.getChannel(), allwize.getDataRate());
42 
43 }
44 
46 
47  // Code to pretty-print the message
48  DEBUG_MSG(
49  "[WIZE] C: 0x%02X, MAN: %s, ADDR: 0x%02X%02X%02X%02X, TYPE: 0x%02X, VERSION: 0x%02X, CI: 0x%02X, RSSI: %3d, DATA: ",
50  message.c,
51  message.man,
52  message.address[0], message.address[1],
53  message.address[2], message.address[3],
54  message.type, message.version,
55  message.ci, (int16_t) message.rssi / -2
56  );
57 
58  for (uint8_t i=0; i<message.len; i++) {
59  DEBUG_MSG("%02x", message.data[i]);
60  }
61 
62  DEBUG_MSG("\n");
63 
64 }
65 
66 void wizeLoop() {
67 
68  if (allwize.available()) {
69 
70  // Get the message
71  allwize_message_t message = allwize.read();
72 
73  // Show it to console
74  wizeDebugMessage(message);
75 
76  // Forward it
77  forwarderMessage(message);
78 
79  }
80 
81 }
uint8_t getChannel()
Gets the channel stored in non-volatile memory.
Definition: AllWize.cpp:598
uint8_t rssi
Definition: AllWize.h:63
uint8_t data[RX_BUFFER_SIZE]
Definition: AllWize.h:62
double wizeFrequency(uint8_t channel)
Definition: wize.cpp:16
uint8_t version
Definition: AllWize.h:59
void wizeLoop()
Definition: wize.cpp:66
allwize_message_t read()
Returns latest received message (rebuilds LoRaWan header if necessary)
uint8_t len
Definition: AllWize.h:61
#define WIZE_CHANNEL
Definition: configuration.h:35
AllWize_LoRaWAN allwize(RX_PIN, TX_PIN, RESET_PIN)
char man[4]
Definition: AllWize.h:57
void begin(uint8_t baudrate=MODEM_DEFAULT_BAUDRATE)
Inits the module communications.
Definition: AllWize.cpp:91
uint8_t address[4]
Definition: AllWize.h:60
void wizeDebugMessage(allwize_message_t message)
Definition: wize.cpp:45
#define DEBUG_MSG(...)
Definition: debug.h:12
void master()
Sets the module in master mode.
Definition: AllWize.cpp:234
bool available()
Returns true if a new message has been received and decoded This method has to be called in the main ...
Definition: AllWize.cpp:457
uint16_t wizeDataRateSpeed(uint8_t dr)
Definition: wize.cpp:20
void forwarderMessage(allwize_message_t message)
Definition: forwarder.cpp:82
uint8_t ci
Definition: AllWize.h:56
bool waitForReady(uint32_t timeout=DEFAULT_TIMEOUT)
Waits for timeout millis for the module to be ready.
Definition: AllWize.cpp:294
double getFrequency(uint8_t channel)
Returns the frequency for the given channel.
Definition: AllWize.cpp:1135
void setChannel(uint8_t channel, bool persist=false)
Sets the communications channel (for MBUS_MODE_R2 only)
Definition: AllWize.cpp:583
#define TX_PIN
Definition: configuration.h:29
uint8_t type
Definition: AllWize.h:58
#define RESET_PIN
Definition: configuration.h:27
#define WIZE_DATARATE
Definition: configuration.h:36
uint16_t getDataRateSpeed(uint8_t dr)
Returns the speed for te given datarate.
Definition: AllWize.cpp:1160
#define RX_PIN
Definition: configuration.h:28
void setDataRate(uint8_t dr)
Sets the data rate.
Definition: AllWize.cpp:628
uint8_t getDataRate()
Gets the data rate stored in non-volatile memory.
Definition: AllWize.cpp:653
void wizeSetup()
Definition: wize.cpp:24