sigfox
Fork of Sigfox by
Sigfox.cpp
- Committer:
- dahmani_belkacem
- Date:
- 2018-01-17
- Revision:
- 12:43a4b8ba4635
- Parent:
- 11:7e21590031dd
- Child:
- 13:9e1c2ea4742b
File content as of revision 12:43a4b8ba4635:
#include "Sigfox.h"
bool Sigfox::ready() {
_at->send("AT");
return _at->recv("OK");
}
/*bool Sigfox::send(const char *data, char* response) {
// If require a response add plus in message
if(response != NULL) {
// Add request response data
_at->send("AT$SF=%s,1", data);
// Wait response from sigfox after send
if(_at->recv("OK")) {
// Wait return
return _at->recv("RX=%[^\r]", response);
}
return false;
} else {
_at->send("AT$SF=%s", data);
return _at->recv("OK");
}
}*/
bool Sigfox::send(const char *data) {
// If require a response add plus in message
// Add request response data
_at->send("AT$SF=%s,1", data);
// Wait response from sigfox after send
}
bool Sigfox::setKey(bool type) {
_at->send("ATS410=%d", type);
return _at->recv("OK");
}
bool Sigfox::setPower(uint8_t power) {
_at->send("ATS302=%d", power);
return _at->recv("OK");
}
bool Sigfox::setPowerMode(uint8_t power) {
_at->send("AT$P=%d", power);
return _at->recv("OK");
}
bool Sigfox::saveConfig() {
_at->send("AT$WR");
return _at->recv("OK");
}
void Sigfox::wakeup(DigitalInOut sig_rst, float time) {
// Wake up sigfox
sig_rst.output();
sig_rst = 0;
wait(time);
// Set high impendance the sigfox reset pin
sig_rst.input();
wait(time);
}
char *Sigfox::getID() {
char buff[8+2];
_at->send("AT$I=10");
_at->read(buff, 8+2);
memcpy(&ID[0],&buff[0],8);
return &ID[0];
}
char *Sigfox::getPAC() {
char buff[16+2];
_at->send("AT$I=11");
_at->read(buff, 16+2);
memcpy(&PAC[0],&buff[0],16);
return &PAC[0];
}
float Sigfox::getTemperature() {
char buff[6];
_at->send("AT$T?");
_at->read(buff, 6);
buff[5] = 0;
return ((double)atoi(buff))/10;
}
sigfoxvoltage_t Sigfox::getVoltages() {
sigfoxvoltage_t volt;
char buff[12];
_at->send("AT$V?");
_at->read(buff, 12);
char buff2[5];
memset(buff2,0,5);
memcpy(buff2, &buff[0], 4);
volt.current = ((double)atoi(buff2))/1000;
memset(buff2,0,5);
memcpy(buff2, &buff[6], 4);
volt.last = ((double)atoi(buff2))/1000;
return volt;
}
