Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Sigfox by
Sigfox.cpp
00001 00002 #include "Sigfox.h" 00003 00004 bool Sigfox::ready() { 00005 _at->send("AT"); 00006 return _at->recv("OK"); 00007 } 00008 bool Sigfox::reset() { 00009 _at->send("AT$P=0"); 00010 return _at->recv("OK"); 00011 } 00012 00013 /*bool Sigfox::send(const char *data, char* response) { 00014 // If require a response add plus in message 00015 if(response != NULL) { 00016 // Add request response data 00017 _at->send("AT$SF=%s,1", data); 00018 // Wait response from sigfox after send 00019 if(_at->recv("OK")) { 00020 // Wait return 00021 return _at->recv("RX=%[^\r]", response); 00022 } 00023 return false; 00024 } else { 00025 _at->send("AT$SF=%s", data); 00026 return _at->recv("OK"); 00027 } 00028 }*/ 00029 00030 00031 bool Sigfox::send(const char *data) { 00032 // If require a response add plus in message 00033 // Add request response data 00034 _at->send("AT$SF=%s", data); 00035 // Wait response from sigfox after send 00036 return _at->recv("OK"); 00037 00038 } 00039 00040 bool Sigfox::setKey(bool type) { 00041 _at->send("ATS410=%d", type); 00042 return _at->recv("OK"); 00043 } 00044 00045 00046 bool Sigfox::setCwEU(uint8_t mode ,uint8_t power) { 00047 _at->send("AT$CW=868130000,%d,%d",mode,power); 00048 return _at->recv("OK"); 00049 } 00050 00051 00052 bool Sigfox::setPower(uint8_t power) { 00053 _at->send("ATS302=%d", power); 00054 return _at->recv("OK"); 00055 } 00056 00057 bool Sigfox::setPowerMode(uint8_t power) { 00058 _at->send("AT$P=%d", power); 00059 return _at->recv("OK"); 00060 } 00061 00062 bool Sigfox::saveConfig() { 00063 _at->send("AT$WR"); 00064 return _at->recv("OK"); 00065 } 00066 00067 void Sigfox::wakeup(DigitalInOut sig_rst, float time) { 00068 // Wake up sigfox 00069 sig_rst.output(); 00070 sig_rst = 0; 00071 wait(time); 00072 // Set high impendance the sigfox reset pin 00073 sig_rst.input(); 00074 wait(time); 00075 } 00076 00077 char *Sigfox::getID() { 00078 char *id; 00079 id = new char[8+2+2]; 00080 _at->send("AT$I=10"); 00081 _at->read(id, 8+2+2); 00082 memcpy(&ID[0],&id[2],9); 00083 ID[9] = '\0'; 00084 return &ID[0]; 00085 } 00086 00087 char *Sigfox::getPAC() { 00088 char *pac; 00089 pac= new char[16+2+2]; 00090 _at->send("AT$I=11"); 00091 _at->read(pac, 16+2+2); 00092 memcpy(&PAC[0],&pac[2],17); 00093 PAC[17] = '\0'; 00094 return &PAC[0]; 00095 } 00096 00097 float Sigfox::getTemperature() { 00098 char buff[6]; 00099 _at->send("AT$T?"); 00100 _at->read(buff, 6); 00101 buff[5] = 0; 00102 return ((double)atoi(buff))/10; 00103 } 00104 00105 sigfoxvoltage_t Sigfox::getVoltages() { 00106 sigfoxvoltage_t volt; 00107 char buff[12]; 00108 _at->send("AT$V?"); 00109 _at->read(buff, 12); 00110 char buff2[5]; 00111 memset(buff2,0,5); 00112 memcpy(buff2, &buff[0], 4); 00113 volt.current = ((double)atoi(buff2))/1000; 00114 memset(buff2,0,5); 00115 memcpy(buff2, &buff[6], 4); 00116 volt.last = ((double)atoi(buff2))/1000; 00117 return volt; 00118 }
Generated on Fri Jul 29 2022 16:15:33 by
1.7.2
