Sigfox library with integration of ATParser
Sigfox.cpp@3:279bed56f354, 2017-05-01 (annotated)
- Committer:
- Raffaello
- Date:
- Mon May 01 08:26:05 2017 +0000
- Revision:
- 3:279bed56f354
- Parent:
- 2:d07e3b39ff74
- Child:
- 4:c77d5019b264
Added return message from sigfox
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 | 2:d07e3b39ff74 | 33 | bool Sigfox::setPower(uint8_t power) { |
Raffaello | 2:d07e3b39ff74 | 34 | _at->send("ATS302=%d", power); |
Raffaello | 2:d07e3b39ff74 | 35 | return _at->recv("OK"); |
Raffaello | 2:d07e3b39ff74 | 36 | } |
Raffaello | 2:d07e3b39ff74 | 37 | |
Raffaello | 1:93450d8b2540 | 38 | bool Sigfox::setPowerMode(uint8_t power) { |
Raffaello | 1:93450d8b2540 | 39 | _at->send("AT$P=%d", power); |
Raffaello | 1:93450d8b2540 | 40 | return _at->recv("OK"); |
Raffaello | 1:93450d8b2540 | 41 | } |
Raffaello | 1:93450d8b2540 | 42 | |
Raffaello | 2:d07e3b39ff74 | 43 | void Sigfox::wakeup(DigitalInOut sig_rst, float time) { |
Raffaello | 2:d07e3b39ff74 | 44 | // Wake up sigfox |
Raffaello | 2:d07e3b39ff74 | 45 | sig_rst.output(); |
Raffaello | 2:d07e3b39ff74 | 46 | sig_rst = 0; |
Raffaello | 2:d07e3b39ff74 | 47 | wait(time); |
Raffaello | 2:d07e3b39ff74 | 48 | // Set high impendance the sigfox reset pin |
Raffaello | 2:d07e3b39ff74 | 49 | sig_rst.input(); |
Raffaello | 2:d07e3b39ff74 | 50 | wait(time); |
Raffaello | 1:93450d8b2540 | 51 | } |
Raffaello | 1:93450d8b2540 | 52 | |
Raffaello | 2:d07e3b39ff74 | 53 | char *Sigfox::getID() { |
Raffaello | 2:d07e3b39ff74 | 54 | char buff[8+2]; |
Raffaello | 2:d07e3b39ff74 | 55 | _at->send("AT$I=10"); |
Raffaello | 2:d07e3b39ff74 | 56 | _at->read(buff, 8+2); |
Raffaello | 2:d07e3b39ff74 | 57 | memcpy(&ID[0],&buff[2],8); |
Raffaello | 2:d07e3b39ff74 | 58 | return &ID[0]; |
Raffaello | 2:d07e3b39ff74 | 59 | } |
Raffaello | 2:d07e3b39ff74 | 60 | |
Raffaello | 2:d07e3b39ff74 | 61 | char *Sigfox::getPAC() { |
Raffaello | 2:d07e3b39ff74 | 62 | char buff[16+2]; |
Raffaello | 1:93450d8b2540 | 63 | _at->send("AT$I=11"); |
Raffaello | 2:d07e3b39ff74 | 64 | _at->read(buff, 16+2); |
Raffaello | 2:d07e3b39ff74 | 65 | memcpy(&PAC[0],&buff[2],16); |
Raffaello | 2:d07e3b39ff74 | 66 | return &PAC[0]; |
Raffaello | 0:5e0ae613c18c | 67 | } |