sigfox

Fork of Sigfox by Belkacem DAHMANI

Committer:
helmi_heyliot
Date:
Tue Feb 27 12:45:51 2018 +0000
Revision:
15:5cac9747f00f
Parent:
14:e858a765590a
v0 dev heymag;

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 }
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
helmi_heyliot 15:5cac9747f00f 34 _at->send("AT$SF=%s", 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
helmi_heyliot 15:5cac9747f00f 46 bool Sigfox::setCwEU(uint8_t mode ,uint8_t power) {
helmi_heyliot 15:5cac9747f00f 47 _at->send("AT$CW=868130000,%d,%d",mode,power);
helmi_heyliot 15:5cac9747f00f 48 return _at->recv("OK");
helmi_heyliot 15:5cac9747f00f 49 }
helmi_heyliot 15:5cac9747f00f 50
helmi_heyliot 15:5cac9747f00f 51
Raffaello 2:d07e3b39ff74 52 bool Sigfox::setPower(uint8_t power) {
Raffaello 2:d07e3b39ff74 53 _at->send("ATS302=%d", power);
Raffaello 2:d07e3b39ff74 54 return _at->recv("OK");
Raffaello 2:d07e3b39ff74 55 }
Raffaello 2:d07e3b39ff74 56
Raffaello 1:93450d8b2540 57 bool Sigfox::setPowerMode(uint8_t power) {
Raffaello 1:93450d8b2540 58 _at->send("AT$P=%d", power);
Raffaello 1:93450d8b2540 59 return _at->recv("OK");
Raffaello 1:93450d8b2540 60 }
Raffaello 1:93450d8b2540 61
Raffaello 5:66e05787ad5c 62 bool Sigfox::saveConfig() {
Raffaello 5:66e05787ad5c 63 _at->send("AT$WR");
Raffaello 5:66e05787ad5c 64 return _at->recv("OK");
Raffaello 5:66e05787ad5c 65 }
Raffaello 5:66e05787ad5c 66
Raffaello 2:d07e3b39ff74 67 void Sigfox::wakeup(DigitalInOut sig_rst, float time) {
Raffaello 2:d07e3b39ff74 68 // Wake up sigfox
Raffaello 2:d07e3b39ff74 69 sig_rst.output();
Raffaello 2:d07e3b39ff74 70 sig_rst = 0;
Raffaello 2:d07e3b39ff74 71 wait(time);
Raffaello 2:d07e3b39ff74 72 // Set high impendance the sigfox reset pin
Raffaello 2:d07e3b39ff74 73 sig_rst.input();
Raffaello 2:d07e3b39ff74 74 wait(time);
Raffaello 1:93450d8b2540 75 }
Raffaello 1:93450d8b2540 76
Raffaello 2:d07e3b39ff74 77 char *Sigfox::getID() {
helmi_heyliot 14:e858a765590a 78 char *id;
helmi_heyliot 14:e858a765590a 79 id = new char[8+2+2];
Raffaello 2:d07e3b39ff74 80 _at->send("AT$I=10");
helmi_heyliot 14:e858a765590a 81 _at->read(id, 8+2+2);
helmi_heyliot 14:e858a765590a 82 memcpy(&ID[0],&id[2],9);
helmi_heyliot 14:e858a765590a 83 ID[9] = '\0';
Raffaello 2:d07e3b39ff74 84 return &ID[0];
Raffaello 2:d07e3b39ff74 85 }
Raffaello 2:d07e3b39ff74 86
Raffaello 2:d07e3b39ff74 87 char *Sigfox::getPAC() {
helmi_heyliot 14:e858a765590a 88 char *pac;
helmi_heyliot 14:e858a765590a 89 pac= new char[16+2+2];
Raffaello 1:93450d8b2540 90 _at->send("AT$I=11");
helmi_heyliot 14:e858a765590a 91 _at->read(pac, 16+2+2);
helmi_heyliot 14:e858a765590a 92 memcpy(&PAC[0],&pac[2],17);
helmi_heyliot 14:e858a765590a 93 PAC[17] = '\0';
Raffaello 2:d07e3b39ff74 94 return &PAC[0];
Raffaello 6:799a482a7024 95 }
Raffaello 6:799a482a7024 96
Raffaello 8:b10abac6a42e 97 float Sigfox::getTemperature() {
Raffaello 8:b10abac6a42e 98 char buff[6];
Raffaello 8:b10abac6a42e 99 _at->send("AT$T?");
Raffaello 8:b10abac6a42e 100 _at->read(buff, 6);
Raffaello 8:b10abac6a42e 101 buff[5] = 0;
Raffaello 8:b10abac6a42e 102 return ((double)atoi(buff))/10;
Raffaello 8:b10abac6a42e 103 }
Raffaello 8:b10abac6a42e 104
Raffaello 6:799a482a7024 105 sigfoxvoltage_t Sigfox::getVoltages() {
Raffaello 6:799a482a7024 106 sigfoxvoltage_t volt;
Raffaello 6:799a482a7024 107 char buff[12];
Raffaello 6:799a482a7024 108 _at->send("AT$V?");
Raffaello 6:799a482a7024 109 _at->read(buff, 12);
Raffaello 6:799a482a7024 110 char buff2[5];
Raffaello 6:799a482a7024 111 memset(buff2,0,5);
Raffaello 6:799a482a7024 112 memcpy(buff2, &buff[0], 4);
Raffaello 6:799a482a7024 113 volt.current = ((double)atoi(buff2))/1000;
Raffaello 6:799a482a7024 114 memset(buff2,0,5);
Raffaello 6:799a482a7024 115 memcpy(buff2, &buff[6], 4);
Raffaello 6:799a482a7024 116 volt.last = ((double)atoi(buff2))/1000;
Raffaello 6:799a482a7024 117 return volt;
Raffaello 0:5e0ae613c18c 118 }