Sigfox library with integration of ATParser

Committer:
Raffaello
Date:
Wed Apr 19 20:57:38 2017 +0000
Revision:
2:d07e3b39ff74
Parent:
1:93450d8b2540
Child:
3:279bed56f354
Improved Sigfox messages

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 0:5e0ae613c18c 9 bool Sigfox::send(const char *data) {
Raffaello 0:5e0ae613c18c 10 _at->send("AT$SF=%s", data);
Raffaello 0:5e0ae613c18c 11 return _at->recv("OK");
Raffaello 1:93450d8b2540 12 }
Raffaello 1:93450d8b2540 13
Raffaello 2:d07e3b39ff74 14 bool Sigfox::setPower(uint8_t power) {
Raffaello 2:d07e3b39ff74 15 _at->send("ATS302=%d", power);
Raffaello 2:d07e3b39ff74 16 return _at->recv("OK");
Raffaello 2:d07e3b39ff74 17 }
Raffaello 2:d07e3b39ff74 18
Raffaello 1:93450d8b2540 19 bool Sigfox::setPowerMode(uint8_t power) {
Raffaello 1:93450d8b2540 20 _at->send("AT$P=%d", power);
Raffaello 1:93450d8b2540 21 return _at->recv("OK");
Raffaello 1:93450d8b2540 22 }
Raffaello 1:93450d8b2540 23
Raffaello 2:d07e3b39ff74 24 void Sigfox::wakeup(DigitalInOut sig_rst, float time) {
Raffaello 2:d07e3b39ff74 25 // Wake up sigfox
Raffaello 2:d07e3b39ff74 26 sig_rst.output();
Raffaello 2:d07e3b39ff74 27 sig_rst = 0;
Raffaello 2:d07e3b39ff74 28 wait(time);
Raffaello 2:d07e3b39ff74 29 // Set high impendance the sigfox reset pin
Raffaello 2:d07e3b39ff74 30 sig_rst.input();
Raffaello 2:d07e3b39ff74 31 wait(time);
Raffaello 1:93450d8b2540 32 }
Raffaello 1:93450d8b2540 33
Raffaello 2:d07e3b39ff74 34 char *Sigfox::getID() {
Raffaello 2:d07e3b39ff74 35 char buff[8+2];
Raffaello 2:d07e3b39ff74 36 _at->send("AT$I=10");
Raffaello 2:d07e3b39ff74 37 _at->read(buff, 8+2);
Raffaello 2:d07e3b39ff74 38 memcpy(&ID[0],&buff[2],8);
Raffaello 2:d07e3b39ff74 39 return &ID[0];
Raffaello 2:d07e3b39ff74 40 }
Raffaello 2:d07e3b39ff74 41
Raffaello 2:d07e3b39ff74 42 char *Sigfox::getPAC() {
Raffaello 2:d07e3b39ff74 43 char buff[16+2];
Raffaello 1:93450d8b2540 44 _at->send("AT$I=11");
Raffaello 2:d07e3b39ff74 45 _at->read(buff, 16+2);
Raffaello 2:d07e3b39ff74 46 memcpy(&PAC[0],&buff[2],16);
Raffaello 2:d07e3b39ff74 47 return &PAC[0];
Raffaello 0:5e0ae613c18c 48 }