_gatewayMgt.ino 2.6 KB

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