_gatewayMgt.ino 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // 1-channel LoRa Gateway for ESP8266
  2. // Copyright (c) 2016-2020 Maarten Westenberg
  3. //
  4. // Based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
  5. // and many others.
  6. //
  7. // All rights reserved. This program and the accompanying materials
  8. // are made available under the terms of the MIT License
  9. // which accompanies this distribution, and is available at
  10. // https://opensource.org/licenses/mit-license.php
  11. //
  12. // NO WARRANTY OF ANY KIND IS PROVIDED
  13. //
  14. // Author: Maarten Westenberg
  15. //
  16. // This file contains the functions to do management over UDP
  17. // We could make use of the LoRa message function for the Gateway sensor
  18. // itself. However the functions defined in this file are not sensor
  19. // functions and activating them through the LoRa interface would add
  20. // no value and make the code more complex.
  21. //
  22. // So advantage: Simple, and does not mess with TTN setup.
  23. //
  24. // Disadvantage of course is that you need to setup you own small backend
  25. // function to exchange messages with the gateway, as TTN won't do this.
  26. //
  27. // XXX But, if necessary we can always add this later.
  28. #if _GATEWAYMGT==1
  29. #if !defined _THINGPORT
  30. #error "The management functions needs _THINGPORT defined (and not over _TTNPORT)"
  31. #endif
  32. // ----------------------------------------------------------------------------
  33. // This function gateway_mgt is called in the UDP Receive function after
  34. // all well-known LoRa Gateway messages are scanned.
  35. //
  36. // As part of this function, we will listen for another set of messages
  37. // that is defined in loraModem.h.
  38. // All opCodes start with 0x1y for at leaving opcodes 0x00 to 0x0F to the
  39. // pure Gateway protocol
  40. //
  41. // Incoming mesage format:
  42. // buf[0]-buf[2], These are 0x00 or dont care
  43. // buf[3], contains opcode
  44. // buf[4]-buf[7], contains parameter max. 4 bytes.
  45. //
  46. // Upstream Message format:
  47. //
  48. // ----------------------------------------------------------------------------
  49. void gateway_mgt(uint8_t size, uint8_t *buff) {
  50. uint8_t opcode = buff[3];
  51. switch (opcode) {
  52. case MGT_RESET:
  53. Serial.println(F("gateway_mgt:: RESET"));
  54. // No further parameters, just reset the GWay
  55. setup(); // Call the sketch setup function
  56. // Send Ack to server
  57. break;
  58. case MGT_SET_SF:
  59. Serial.println(F("gateway_mgt:: SET SF"));
  60. // byte [4] contains desired SF code (7 for SF7 and 12 for SF12)
  61. break;
  62. case MGT_SET_FREQ:
  63. Serial.println(F("gateway_mgt:: SET FREQ"));
  64. // Byte [4] contains index of Frequency
  65. break;
  66. default:
  67. Serial.print(F("gateway_mgt:: Unknown UDP code="));
  68. Serial.println(opcode);
  69. return;
  70. break;
  71. }
  72. }
  73. #endif //_GATEWAYMGT==1