项目作者: pilotak

项目描述 :
Mbed library for Wisol WSSFM10 SigFox modem
高级语言: C++
项目地址: git://github.com/pilotak/wisol.git
创建时间: 2020-07-23T11:12:37Z
项目社区:https://github.com/pilotak/wisol

开源协议:MIT License

下载


Mbed Wisol library

Framework Badge mbed

Mbed library for Wisol WSSFM10 SigFox modem

Example

  1. #include "mbed.h"
  2. #include "Wisol.h"
  3. Wisol wisol(PC_4, PC_5);
  4. int main() {
  5. if (!wisol.init()) {
  6. printf("Could not init");
  7. return 0;
  8. }
  9. uint8_t data[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C};
  10. if (wisol.sendFrame(data, sizeof(data))) {
  11. printf("Message sent!\n");
  12. } else {
  13. printf("Sending message failed\n");
  14. }
  15. return 0;
  16. }

Detailed example

mbed_app.json

  1. {
  2. "config": {
  3. "trace-level": {
  4. "help": "Options are TRACE_LEVEL_ERROR,TRACE_LEVEL_WARN,TRACE_LEVEL_INFO,TRACE_LEVEL_DEBUG",
  5. "macro_name": "MBED_TRACE_MAX_LEVEL",
  6. "value": "TRACE_LEVEL_DEBUG"
  7. }
  8. },
  9. "target_overrides": {
  10. "*": {
  11. "mbed-trace.enable": true,
  12. "target.printf_lib": "std"
  13. }
  14. }
  15. }

main.cpp

  1. #include "mbed.h"
  2. #include "Wisol.h"
  3. #if MBED_CONF_MBED_TRACE_ENABLE
  4. #include "mbed-trace/mbed_trace.h"
  5. static Mutex trace_mutex;
  6. static void trace_wait() {
  7. trace_mutex.lock();
  8. }
  9. static void trace_release() {
  10. trace_mutex.unlock();
  11. }
  12. void trace_init() {
  13. mbed_trace_init();
  14. mbed_trace_mutex_wait_function_set(trace_wait);
  15. mbed_trace_mutex_release_function_set(trace_release);
  16. }
  17. #endif
  18. Wisol wisol(PC_4, PC_5);
  19. int main() {
  20. #if MBED_CONF_MBED_TRACE_ENABLE
  21. trace_init();
  22. #endif
  23. uint8_t data[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C};
  24. uint8_t id[SIGFOX_ID_LENGTH];
  25. uint8_t pac[SIGFOX_PAC_LENGTH];
  26. if (!wisol.init(true)) {
  27. printf("Could not init");
  28. return 0;
  29. }
  30. wisol.getId(id);
  31. wisol.getPac(pac);
  32. wisol.setTransmitRepeat(2);
  33. wisol.sendFrame(data, sizeof(data));
  34. wisol.getTemperature(nullptr);
  35. wisol.getVoltage(nullptr, nullptr);
  36. if (wisol.setPowerMode(Wisol::Sleep)) {
  37. ThisThread::sleep_for(5s);
  38. wisol.sendBreak();
  39. while (!wisol.init(true)) {
  40. ThisThread::sleep_for(250ms);
  41. }
  42. }
  43. wisol.reset();
  44. return 0;
  45. }