9 Commits
Author SHA1 Message Date
jlehmann a6d5d045f1 fix bug with big difference 2021-04-28 07:21:39 +02:00
jlehmann 74bca8966b calculate appkey 2021-04-26 16:49:27 +02:00
jlehmann 1772cf6f7e updated Cubecell-Arduino 2021-04-26 16:13:13 +02:00
jlehmann cefc4473e5 change to arduino-cli, document build flags 2021-04-23 20:37:46 +02:00
jlehmann c88c1a68be Umstellung auf arduino-cli 2021-04-23 11:12:43 +02:00
jlehmann 1651aab05b included upload command in README 2021-04-09 14:02:53 +02:00
jlehmann 2cff8e78c8 updated heltec library 2021-04-09 13:41:16 +02:00
jlehmann 15d75f10fc rejoin after every powercycle, updated cubecell lib 2021-02-22 18:13:20 +01:00
jlehmann 4adaf33835 save OTAA config in config_data (flash) 2021-02-06 18:14:50 +01:00
3 changed files with 125 additions and 16 deletions
@@ -12,19 +12,16 @@ BME280 bme280;
/******************************************************************************/
/* Firmware Version */
/******************************************************************************/
static const int32_t fwVersion = 20210205;
static const int32_t fwVersion = 20210427;
/******************************************************************************/
/* LoraWAN Settings */
/******************************************************************************/
/* OTAA para*/
//uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 };
//uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
//uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 };
uint8_t devEui[] = { 0x00, 0x00, 0xd3, 0xa6, 0x59, 0x83, 0x3b, 0x25 };
uint8_t appEui[] = { 0x70, 0xb3, 0xd5, 0x7e, 0xd0, 0x02, 0xe5, 0xab };
uint8_t appKey[] = { 0x00, 0x00, 0xd3, 0xa6, 0x59, 0x83, 0x3b, 0x25, 0x00, 0x00, 0xd3, 0xa6, 0x59, 0x83, 0x3b, 0x25 };
uint8_t devEui[8];
uint8_t appEui[8];
uint8_t appKey[16];
/* ABP para*/
uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda, 0x85 };
@@ -170,6 +167,9 @@ typedef struct {
float cal_a_factor; // 4 Bytes, Kalibrationsfaktor Waegezelle 1
float cal_b_factor; // 4 Bytes, Kalibrationsfaktor Waegezelle 2
byte debug_level; // 0 => no debugging, no led, 1 => infos, no led, 2 => infos, 3 => error, 4 => highest level
uint8_t devEui[8]; // keep OTAA settings so that new fw-updates does not overwrite it
uint8_t appEui[8]; // dito
uint8_t appKey[16]; // dito
} __attribute__((packed)) CONFIG_data;
typedef struct {
@@ -655,6 +655,19 @@ bool checkUserAt(char *cmd, char *content)
return true;
}
if (strcmp(cmd, "SAVE_OTAA_CONFIG") == 0)
{
if (content[0] == '1')
{
memcpy(config_data.devEui, devEui, sizeof(devEui));
memcpy(config_data.appEui, appEui, sizeof(appEui));
memcpy(config_data.appKey, appKey, sizeof(appKey));
WriteConfigDataToFlash();
Serial.printf("saved OTAA configuration to flash\n");
}
return true;
}
if (strcmp(cmd, "READ_SENSORS") == 0)
{
if (content[0] == '?')
@@ -763,6 +776,10 @@ void setup_platform(void)
// read config_data from flash...
ReadConfigDataFromFlash();
memcpy(devEui, config_data.devEui, sizeof(config_data.devEui));
memcpy(appEui, config_data.appEui, sizeof(config_data.appEui));
memcpy(appKey, config_data.appKey, sizeof(config_data.appKey));
if (config_data.debug_level > 0) {
Serial.printf("Setup_platform, this is the configuration\n");
Serial.printf("cal_a_0: %d\n", config_data.cal_a_0);
@@ -833,12 +850,14 @@ void AddSensorDataToLoraData()
timer_pos0 = millis();
}
my_position++;
last_sensor_reading = sensor_data;
}
bool TooBigWeightChange()
{
// on first position there cannot be a difference
if (my_position == 1) {
return false;
}
bool big_difference = (abs(last_sensor_reading.weight - sensor_data.weight) > SEND_DIFF_THRESHOLD_5GRAMS);
if (big_difference) {
lora_data.weight_last = sensor_data.weight;
@@ -890,7 +909,8 @@ bool ReadSensors(bool read_only)
if (!read_only) {
AddSensorDataToLoraData();
send_data = (TooBigWeightChange()) || (my_position >= MAX_VALUES_TO_SEND) || (iteration <= INIT_PACKETS) || (iteration % INIT_PACKAGE_INTERVAL == 0);
last_sensor_reading = sensor_data;
if (config_data.debug_level > 0) {
if (send_data) {
Serial.printf("Iteration: %d, we send the data...\n", iteration);
+47 -5
View File
@@ -20,10 +20,52 @@ Autor: Joerg Lehmann, nbit Informatik GmbH
Das sind die verwendeten Libraries [1]:
| URL | Commit | Commit Date |
| --- | ----- | ----------- |
| https://github.com/HelTecAutomation/ASR650x-Arduino.git | 9856523 | Thu, 4 Feb 2021 18:02:48 +0800 |
| https://github.com/sparkfun/SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.git | 688f255 | Fri, 3 Jan 2020 12:35:22 -0700 |
| https://github.com/sparkfun/SparkFun_BME280_Arduino_Library.git | 0b5eabf | Wed, 30 Dec 2020 20:44:27 -0700 |
| URL | Branch | Commit | Commit Date |
| --- | ------ | ----- | ----------- |
| https://github.com/HelTecAutomation/CubeCell-Arduino.git | 58ed094 | Mon, 26 Apr 2021 09:48:49 +0800 |
| https://github.com/sparkfun/SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.git | master | 688f255 | Fri, 3 Jan 2020 12:35:22 -0700 |
| https://github.com/sparkfun/SparkFun_BME280_Arduino_Library.git | master | 0b5eabf | Wed, 30 Dec 2020 20:44:27 -0700 |
`
[1]: echo "| $(git remote -v |grep fetch |awk '{print $2}' |tr '\n' ' ') | $(git log --pretty=format:'%h | %cD ' -n 1) |"
`
## Wir verwenden arduino-cli
Installation:
`
$ curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=~/bin sh
$ arduino-cli version
arduino-cli alpha Version: 0.18.1 Commit: b3cf8e19 Date: 2021-04-13T13:08:30Z
$ arduino-cli sketch new MiniBeieliNodeSketch
$ arduino-cli core update-index
$ arduino-cli board listall
$ arduino-cli core install CubeCell:CubeCell
$ arduino-cli core list
Compile:
$ arduino-cli compile --fqbn CubeCell:CubeCell:CubeCell-Board \
--build-property "build.band=REGION_EU868" \
--build-property "build.LORAWAN_CLASS=CLASS_A" \
--build-property "build.LORAWAN_CLASS=CLASS_A" \
--build-property "build.LORAWAN_DEVEUI_AUTO=0" \
--build-property "build.LORAWAN_NETMODE=true" \
--build-property "build.LORAWAN_ADR=true" \
--build-property "build.LORAWAN_UPLINKMODE=false" \
--build-property "build.LORAWAN_Net_Reserve=false" \
--build-property "build.LORAWAN_AT_SUPPORT=1" \
--build-property "build.RGB=0" \
--build-property "build.LORAWAN_DebugLevel=0" \
MiniBeieliNodeSketch
Output ist in /tmp/arduino-sketch-XXXXXXXXXXXXXXXXXXXXXXXXX und kann kopiert werden:
$ mkdir ~/arduino-builds-saved/20210423/
$ cp /tmp/arduino-sketch-0870BAA82DFEB3C4E076C8FBBDEB25B4/CubeCell_Board_REGION_EU868_RGB_0.cyacd ~/arduino-builds-saved/20210423/
Upload:
/home/joerg/Arduino/hardware/CubeCell/CubeCell/tools/CubeCellflash/CubeCellflash -serial /dev/ttyUSB0 /home/joerg/arduino-builds-saved/latest/CubeCell_Board_REGION_EU868_RGB_0.cyacd
`
+48 -1
View File
@@ -58,6 +58,51 @@ func readSerial(p *serial.Port) {
}
}
func getAppKey(deveui string) string {
if len(deveui) == 16 {
appkey := fmt.Sprintf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
deveui[10],
deveui[3],
deveui[4],
deveui[7],
deveui[15],
deveui[9],
deveui[11],
deveui[2],
deveui[0],
deveui[8],
deveui[1],
deveui[6],
deveui[5],
deveui[12],
deveui[14],
deveui[13],
deveui[3],
deveui[6],
deveui[12],
deveui[7],
deveui[15],
deveui[1],
deveui[9],
deveui[11],
deveui[2],
deveui[10],
deveui[0],
deveui[8],
deveui[5],
deveui[14],
deveui[4],
deveui[13])
fmt.Printf("calculated AppKey: %s\n", appkey)
return appkey
} else {
fmt.Printf("devEui has wrong length: %s\n", deveui)
return ""
}
}
func main() {
if len(os.Args) != 3 {
fmt.Println("usage: " + filepath.Base(os.Args[0]) + " <SerialDevice> <appEui>")
@@ -75,10 +120,12 @@ func main() {
sendCommand(s, "AT+XXX")
devEui := getDevEui(s)
appKey := getAppKey(devEui)
if devEui != "" {
sendCommand(s, "AT+DevEui="+devEui)
sendCommand(s, "AT+AppEui="+appEui)
sendCommand(s, "AT+AppKey="+devEui+devEui)
sendCommand(s, "AT+AppKey="+appKey)
sendCommand(s, "AT+SAVE_OTAA_CONFIG=1")
sendCommand(s, "AT+RESET=1")
readSerial(s)
} else {