Sigfox library with integration of ATParser
Sigfox.cpp@5:66e05787ad5c, 2017-05-27 (annotated)
- Committer:
- Raffaello
- Date:
- Sat May 27 10:55:06 2017 +0000
- Revision:
- 5:66e05787ad5c
- Parent:
- 4:c77d5019b264
- Child:
- 6:799a482a7024
Added store configuration
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Raffaello | 0:5e0ae613c18c | 1 | |
Raffaello | 0:5e0ae613c18c | 2 | #include "Sigfox.h" |
Raffaello | 0:5e0ae613c18c | 3 | |
Raffaello | 0:5e0ae613c18c | 4 | bool Sigfox::ready() { |
Raffaello | 0:5e0ae613c18c | 5 | _at->send("AT"); |
Raffaello | 0:5e0ae613c18c | 6 | return _at->recv("OK"); |
Raffaello | 0:5e0ae613c18c | 7 | } |
Raffaello | 0:5e0ae613c18c | 8 | |
Raffaello | 3:279bed56f354 | 9 | bool Sigfox::send(const char *data, char* response) { |
Raffaello | 3:279bed56f354 | 10 | // If require a response add plus in message |
Raffaello | 3:279bed56f354 | 11 | if(response != NULL) { |
Raffaello | 3:279bed56f354 | 12 | // Add request response data |
Raffaello | 3:279bed56f354 | 13 | _at->send("AT$SF=%s,1", data); |
Raffaello | 3:279bed56f354 | 14 | // Wait response from sigfox after send |
Raffaello | 3:279bed56f354 | 15 | if(_at->recv("OK")) { |
Raffaello | 3:279bed56f354 | 16 | char message[20]; |
Raffaello | 3:279bed56f354 | 17 | // Wait return |
Raffaello | 3:279bed56f354 | 18 | // TODO add loop to load data |
Raffaello | 3:279bed56f354 | 19 | if(_at->recv("+RX%s", &message)) { |
Raffaello | 3:279bed56f354 | 20 | // Check if message received is equal to " OK" |
Raffaello | 3:279bed56f354 | 21 | if(strcmp(message, " OK") == 0) { |
Raffaello | 3:279bed56f354 | 22 | return true; |
Raffaello | 3:279bed56f354 | 23 | } |
Raffaello | 3:279bed56f354 | 24 | } |
Raffaello | 3:279bed56f354 | 25 | } |
Raffaello | 3:279bed56f354 | 26 | return false; |
Raffaello | 3:279bed56f354 | 27 | } else { |
Raffaello | 3:279bed56f354 | 28 | _at->send("AT$SF=%s", data); |
Raffaello | 3:279bed56f354 | 29 | return _at->recv("OK"); |
Raffaello | 3:279bed56f354 | 30 | } |
Raffaello | 1:93450d8b2540 | 31 | } |
Raffaello | 1:93450d8b2540 | 32 | |
Raffaello | 4:c77d5019b264 | 33 | bool Sigfox::setKey(bool type) { |
Raffaello | 4:c77d5019b264 | 34 | _at->send("ATS410=%d", type); |
Raffaello | 4:c77d5019b264 | 35 | return _at->recv("OK"); |
Raffaello | 4:c77d5019b264 | 36 | } |
Raffaello | 4:c77d5019b264 | 37 | |
Raffaello | 2:d07e3b39ff74 | 38 | bool Sigfox::setPower(uint8_t power) { |
Raffaello | 2:d07e3b39ff74 | 39 | _at->send("ATS302=%d", power); |
Raffaello | 2:d07e3b39ff74 | 40 | return _at->recv("OK"); |
Raffaello | 2:d07e3b39ff74 | 41 | } |
Raffaello | 2:d07e3b39ff74 | 42 | |
Raffaello | 1:93450d8b2540 | 43 | bool Sigfox::setPowerMode(uint8_t power) { |
Raffaello | 1:93450d8b2540 | 44 | _at->send("AT$P=%d", power); |
Raffaello | 1:93450d8b2540 | 45 | return _at->recv("OK"); |
Raffaello | 1:93450d8b2540 | 46 | } |
Raffaello | 1:93450d8b2540 | 47 | |
Raffaello | 5:66e05787ad5c | 48 | bool Sigfox::saveConfig() { |
Raffaello | 5:66e05787ad5c | 49 | _at->send("AT$WR"); |
Raffaello | 5:66e05787ad5c | 50 | return _at->recv("OK"); |
Raffaello | 5:66e05787ad5c | 51 | } |
Raffaello | 5:66e05787ad5c | 52 | |
Raffaello | 2:d07e3b39ff74 | 53 | void Sigfox::wakeup(DigitalInOut sig_rst, float time) { |
Raffaello | 2:d07e3b39ff74 | 54 | // Wake up sigfox |
Raffaello | 2:d07e3b39ff74 | 55 | sig_rst.output(); |
Raffaello | 2:d07e3b39ff74 | 56 | sig_rst = 0; |
Raffaello | 2:d07e3b39ff74 | 57 | wait(time); |
Raffaello | 2:d07e3b39ff74 | 58 | // Set high impendance the sigfox reset pin |
Raffaello | 2:d07e3b39ff74 | 59 | sig_rst.input(); |
Raffaello | 2:d07e3b39ff74 | 60 | wait(time); |
Raffaello | 1:93450d8b2540 | 61 | } |
Raffaello | 1:93450d8b2540 | 62 | |
Raffaello | 2:d07e3b39ff74 | 63 | char *Sigfox::getID() { |
Raffaello | 2:d07e3b39ff74 | 64 | char buff[8+2]; |
Raffaello | 2:d07e3b39ff74 | 65 | _at->send("AT$I=10"); |
Raffaello | 2:d07e3b39ff74 | 66 | _at->read(buff, 8+2); |
Raffaello | 2:d07e3b39ff74 | 67 | memcpy(&ID[0],&buff[2],8); |
Raffaello | 2:d07e3b39ff74 | 68 | return &ID[0]; |
Raffaello | 2:d07e3b39ff74 | 69 | } |
Raffaello | 2:d07e3b39ff74 | 70 | |
Raffaello | 2:d07e3b39ff74 | 71 | char *Sigfox::getPAC() { |
Raffaello | 2:d07e3b39ff74 | 72 | char buff[16+2]; |
Raffaello | 1:93450d8b2540 | 73 | _at->send("AT$I=11"); |
Raffaello | 2:d07e3b39ff74 | 74 | _at->read(buff, 16+2); |
Raffaello | 2:d07e3b39ff74 | 75 | memcpy(&PAC[0],&buff[2],16); |
Raffaello | 2:d07e3b39ff74 | 76 | return &PAC[0]; |
Raffaello | 0:5e0ae613c18c | 77 | } |