ruche upmc

Dependents:   Final

Fork of Sigfox by Raffaello Bonghi

Committer:
Raffaello
Date:
Thu May 18 17:32:00 2017 +0000
Revision:
4:c77d5019b264
Parent:
3:279bed56f354
Child:
5:66e05787ad5c
Added some new commands. Minor fixes

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 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 2:d07e3b39ff74 48 void Sigfox::wakeup(DigitalInOut sig_rst, float time) {
Raffaello 2:d07e3b39ff74 49 // Wake up sigfox
Raffaello 2:d07e3b39ff74 50 sig_rst.output();
Raffaello 2:d07e3b39ff74 51 sig_rst = 0;
Raffaello 2:d07e3b39ff74 52 wait(time);
Raffaello 2:d07e3b39ff74 53 // Set high impendance the sigfox reset pin
Raffaello 2:d07e3b39ff74 54 sig_rst.input();
Raffaello 2:d07e3b39ff74 55 wait(time);
Raffaello 1:93450d8b2540 56 }
Raffaello 1:93450d8b2540 57
Raffaello 2:d07e3b39ff74 58 char *Sigfox::getID() {
Raffaello 2:d07e3b39ff74 59 char buff[8+2];
Raffaello 2:d07e3b39ff74 60 _at->send("AT$I=10");
Raffaello 2:d07e3b39ff74 61 _at->read(buff, 8+2);
Raffaello 2:d07e3b39ff74 62 memcpy(&ID[0],&buff[2],8);
Raffaello 2:d07e3b39ff74 63 return &ID[0];
Raffaello 2:d07e3b39ff74 64 }
Raffaello 2:d07e3b39ff74 65
Raffaello 2:d07e3b39ff74 66 char *Sigfox::getPAC() {
Raffaello 2:d07e3b39ff74 67 char buff[16+2];
Raffaello 1:93450d8b2540 68 _at->send("AT$I=11");
Raffaello 2:d07e3b39ff74 69 _at->read(buff, 16+2);
Raffaello 2:d07e3b39ff74 70 memcpy(&PAC[0],&buff[2],16);
Raffaello 2:d07e3b39ff74 71 return &PAC[0];
Raffaello 0:5e0ae613c18c 72 }