Belkacem DAHMANI / Sigfox

Dependents:   Final

Fork of Sigfox by Raffaello Bonghi

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Sigfox.cpp Source File

Sigfox.cpp

00001 
00002 #include "Sigfox.h"
00003 
00004 bool Sigfox::ready() {
00005     _at->send("AT");
00006     return _at->recv("OK");
00007 }
00008 
00009 /*bool Sigfox::send(const char *data, char* response) {
00010     // If require a response add plus in message
00011     if(response != NULL) {
00012         // Add request response data
00013         _at->send("AT$SF=%s,1", data);
00014         // Wait response from sigfox after send
00015         if(_at->recv("OK")) {
00016             // Wait return
00017             return _at->recv("RX=%[^\r]", response);
00018         }
00019         return false;
00020     } else {
00021         _at->send("AT$SF=%s", data);
00022         return _at->recv("OK");
00023     }    
00024 }*/
00025 
00026 
00027 bool Sigfox::send(const char *data) {
00028     // If require a response add plus in message
00029         // Add request response data
00030         _at->send("AT$SF=%s,1", data);
00031         // Wait response from sigfox after send
00032 
00033 
00034   
00035    
00036 }
00037 
00038 bool Sigfox::setKey(bool type) {
00039     _at->send("ATS410=%d", type);
00040     return _at->recv("OK");
00041 }
00042 
00043 bool Sigfox::setPower(uint8_t power) {
00044     _at->send("ATS302=%d", power);
00045     return _at->recv("OK");
00046 }
00047 
00048 bool Sigfox::setPowerMode(uint8_t power) {
00049     _at->send("AT$P=%d", power);
00050     return _at->recv("OK");
00051 }
00052 
00053 bool Sigfox::saveConfig() {
00054     _at->send("AT$WR");
00055     return _at->recv("OK");
00056 }
00057 
00058 void Sigfox::wakeup(DigitalInOut sig_rst, float time) {
00059     // Wake up sigfox
00060     sig_rst.output();
00061     sig_rst = 0;
00062     wait(time);
00063     // Set high impendance the sigfox reset pin
00064     sig_rst.input();
00065     wait(time);
00066 }
00067 
00068 char *Sigfox::getID() {
00069     char buff[8+2];
00070     _at->send("AT$I=10");
00071     _at->read(buff, 8+2);
00072     memcpy(&ID[0],&buff[0],8);
00073     return &ID[0];
00074 }
00075 
00076 char *Sigfox::getPAC() {
00077     char buff[16+2];
00078     _at->send("AT$I=11");
00079     _at->read(buff, 16+2);
00080     memcpy(&PAC[0],&buff[0],16);
00081     return &PAC[0];
00082 }
00083 
00084 float Sigfox::getTemperature() {
00085     char buff[6];
00086     _at->send("AT$T?");
00087     _at->read(buff, 6);
00088     buff[5] = 0;
00089     return ((double)atoi(buff))/10;
00090 }
00091 
00092 sigfoxvoltage_t Sigfox::getVoltages() {
00093     sigfoxvoltage_t volt;
00094     char buff[12];
00095     _at->send("AT$V?");
00096     _at->read(buff, 12);
00097     char buff2[5];
00098     memset(buff2,0,5);
00099     memcpy(buff2, &buff[0], 4);
00100     volt.current = ((double)atoi(buff2))/1000;
00101     memset(buff2,0,5);
00102     memcpy(buff2, &buff[6], 4);
00103     volt.last = ((double)atoi(buff2))/1000;
00104     return volt;
00105 }