### Install MQTT dependencies Source: https://docs.heltec.org/general/subscribe_mqtt_messages.html Command to install the necessary Python libraries for MQTT communication. ```bash sudo pip3 install paho-mqtt python-etcd ``` -------------------------------- ### Example License Activation Command Source: https://docs.heltec.org/general/how_to_use_license.html This shows how to format a license for the activation command if it includes '0x' prefixes in its original form. The command uses only the hexadecimal digits. ```text AT+CDKEY=12345678123456781234567812345678 ``` -------------------------------- ### Example ChannelsMask Configuration Source: https://docs.heltec.org/general/connect_to_single_channel_gateway.html This example demonstrates a ChannelsMask configuration that enables channels 21 through 32. ```c++ uint16_t userChannelsMask[6]={ 0x0000,0xFFF0,0x0000,0x0000,0x0000,0x0000 }; ``` -------------------------------- ### Example MQTT JSON Payload Source: https://docs.heltec.org/general/subscribe_mqtt_messages_from_snapemu.html The structure of the JSON payload received when subscribing to device or group topics. ```json { "bytes": "BAAKAmMQo0EStVIJQgAAAgU8", "device": "d326a3d6-12bf-48cf-817e-cbd2b11278c9", "battery": 66, "eui": "FFFFFFFFFFFFFFFF", "charge": false, "data": [ { "data": 34.44215774536133, "data_id": 65, "v_type": "F32", "v_unit": "°C", "v_name": "Temperature" } ] } ``` -------------------------------- ### Configure LoRaWAN AU915 Sub-Band Source: https://docs.heltec.org/general/sub_band_usage.html Modify the `channelsMaskTemp` array to select different sub-bands for LoRaWAN communication in the AU915 frequency plan. For example, setting `channelsMaskTemp[0] = 0xFF00;` selects channels 8-15. ```c uint16_t userChannelsMask[6]; // Example: Use channels 0-7 (915.2MHz to 916.6MHz) userChannelsMask[0] = 0x00FF; // Example: Use channels 8-15 (916.8MHz to 918.2MHz) userChannelsMask[0] = 0xFF00; // Example: Use channels 65 (a specific channel) // Note: This is a simplified representation, actual mask usage might differ. // For TTN AU915, channels 8-15 and 65 are typically used. // The provided text mentions changing channelsMaskTemp[0]=0xFF00; to switch to channels 8-15. ``` -------------------------------- ### Write License via AT Command on Arduino Source: https://docs.heltec.org/general/how_to_use_license.html Use this AT command in the Arduino serial port to write your license. Ensure the license contains only numbers, without spaces or '0x' prefixes. ```arduino AT+CDKEY=License ``` -------------------------------- ### Activate Gateway via AT Command Source: https://docs.heltec.org/general/how_to_use_license.html If the LoRa code does not reserve a license interface, send this AT command through the serial port after the chip ID is printed to activate the gateway. Replace 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' with your 32-bit license. ```text AT+CDKEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ``` -------------------------------- ### Configure Wi-Fi Connection on Raspberry Pi Source: https://docs.heltec.org/general/how_to_config_raspberry_pi.html Edit the wpa_supplicant.conf file to add your Wi-Fi network SSID and password. This allows the Raspberry Pi to automatically connect to your network upon startup. ```bash sudo nano /etc/wpa_supplicant/wpa_supplicant.conf ``` ```text network={ ssid="Your WiFi name" psk="Your WIFI password" } ``` -------------------------------- ### Configure CN470 User Channels Mask (Channels 0-7) Source: https://docs.heltec.org/general/lorawan_parameters.html Sets the user channels mask for the CN470 region to enable channels 0 through 7. Ensure this matches the gateway's configured channels. ```c uint16_t userChannelsMask[6]={ 0x00FF,0x0000,0x0000,0x0000,0x0000,0x0000 }; ``` -------------------------------- ### Run Python MQTT receiver Source: https://docs.heltec.org/general/subscribe_mqtt_messages.html Command to execute the Python script for receiving MQTT messages. ```bash python3 mqtt-receiver.py ``` -------------------------------- ### Identify Serial Port on MacOS Source: https://docs.heltec.org/general/establish_serial_connection.html Run this command before and after plugging in the board to identify the new serial device path. ```bash ls /dev/cu.* ``` -------------------------------- ### Enable SSH on Raspberry Pi Source: https://docs.heltec.org/general/how_to_config_raspberry_pi.html Use the raspi-config tool to enable SSH access, allowing you to log in to your Raspberry Pi remotely over the network. ```bash sudo raspi-config ``` ```bash Interfacing Options --> SSH --> YES ``` -------------------------------- ### Enable UART Logging in Raspberry Pi Source: https://docs.heltec.org/general/how_to_config_raspberry_pi.html Add this line to the config.txt file to enable serial port logging for debugging purposes. ```text enable_uart=1 ``` -------------------------------- ### Configure ChannelsMask for Single Channel Gateway Source: https://docs.heltec.org/general/connect_to_single_channel_gateway.html Set the userChannelsMask to enable channel 3 when the single-channel gateway is configured for 470.7 MHz. ```c++ uint16_t userChannelsMask[6]={ 0x0004,0x0000,0x0000,0x0000,0x0000,0x0000 }; ``` -------------------------------- ### Query CubeCell Chip ID via AT Command Source: https://docs.heltec.org/general/view_limited_technical_data.html Use the AT command to retrieve the unique Chip ID for CubeCell series devices. ```text AT+ChipID=? ``` -------------------------------- ### Configure ChannelsMask for HT-M00 Dual-Channel Gateway Source: https://docs.heltec.org/general/connect_to_single_channel_gateway.html Set the userChannelsMask to enable channels 10 and 11 when the HT-M00 gateway is configured for frequencies 472.1 MHz and 472.3 MHz. ```c++ uint16_t userChannelsMask[6]={ 0x0600,0x0000,0x0000,0x0000,0x0000,0x0000 }; ``` -------------------------------- ### Configure CN470 User Channels Mask (Channels 16-23) Source: https://docs.heltec.org/general/lorawan_parameters.html Sets the user channels mask for the CN470 region to enable channels 16 through 23. This configuration is specific to the CN470 frequency plan. ```c uint16_t userChannelsMask[6]={ 0x0000,0x0000,0x00FF,0x0000,0x0000,0x0000 }; ``` -------------------------------- ### Configure ABP Mode in LoRaWAN Source: https://docs.heltec.org/general/lorawan_abp/config_parameter.html Set the LoRaWAN mode to ABP by assigning a boolean false value to the configuration parameter. ```cpp false ``` -------------------------------- ### Configure CN470 User Channels Mask (Channels 88-95) Source: https://docs.heltec.org/general/lorawan_parameters.html Sets the user channels mask for the CN470 region to enable channels 88 through 95. This configuration is specific to the CN470 frequency plan. ```c uint16_t userChannelsMask[6]={ 0x0000,0x0000,0x0000,0x0000,0x0000,0xFF00 }; ``` -------------------------------- ### Handle Downlink Data in LoRaWAN Source: https://docs.heltec.org/general/downlinkdata_example_on_snapemu.html This C++ code snippet handles received downlink data for LoRaWAN. It parses commands from the received buffer and executes corresponding actions, such as controlling an LED. Ensure the LoRaWAN library is correctly set up. ```cpp uint8_t command = 0; // To store received command void downLinkDataHandle(McpsIndication_t *mcpsIndication) { if (mcpsIndication->BufferSize > 0) { // Print the received downlink data Serial.print("+Received Buffer: "); for (uint8_t i = 0; i < mcpsIndication->BufferSize; i++) { Serial.printf("0x%02X ", mcpsIndication->Buffer[i]); } Serial.println(); // Extract the first byte as a command uint8_t command = mcpsIndication->Buffer[0]; Serial.print("Received command: 0x"); Serial.println(command, HEX); // Process according to commands switch (command) { case 0x01: Serial.println("Command 0x01: Turning off LED..."); pinMode(18, OUTPUT); digitalWrite(18, LOW); // Execute action break; case 0x02: Serial.println("Command 0x02: Turning on LED..."); pinMode(18, OUTPUT); digitalWrite(18, HIGH); // Execute action break; default: Serial.println("Unknown command received."); break; } } else { Serial.println("No data received."); } } ``` -------------------------------- ### Calculate Data ID Source: https://docs.heltec.org/general/subscribe_mqtt_messages_from_snapemu.html Formula for calculating the data_id using sensor_id and pk_id. ```text data_id = (sensor_id << 4) | pk_id ; ``` -------------------------------- ### Convert 32-bit Data Types Source: https://docs.heltec.org/general/data_format_document.html Use this union structure to convert 32-bit types like float, int32_t, or uint32_t into a byte array for transmission. The low byte is stored first in the resulting array. ```c typedef union { union bits_32_raw_data { uint32_t uint32_t_raw_data; int32_t int32_t_raw_data; float float_raw_data; }; uint8_t bits_32_convert_data[4]; }bits_32_type_convert_t; data[0] = bits_32_convert_data[0]; data[1] = bits_32_convert_data[1]; data[2] = bits_32_convert_data[2]; data[3] = bits_32_convert_data[3]; ``` -------------------------------- ### Define custom sensor decoding function Source: https://docs.heltec.org/general/define_sensor_decoding_function_on_snapemu.html Implement the decodeUplink function to parse raw byte arrays into specific data fields. Ensure the returned ID matches the ID configured in the application interface. ```javascript export function decodeUplink(data) { let counter = (data.bytes[4] << 24) | (data.bytes[5] << 16) | (data.bytes[6] << 8) | data.bytes[7]; // decode counter return { data: [ { data: counter, id: 0 } // Return the count value and identifier ] }; } ``` -------------------------------- ### Prescribed Format MQTT JSON Payload Source: https://docs.heltec.org/general/subscribe_mqtt_messages_from_snapemu.html The structure of the JSON payload for data in a prescribed format. ```json { "bytes": "xcQJQg==", "data": 34.44215774536133, "data_id": 65, "device": "d326a3d6-12bf-48cf-817e-cbd2b11278c9", "pk_id": 1, "s_id": 4, "v_type": "F32" } ``` -------------------------------- ### MQTT Message Payload Structure Source: https://docs.heltec.org/general/publish_mqtt_message.html This is the structure for the data payload when publishing an MQTT message. Ensure 'fPort' is greater than 0 and 'data' is Base64 encoded. ```json { "fPort": 10, //Port used(fPort > 0) "data": "EjQ=" //Published data } ``` -------------------------------- ### Decode Payload Data in TTN Source: https://docs.heltec.org/general/decode_payload.html JavaScript decoder function for The Things Network that converts a 4-byte LSB array into a floating-point number. ```javascript function Decoder(bytes, port) { function bytesToFloat(bytes) { //LSB Format (least significant byte first). var bits = bytes[3]<<24 | bytes[2]<<16 | bytes[1]<<8 | bytes[0]; var sign = (bits>>>31 === 0) ? 1.0 : -1.0; var e = bits>>>23 & 0xff; var m = (e === 0) ? (bits & 0x7fffff)<<1 : (bits & 0x7fffff) | 0x800000; var f = sign * m * Math.pow(2, e - 150); return f; } return { temp: bytesToFloat(bytes.slice(0, 4)) }; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.