changes
This commit is contained in:
		
							
								
								
									
										13
									
								
								libraries/includes/defines.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								libraries/includes/defines.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
#ifndef _DEFINES_H_
 | 
			
		||||
#define _DEFINES_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define ONE_WIRE 4
 | 
			
		||||
#define LED_RED 3
 | 
			
		||||
#define LED_GREEN 2
 | 
			
		||||
#define LED_BLUE 45
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif /* _DEFINES_H_ */
 | 
			
		||||
							
								
								
									
										30
									
								
								readme.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								readme.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
# LoRaWAN Thermometer
 | 
			
		||||
 | 
			
		||||
## Some pictures
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Notes on the development environment
 | 
			
		||||
* start dev environment using `startDevEnv.sh`
 | 
			
		||||
* inside the container go into the directory `~/project`
 | 
			
		||||
* set the env variable `ARDUINO_SKETCHBOOK_DIR` to `$PWD`
 | 
			
		||||
* build application in container in directory `~/project` using `arduino-cli compile --fqbn=Heltec-esp32:esp32:WIFI_LoRa_32_V3 --export-binaries /home/arduino/project/sketch/`
 | 
			
		||||
* flash device using `esptool.py --port /dev/tty.usbserial-0001 --baud 921600 --chip esp32s3 write_flash --flash_mode dio --flash_size 8MB 0x0 sketch.ino.bootloader.bin 0x8000 sketch.ino.partitions.bin 0x10000 sketch.ino.bin`
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
From Arduino IDE:
 | 
			
		||||
 | 
			
		||||
    /Users/wn/Library/Arduino15/packages/Heltec-esp32/tools/esptool_py/3.3.0/esptool 
 | 
			
		||||
    --chip esp32s3 
 | 
			
		||||
    --port /dev/cu.usbserial-0001 
 | 
			
		||||
    --baud 921600 
 | 
			
		||||
    --before default_reset 
 | 
			
		||||
    --after hard_reset 
 | 
			
		||||
    write_flash 
 | 
			
		||||
    -z 
 | 
			
		||||
    --flash_mode dio 
 | 
			
		||||
    --flash_freq 80m 
 | 
			
		||||
    --flash_size 8MB 
 | 
			
		||||
    0x0 /var/folders/vy/d60s0tzx3mn8bfy6ssd27hl00000gn/T/arduino_build_190148/LoRaWan.ino.bootloader.bin 
 | 
			
		||||
    0x8000 /var/folders/vy/d60s0tzx3mn8bfy6ssd27hl00000gn/T/arduino_build_190148/LoRaWan.ino.partitions.bin 
 | 
			
		||||
    0xe000 /Users/wn/Library/Arduino15/packages/Heltec-esp32/hardware/esp32/0.0.7/tools/partitions/boot_app0.bin
 | 
			
		||||
    0x10000 /var/folders/vy/d60s0tzx3mn8bfy6ssd27hl00000gn/T/arduino_build_190148/LoRaWan.ino.bin
 | 
			
		||||
							
								
								
									
										57
									
								
								sketch/configuration.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								sketch/configuration.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
			
		||||
#include "configuration.h"
 | 
			
		||||
#include "defines.h"
 | 
			
		||||
#include "LoRaWan_APP.h"
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <Wire.h>  
 | 
			
		||||
#include "HT_SSD1306Wire.h"
 | 
			
		||||
 | 
			
		||||
#include <WiFi.h>
 | 
			
		||||
#include <WiFiClient.h>
 | 
			
		||||
#include <WebServer.h>
 | 
			
		||||
#include <WiFiAP.h>
 | 
			
		||||
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <iomanip>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const uint32_t MAGIC = 0xaffe0001;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
config_t myConfig = { 
 | 
			
		||||
    .magic = MAGIC,
 | 
			
		||||
    .appEui = { 0xa0, 0x57, 0x81, 0x00, 0x01, 0x12, 0xaa, 0xf4 },
 | 
			
		||||
    .appKey = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
uint8_t devEui[8];
 | 
			
		||||
uint8_t appEui[8];
 | 
			
		||||
uint8_t appKey[16];
 | 
			
		||||
uint8_t nwkSKey[16];
 | 
			
		||||
uint8_t appSKey[16];
 | 
			
		||||
uint32_t devAddr;
 | 
			
		||||
LoRaMacRegion_t loraWanRegion;
 | 
			
		||||
bool overTheAirActivation;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void configurationSetup() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void configurationLoop() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void configLoad() {
 | 
			
		||||
    memcpy(appEui, myConfig.appEui, sizeof(appEui));
 | 
			
		||||
    memcpy(appKey, myConfig.appKey, sizeof(appKey));
 | 
			
		||||
    loraWanRegion = LORAMAC_REGION_EU868;
 | 
			
		||||
    overTheAirActivation = true;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										26
									
								
								sketch/configuration.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								sketch/configuration.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
#ifndef _CONFIGURATION_H_
 | 
			
		||||
#define _CONFIGURATION_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
typedef struct config_s {
 | 
			
		||||
    uint32_t magic;
 | 
			
		||||
    uint8_t appEui[8];
 | 
			
		||||
    uint8_t appKey[16];
 | 
			
		||||
} config_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void configurationSetup();
 | 
			
		||||
void configurationLoop();
 | 
			
		||||
 | 
			
		||||
void configLoad();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // _CONFIGURATION_H_
 | 
			
		||||
							
								
								
									
										118
									
								
								sketch/production.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								sketch/production.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,118 @@
 | 
			
		||||
#include "LoRaWan_APP.h"
 | 
			
		||||
#include "defines.h"
 | 
			
		||||
#include "configuration.h"
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// from config.cpp
 | 
			
		||||
extern config_t myConfig;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*LoraWan channelsmask, default channels 0-7*/ 
 | 
			
		||||
uint16_t userChannelsMask[6]={ 0x00FF,0x0000,0x0000,0x0000,0x0000,0x0000 };
 | 
			
		||||
 | 
			
		||||
/*LoraWan Class, Class A and Class C are supported*/
 | 
			
		||||
DeviceClass_t  loraWanClass = CLASS_A;
 | 
			
		||||
 | 
			
		||||
/*the application data transmission duty cycle.  value in [ms].*/
 | 
			
		||||
uint32_t appTxDutyCycle = 15000;
 | 
			
		||||
 | 
			
		||||
/*ADR enable*/
 | 
			
		||||
bool loraWanAdr = true;
 | 
			
		||||
 | 
			
		||||
/* Indicates if the node is sending confirmed or unconfirmed messages */
 | 
			
		||||
bool isTxConfirmed = true;
 | 
			
		||||
 | 
			
		||||
/* Application port */
 | 
			
		||||
uint8_t appPort = 2;
 | 
			
		||||
/*!
 | 
			
		||||
* Number of trials to transmit the frame, if the LoRaMAC layer did not
 | 
			
		||||
* receive an acknowledgment. The MAC performs a datarate adaptation,
 | 
			
		||||
* according to the LoRaWAN Specification V1.0.2, chapter 18.4, according
 | 
			
		||||
* to the following table:
 | 
			
		||||
*
 | 
			
		||||
* Transmission nb | Data Rate
 | 
			
		||||
* ----------------|-----------
 | 
			
		||||
* 1 (first)       | DR
 | 
			
		||||
* 2               | DR
 | 
			
		||||
* 3               | max(DR-1,0)
 | 
			
		||||
* 4               | max(DR-1,0)
 | 
			
		||||
* 5               | max(DR-2,0)
 | 
			
		||||
* 6               | max(DR-2,0)
 | 
			
		||||
* 7               | max(DR-3,0)
 | 
			
		||||
* 8               | max(DR-3,0)
 | 
			
		||||
*
 | 
			
		||||
* Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
 | 
			
		||||
* the datarate, in case the LoRaMAC layer did not receive an acknowledgment
 | 
			
		||||
*/
 | 
			
		||||
uint8_t confirmedNbTrials = 4;
 | 
			
		||||
 | 
			
		||||
/* Prepares the payload of the frame */
 | 
			
		||||
static void prepareTxFrame( uint8_t port )
 | 
			
		||||
{
 | 
			
		||||
  appDataSize = 4;
 | 
			
		||||
  appData[0] = 0x01;
 | 
			
		||||
  appData[1] = 0x02;
 | 
			
		||||
  appData[2] = 0x03;
 | 
			
		||||
  appData[3] = 0x04;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
RTC_DATA_ATTR bool firstrun = true;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void productionSetup() {
 | 
			
		||||
  Serial.println("Starting");
 | 
			
		||||
  Mcu.begin();
 | 
			
		||||
 | 
			
		||||
  deviceState = DEVICE_STATE_INIT;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void productionLoop()
 | 
			
		||||
{
 | 
			
		||||
  digitalWrite(LED_GREEN, HIGH);
 | 
			
		||||
 | 
			
		||||
  switch( deviceState )
 | 
			
		||||
  {
 | 
			
		||||
    case DEVICE_STATE_INIT:
 | 
			
		||||
    digitalWrite(LED_GREEN, LOW);
 | 
			
		||||
    {
 | 
			
		||||
      LoRaWAN.generateDeveuiByChipID();
 | 
			
		||||
      LoRaWAN.init(loraWanClass,loraWanRegion);
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    case DEVICE_STATE_JOIN:
 | 
			
		||||
    {
 | 
			
		||||
      Serial.println("Joining");
 | 
			
		||||
      LoRaWAN.join();
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    case DEVICE_STATE_SEND:
 | 
			
		||||
    digitalWrite(LED_BLUE, HIGH);
 | 
			
		||||
    {
 | 
			
		||||
      Serial.println("sending");
 | 
			
		||||
      prepareTxFrame( appPort );
 | 
			
		||||
      LoRaWAN.send();
 | 
			
		||||
      deviceState = DEVICE_STATE_CYCLE;
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    case DEVICE_STATE_CYCLE:
 | 
			
		||||
    digitalWrite(LED_BLUE, LOW);
 | 
			
		||||
    {
 | 
			
		||||
      // Schedule next packet transmission
 | 
			
		||||
      txDutyCycleTime = appTxDutyCycle + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
 | 
			
		||||
      LoRaWAN.cycle(txDutyCycleTime);
 | 
			
		||||
      deviceState = DEVICE_STATE_SLEEP;
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    case DEVICE_STATE_SLEEP:
 | 
			
		||||
    {
 | 
			
		||||
      LoRaWAN.sleep(loraWanClass);
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    default:
 | 
			
		||||
    {
 | 
			
		||||
      deviceState = DEVICE_STATE_INIT;
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								sketch/production.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								sketch/production.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
#ifndef _PRODUCTION_H_
 | 
			
		||||
#define _PRODUCTION_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void productionSetup();
 | 
			
		||||
void productionLoop();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // _PRODUCTION_H_
 | 
			
		||||
							
								
								
									
										32
									
								
								sketch/sketch.ino
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								sketch/sketch.ino
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
 | 
			
		||||
#include "defines.h"
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include "production.h"
 | 
			
		||||
#include "configuration.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// from config.cpp
 | 
			
		||||
extern config_t myConfig;
 | 
			
		||||
 | 
			
		||||
bool productionMode = false;
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  pinMode(LED_BLUE, OUTPUT);
 | 
			
		||||
  digitalWrite(LED_BLUE, LOW);
 | 
			
		||||
  pinMode(LED_RED, OUTPUT);
 | 
			
		||||
  digitalWrite(LED_RED, LOW);
 | 
			
		||||
  pinMode(LED_GREEN, OUTPUT);
 | 
			
		||||
  digitalWrite(LED_GREEN, LOW);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  Serial.begin(115200);
 | 
			
		||||
 | 
			
		||||
  configLoad();
 | 
			
		||||
 | 
			
		||||
  productionSetup();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
  productionLoop();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								startDevEnv.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										9
									
								
								startDevEnv.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
#!/usr/local/bin/bash
 | 
			
		||||
 | 
			
		||||
docker run \
 | 
			
		||||
  -it \
 | 
			
		||||
  --rm \
 | 
			
		||||
  -v $PWD:/home/arduino/project \
 | 
			
		||||
  registry.hottis.de/dockerized/build-env-arduino:0.29.0-10 \
 | 
			
		||||
  bash
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user