Sigfox Communication library, allowing you to use any kind of UART able Sigfox Transmitter
Dependents: TestVirtualisation
Revision 3:3ef537a95c15, committed 2019-01-15
- Comitter:
- Sidibe
- Date:
- Tue Jan 15 15:18:38 2019 +0000
- Parent:
- 2:975b82a3cde0
- Commit message:
- bonjour
Changed in this revision
sigfox.cpp | Show annotated file Show diff for this revision Revisions of this file |
sigfox.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/sigfox.cpp Sat Mar 12 16:00:57 2016 +0000 +++ b/sigfox.cpp Tue Jan 15 15:18:38 2019 +0000 @@ -5,19 +5,22 @@ Sigfox_ Sigfox; Sigfox_::Sigfox_() { - Serial device(PIN_RX, PIN_TX); + Serial device(PIN_TX, PIN_RX); _lastSend=-1; } uint8_t Sigfox_::_nextReturn() { - Serial device(PIN_RX, PIN_TX); + Serial sc(SERIAL_TX, SERIAL_RX, 9600); + Serial device(PIN_TX, PIN_RX); char fstChar = device.getc(); - while(device.getc() != ';'); + sc.printf("hola\n"); + // while(device.getc() != ';'); + sc.printf("momo\n"); return fstChar; } void Sigfox_::begin () { - Serial device(PIN_RX, PIN_TX); + Serial device(PIN_TX, PIN_RX); device.putc((uint8_t)'\0'); device.putc((uint8_t)';'); @@ -29,28 +32,31 @@ } bool Sigfox_::isReady() { - Serial device(PIN_RX, PIN_TX); + Serial device(PIN_TX, PIN_RX); - unsigned long currentTime = millis(); + /* unsigned long currentTime = millis(); if(currentTime >= _lastSend && (currentTime - _lastSend) <= 600000) { return false; - } + }*/ // Time is ok, ask the modem's status device.putc((uint8_t)'\0'); device.putc((uint8_t)'A'); device.putc((uint8_t)'T'); device.putc('\r'); //device.putc((uint8_t)';'); - - //return _nextReturn() == OK; + + + // return _nextReturn() == OK; return true; } bool Sigfox_::send(const void* data, uint8_t len) { + Serial sc(SERIAL_TX, SERIAL_RX, 9600); + sc.printf("sending ... \n"); + uint8_t* bytes = (uint8_t*)data; - _lastSend = millis(); - - Serial device(PIN_RX, PIN_TX); + // _lastSend = millis(); + Serial device(PIN_TX, PIN_RX); device.putc((uint8_t)'\0'); device.putc((uint8_t)'A'); device.putc((uint8_t)'T'); @@ -59,22 +65,25 @@ device.putc((uint8_t)'F'); device.putc((uint8_t)'='); + sc.printf("coucou 0\n"); for(uint8_t i = 0; i < len; ++i) { device.putc(bytes[i]); } device.putc('\r'); - - uint8_t ok = _nextReturn(); + sc.printf("coucou 1 \n"); + /* uint8_t ok = _nextReturn(); if(ok == OK) { _nextReturn(); //SENT return true; } - return false; + sc.printf("coucou 2\n"); + return false;*/ + return true; } unsigned long Sigfox_::getID() { unsigned long id = 0; - Serial device(PIN_RX, PIN_TX); + Serial device(PIN_TX, PIN_RX); device.putc((uint8_t)'\0'); device.putc((uint8_t)'A'); device.putc((uint8_t)'T'); @@ -106,7 +115,7 @@ unsigned long Sigfox_::getPAC() { unsigned long id = 0; - Serial device(PIN_RX, PIN_TX); + Serial device(PIN_TX, PIN_RX); device.putc((uint8_t)'\0'); device.putc((uint8_t)'A'); device.putc((uint8_t)'T'); @@ -127,11 +136,11 @@ for(uint8_t j = 0; j < i; ++j) { id += response[j] << ((i-3-j) * 16); } - return true; + return id; } bool Sigfox_::setPowerMode(uint8_t power) { - Serial device(PIN_RX, PIN_TX); + Serial device(PIN_TX, PIN_RX); device.putc((uint8_t)'\0'); device.putc((uint8_t)'A'); device.putc((uint8_t)'T');
--- a/sigfox.h Sat Mar 12 16:00:57 2016 +0000 +++ b/sigfox.h Tue Jan 15 15:18:38 2019 +0000 @@ -5,8 +5,8 @@ //Define your baudrate and pins here #define BAUDRATE 9600 -#define PIN_RX p19 -#define PIN_TX p18 +#define PIN_RX PA_10 +#define PIN_TX PA_9 class Sigfox_ {