Sigfox library with integration of ATParser

Committer:
Raffaello
Date:
Sat Sep 09 17:21:03 2017 +0000
Revision:
11:7e21590031dd
Parent:
10:8ff45b9e136b
Fixed error lng ID and PAC

Who changed what in which revision?

UserRevisionLine numberNew 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 // 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 }
Raffaello 1:93450d8b2540 24 }
Raffaello 1:93450d8b2540 25
Raffaello 4:c77d5019b264 26 bool Sigfox::setKey(bool type) {
Raffaello 4:c77d5019b264 27 _at->send("ATS410=%d", type);
Raffaello 4:c77d5019b264 28 return _at->recv("OK");
Raffaello 4:c77d5019b264 29 }
Raffaello 4:c77d5019b264 30
Raffaello 2:d07e3b39ff74 31 bool Sigfox::setPower(uint8_t power) {
Raffaello 2:d07e3b39ff74 32 _at->send("ATS302=%d", power);
Raffaello 2:d07e3b39ff74 33 return _at->recv("OK");
Raffaello 2:d07e3b39ff74 34 }
Raffaello 2:d07e3b39ff74 35
Raffaello 1:93450d8b2540 36 bool Sigfox::setPowerMode(uint8_t power) {
Raffaello 1:93450d8b2540 37 _at->send("AT$P=%d", power);
Raffaello 1:93450d8b2540 38 return _at->recv("OK");
Raffaello 1:93450d8b2540 39 }
Raffaello 1:93450d8b2540 40
Raffaello 5:66e05787ad5c 41 bool Sigfox::saveConfig() {
Raffaello 5:66e05787ad5c 42 _at->send("AT$WR");
Raffaello 5:66e05787ad5c 43 return _at->recv("OK");
Raffaello 5:66e05787ad5c 44 }
Raffaello 5:66e05787ad5c 45
Raffaello 2:d07e3b39ff74 46 void Sigfox::wakeup(DigitalInOut sig_rst, float time) {
Raffaello 2:d07e3b39ff74 47 // Wake up sigfox
Raffaello 2:d07e3b39ff74 48 sig_rst.output();
Raffaello 2:d07e3b39ff74 49 sig_rst = 0;
Raffaello 2:d07e3b39ff74 50 wait(time);
Raffaello 2:d07e3b39ff74 51 // Set high impendance the sigfox reset pin
Raffaello 2:d07e3b39ff74 52 sig_rst.input();
Raffaello 2:d07e3b39ff74 53 wait(time);
Raffaello 1:93450d8b2540 54 }
Raffaello 1:93450d8b2540 55
Raffaello 2:d07e3b39ff74 56 char *Sigfox::getID() {
Raffaello 2:d07e3b39ff74 57 char buff[8+2];
Raffaello 2:d07e3b39ff74 58 _at->send("AT$I=10");
Raffaello 2:d07e3b39ff74 59 _at->read(buff, 8+2);
Raffaello 11:7e21590031dd 60 memcpy(&ID[0],&buff[0],8);
Raffaello 2:d07e3b39ff74 61 return &ID[0];
Raffaello 2:d07e3b39ff74 62 }
Raffaello 2:d07e3b39ff74 63
Raffaello 2:d07e3b39ff74 64 char *Sigfox::getPAC() {
Raffaello 2:d07e3b39ff74 65 char buff[16+2];
Raffaello 1:93450d8b2540 66 _at->send("AT$I=11");
Raffaello 2:d07e3b39ff74 67 _at->read(buff, 16+2);
Raffaello 11:7e21590031dd 68 memcpy(&PAC[0],&buff[0],16);
Raffaello 2:d07e3b39ff74 69 return &PAC[0];
Raffaello 6:799a482a7024 70 }
Raffaello 6:799a482a7024 71
Raffaello 8:b10abac6a42e 72 float Sigfox::getTemperature() {
Raffaello 8:b10abac6a42e 73 char buff[6];
Raffaello 8:b10abac6a42e 74 _at->send("AT$T?");
Raffaello 8:b10abac6a42e 75 _at->read(buff, 6);
Raffaello 8:b10abac6a42e 76 buff[5] = 0;
Raffaello 8:b10abac6a42e 77 return ((double)atoi(buff))/10;
Raffaello 8:b10abac6a42e 78 }
Raffaello 8:b10abac6a42e 79
Raffaello 6:799a482a7024 80 sigfoxvoltage_t Sigfox::getVoltages() {
Raffaello 6:799a482a7024 81 sigfoxvoltage_t volt;
Raffaello 6:799a482a7024 82 char buff[12];
Raffaello 6:799a482a7024 83 _at->send("AT$V?");
Raffaello 6:799a482a7024 84 _at->read(buff, 12);
Raffaello 6:799a482a7024 85 char buff2[5];
Raffaello 6:799a482a7024 86 memset(buff2,0,5);
Raffaello 6:799a482a7024 87 memcpy(buff2, &buff[0], 4);
Raffaello 6:799a482a7024 88 volt.current = ((double)atoi(buff2))/1000;
Raffaello 6:799a482a7024 89 memset(buff2,0,5);
Raffaello 6:799a482a7024 90 memcpy(buff2, &buff[6], 4);
Raffaello 6:799a482a7024 91 volt.last = ((double)atoi(buff2))/1000;
Raffaello 6:799a482a7024 92 return volt;
Raffaello 0:5e0ae613c18c 93 }