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