ruche upmc

Dependents:   Final

Fork of Sigfox by Raffaello Bonghi

Committer:
dahmani_belkacem
Date:
Wed Jan 17 14:30:08 2018 +0000
Revision:
12:43a4b8ba4635
Parent:
11:7e21590031dd
Sigfox ruche

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