Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Sigfox by
Sigfox.cpp@8:b10abac6a42e, 2017-06-04 (annotated)
- Committer:
- Raffaello
- Date:
- Sun Jun 04 16:06:45 2017 +0000
- Revision:
- 8:b10abac6a42e
- Parent:
- 6:799a482a7024
- Child:
- 10:8ff45b9e136b
Added temperature method
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 | 6:799a482a7024 | 67 | memcpy(&ID[0],&buff[2],8-2); |
| 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 | 6:799a482a7024 | 75 | memcpy(&PAC[0],&buff[2],16-2); |
| Raffaello | 2:d07e3b39ff74 | 76 | return &PAC[0]; |
| Raffaello | 6:799a482a7024 | 77 | } |
| Raffaello | 6:799a482a7024 | 78 | |
| Raffaello | 8:b10abac6a42e | 79 | float Sigfox::getTemperature() { |
| Raffaello | 8:b10abac6a42e | 80 | char buff[6]; |
| Raffaello | 8:b10abac6a42e | 81 | _at->send("AT$T?"); |
| Raffaello | 8:b10abac6a42e | 82 | _at->read(buff, 6); |
| Raffaello | 8:b10abac6a42e | 83 | buff[5] = 0; |
| Raffaello | 8:b10abac6a42e | 84 | return ((double)atoi(buff))/10; |
| Raffaello | 8:b10abac6a42e | 85 | } |
| Raffaello | 8:b10abac6a42e | 86 | |
| Raffaello | 6:799a482a7024 | 87 | sigfoxvoltage_t Sigfox::getVoltages() { |
| Raffaello | 6:799a482a7024 | 88 | sigfoxvoltage_t volt; |
| Raffaello | 6:799a482a7024 | 89 | char buff[12]; |
| Raffaello | 6:799a482a7024 | 90 | _at->send("AT$V?"); |
| Raffaello | 6:799a482a7024 | 91 | _at->read(buff, 12); |
| Raffaello | 6:799a482a7024 | 92 | char buff2[5]; |
| Raffaello | 6:799a482a7024 | 93 | memset(buff2,0,5); |
| Raffaello | 6:799a482a7024 | 94 | memcpy(buff2, &buff[0], 4); |
| Raffaello | 6:799a482a7024 | 95 | volt.current = ((double)atoi(buff2))/1000; |
| Raffaello | 6:799a482a7024 | 96 | memset(buff2,0,5); |
| Raffaello | 6:799a482a7024 | 97 | memcpy(buff2, &buff[6], 4); |
| Raffaello | 6:799a482a7024 | 98 | volt.last = ((double)atoi(buff2))/1000; |
| Raffaello | 6:799a482a7024 | 99 | return volt; |
| Raffaello | 0:5e0ae613c18c | 100 | } |
