sigfox
Fork of Sigfox by
Sigfox.cpp@13:9e1c2ea4742b, 2018-02-15 (annotated)
- Committer:
- helmi_heyliot
- Date:
- Thu Feb 15 11:01:23 2018 +0000
- Revision:
- 13:9e1c2ea4742b
- Parent:
- 12:43a4b8ba4635
- Child:
- 14:e858a765590a
setup; ;
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 | |
| dahmani_belkacem | 12:43a4b8ba4635 | 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 | // Wait return |
| Raffaello | 10:8ff45b9e136b | 17 | return _at->recv("RX=%[^\r]", response); |
| Raffaello | 3:279bed56f354 | 18 | } |
| Raffaello | 3:279bed56f354 | 19 | return false; |
| Raffaello | 3:279bed56f354 | 20 | } else { |
| Raffaello | 3:279bed56f354 | 21 | _at->send("AT$SF=%s", data); |
| Raffaello | 3:279bed56f354 | 22 | return _at->recv("OK"); |
| Raffaello | 3:279bed56f354 | 23 | } |
| dahmani_belkacem | 12:43a4b8ba4635 | 24 | }*/ |
| dahmani_belkacem | 12:43a4b8ba4635 | 25 | |
| dahmani_belkacem | 12:43a4b8ba4635 | 26 | |
| dahmani_belkacem | 12:43a4b8ba4635 | 27 | bool Sigfox::send(const char *data) { |
| dahmani_belkacem | 12:43a4b8ba4635 | 28 | // If require a response add plus in message |
| dahmani_belkacem | 12:43a4b8ba4635 | 29 | // Add request response data |
| dahmani_belkacem | 12:43a4b8ba4635 | 30 | _at->send("AT$SF=%s,1", data); |
| dahmani_belkacem | 12:43a4b8ba4635 | 31 | // Wait response from sigfox after send |
| helmi_heyliot | 13:9e1c2ea4742b | 32 | return _at->recv("OK"); |
| dahmani_belkacem | 12:43a4b8ba4635 | 33 | |
| Raffaello | 1:93450d8b2540 | 34 | } |
| Raffaello | 1:93450d8b2540 | 35 | |
| Raffaello | 4:c77d5019b264 | 36 | bool Sigfox::setKey(bool type) { |
| Raffaello | 4:c77d5019b264 | 37 | _at->send("ATS410=%d", type); |
| Raffaello | 4:c77d5019b264 | 38 | return _at->recv("OK"); |
| Raffaello | 4:c77d5019b264 | 39 | } |
| Raffaello | 4:c77d5019b264 | 40 | |
| Raffaello | 2:d07e3b39ff74 | 41 | bool Sigfox::setPower(uint8_t power) { |
| Raffaello | 2:d07e3b39ff74 | 42 | _at->send("ATS302=%d", power); |
| Raffaello | 2:d07e3b39ff74 | 43 | return _at->recv("OK"); |
| Raffaello | 2:d07e3b39ff74 | 44 | } |
| Raffaello | 2:d07e3b39ff74 | 45 | |
| Raffaello | 1:93450d8b2540 | 46 | bool Sigfox::setPowerMode(uint8_t power) { |
| Raffaello | 1:93450d8b2540 | 47 | _at->send("AT$P=%d", power); |
| Raffaello | 1:93450d8b2540 | 48 | return _at->recv("OK"); |
| Raffaello | 1:93450d8b2540 | 49 | } |
| Raffaello | 1:93450d8b2540 | 50 | |
| Raffaello | 5:66e05787ad5c | 51 | bool Sigfox::saveConfig() { |
| Raffaello | 5:66e05787ad5c | 52 | _at->send("AT$WR"); |
| Raffaello | 5:66e05787ad5c | 53 | return _at->recv("OK"); |
| Raffaello | 5:66e05787ad5c | 54 | } |
| Raffaello | 5:66e05787ad5c | 55 | |
| Raffaello | 2:d07e3b39ff74 | 56 | void Sigfox::wakeup(DigitalInOut sig_rst, float time) { |
| Raffaello | 2:d07e3b39ff74 | 57 | // Wake up sigfox |
| Raffaello | 2:d07e3b39ff74 | 58 | sig_rst.output(); |
| Raffaello | 2:d07e3b39ff74 | 59 | sig_rst = 0; |
| Raffaello | 2:d07e3b39ff74 | 60 | wait(time); |
| Raffaello | 2:d07e3b39ff74 | 61 | // Set high impendance the sigfox reset pin |
| Raffaello | 2:d07e3b39ff74 | 62 | sig_rst.input(); |
| Raffaello | 2:d07e3b39ff74 | 63 | wait(time); |
| Raffaello | 1:93450d8b2540 | 64 | } |
| Raffaello | 1:93450d8b2540 | 65 | |
| Raffaello | 2:d07e3b39ff74 | 66 | char *Sigfox::getID() { |
| Raffaello | 2:d07e3b39ff74 | 67 | char buff[8+2]; |
| Raffaello | 2:d07e3b39ff74 | 68 | _at->send("AT$I=10"); |
| Raffaello | 2:d07e3b39ff74 | 69 | _at->read(buff, 8+2); |
| Raffaello | 11:7e21590031dd | 70 | memcpy(&ID[0],&buff[0],8); |
| Raffaello | 2:d07e3b39ff74 | 71 | return &ID[0]; |
| Raffaello | 2:d07e3b39ff74 | 72 | } |
| Raffaello | 2:d07e3b39ff74 | 73 | |
| Raffaello | 2:d07e3b39ff74 | 74 | char *Sigfox::getPAC() { |
| Raffaello | 2:d07e3b39ff74 | 75 | char buff[16+2]; |
| Raffaello | 1:93450d8b2540 | 76 | _at->send("AT$I=11"); |
| Raffaello | 2:d07e3b39ff74 | 77 | _at->read(buff, 16+2); |
| Raffaello | 11:7e21590031dd | 78 | memcpy(&PAC[0],&buff[0],16); |
| Raffaello | 2:d07e3b39ff74 | 79 | return &PAC[0]; |
| Raffaello | 6:799a482a7024 | 80 | } |
| Raffaello | 6:799a482a7024 | 81 | |
| Raffaello | 8:b10abac6a42e | 82 | float Sigfox::getTemperature() { |
| Raffaello | 8:b10abac6a42e | 83 | char buff[6]; |
| Raffaello | 8:b10abac6a42e | 84 | _at->send("AT$T?"); |
| Raffaello | 8:b10abac6a42e | 85 | _at->read(buff, 6); |
| Raffaello | 8:b10abac6a42e | 86 | buff[5] = 0; |
| Raffaello | 8:b10abac6a42e | 87 | return ((double)atoi(buff))/10; |
| Raffaello | 8:b10abac6a42e | 88 | } |
| Raffaello | 8:b10abac6a42e | 89 | |
| Raffaello | 6:799a482a7024 | 90 | sigfoxvoltage_t Sigfox::getVoltages() { |
| Raffaello | 6:799a482a7024 | 91 | sigfoxvoltage_t volt; |
| Raffaello | 6:799a482a7024 | 92 | char buff[12]; |
| Raffaello | 6:799a482a7024 | 93 | _at->send("AT$V?"); |
| Raffaello | 6:799a482a7024 | 94 | _at->read(buff, 12); |
| Raffaello | 6:799a482a7024 | 95 | char buff2[5]; |
| Raffaello | 6:799a482a7024 | 96 | memset(buff2,0,5); |
| Raffaello | 6:799a482a7024 | 97 | memcpy(buff2, &buff[0], 4); |
| Raffaello | 6:799a482a7024 | 98 | volt.current = ((double)atoi(buff2))/1000; |
| Raffaello | 6:799a482a7024 | 99 | memset(buff2,0,5); |
| Raffaello | 6:799a482a7024 | 100 | memcpy(buff2, &buff[6], 4); |
| Raffaello | 6:799a482a7024 | 101 | volt.last = ((double)atoi(buff2))/1000; |
| Raffaello | 6:799a482a7024 | 102 | return volt; |
| Raffaello | 0:5e0ae613c18c | 103 | } |
