things4u / ESP-1ch-Gateway

Version 6 of the single channel gateway
MIT License
364 stars 147 forks source link

ESP32 wemos with hand soldered lora module #27

Closed danielkoek closed 4 years ago

danielkoek commented 4 years ago

Hey, First of all, awesome work you did here! I am not sure what is going on cause i can't seem to really debug it well. Soldered a little gateway together by hand using the wiring of the sparkfuns lora 1ch gateway schemetics, only leaving out the RST pin since there is no need for it. Checked the wiring 3 times but can't seem to get it working, maybe i am missing something but i keep getting a abort, here is the output from the Serial:

entry 0x400806ac SPIFFS begin Format SPIFFS Filesystem Done Do Asserts readConfig ERR:: file=/gwayConfig.txt does not exist .. readConfig:: Error reading config file setup:: readGwayCfg: ERROR readCfgCfg Failed MAC: 30:ae:a4:37:e6:1c, len=17 0:0:1. WlanConnect SSID=Boogmakerstraat 45 WlanStatus:: NO SSID ..1:0:1. WlanConnect SSID=Boogmakerstraat 45 WlanStatus:: CONNECTED ssid=Boogmakerstraat 45 Host=esp32-37e61c WiFi Connected to Boogmakerstraat 45 on IP=192.168.1.108 Local UDP port=1700 UDP Connection successful Gateway ID: 30aea4ffff37e61c, Listening at SF9 on 868.10 MHz. resolveHost:: OK=nl.pool.ntp.org IP=94.228.143.152 Time set=Sunday 8-3-2020 17:39:53 resolveHost:: OK=router.eu.thethings.network IP=52.169.76.203 setupOta:: Started Ready IP address: 192.168.1.108 WARNING:: readSeen, history file not exists /gwayNum.txt WWW Server started on port 80 Unknown transceiver=0, pins.rst =14, pins.ss =18, pins.dio0 =26, pins.dio1 =33, pins.dio2 =32

abort() was called at PC 0x400dea6c on core 1

Backtrace: 0x4008c468:0x3ffb1e40 0x4008c699:0x3ffb1e60 0x400dea6c:0x3ffb1e80 0x400dec15:0x3ffb1eb0 0x400e2dfd:0x3ffb1ee0 0x400ecd97:0x3ffb1fb0 0x40088bb1:0x3ffb1fd0

Rebooting... ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:8896 load:0x40080400,len:5816 entry 0x400806ac SPIFFS begin Format SPIFFS Filesystem Done Do Asserts readConfig ERR:: file=/gwayConfig.txt does not exist ..

If you need any more info please let me know, would really like this to work!

Kind regards, Daniël

platenspeler commented 4 years ago

Can you post a picture of the pin-out? Based on the output your board is not recognized by the software. You use _PIN_OUT==4 which is standard for ESP32 boards. Is it also standard for your board?

Unknown transceiver=0, pins.rst =14, pins.ss =18, pins.dio0 =26, pins.dio1 =33, pins.dio2 =32

The Sparfun seems to be the same.

Maarten

danielkoek commented 4 years ago

It would be easier to write them all down:

DIO2:32 Dio1:33 Dio0:26 Vdd:3v Dio4:NC Dio3:NC Gnd:NC Ant: connected to the wire

Then the second row

Gnd:NC Miso:miso/19 Mosi:mosi/23 Sck:18 Nss:16 RST:NC Dio5:NC Gnd:gnd

Maybe I am missing something but that is the pinout as well as specified right or do I have to connect rst or maybe I messed up nss and sck that nss should the ss pin so change the software to 16 instead of 18? Will check that out the next day, don't have my laptop at hand atm

danielkoek commented 4 years ago

Changed the FW now too, but it didn't change anything expect the pinout is now Unknown transceiver=0, pins.rst =27, pins.ss =16, pins.dio0 =26, pins.dio1 =33, pins.dio2 =32

platenspeler commented 4 years ago

I see now that the software thinks that rst is 27. Did you change the software to be in line with your hardware? Make sure that you change the software in loraModem.h (and pin definition in configGway.h) so that these are the same as the hardware.

Maarten

danielkoek commented 4 years ago

Yea that is right, but i didn't connect rst to anything now, so it is not a pin used, other then that i just set everything to esp32 as far as i know, turned off the oled and all that kind of stuff, so i am really scratching my head what is going on, any suggestion on how i could see why it is failing?

Daniël

platenspeler commented 4 years ago

I will have last look. but since all of my Gateway work, I am not sure what is the problem with yours.

platenspeler commented 4 years ago

Perhaps send me a version of your configNode.h and configGway.h file together with a picture of your pin-out of the node.

Maarten

danielkoek commented 4 years ago

Yea ofc no bother at all, here you go: IMG_20200331_140923 IMG_20200331_140946

danielkoek commented 4 years ago
// 1-channel LoRa Gateway for ESP32 and ESP8266
// Copyright (c) Maarten Westenberg 2016-2020

#define VERSION "V.6.2.3.E.EU868; PlatformIO 200223a"
//
// Based on work done by Thomas Telkamp for Raspberry PI 1ch gateway and many others.
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the MIT License
// which accompanies this distribution, and is available at
// https://opensource.org/licenses/mit-license.php
//
// NO WARRANTY OF ANY KIND IS PROVIDED
//
// Author: Maarten Westenberg (mw12554@hotmail.com)
//
// This file contains a number of compile-time settings that can be set on (=1) or off (=0)
// The disadvantage of compile time is minor compared to the memory gain of not having
// too much code compiled and loaded on your ESP device.
//
// NOTE:
// If version is for ESP32 Heltec board, compile with ESP32 setting and board
// "ESP32 Dev Module" or "Heltec WiFi Lora 32"
//
// For ESP8266 Wemos: compile with "Wemos R1 D1" and choose
// the right _PIN_OUT below. Selecting OLED while that is not connected does not
// really matter (so you can leave that in).
//
// The source has been optimized for PlatformIO usage. Than means the some variables
// can be define in the .platformio.ini file. Pleas look at the example file to see
// how to set these #defines
//
// ========================================================================================

// Define whether we should do a formatting of SPIFFS when starting the gateway
// This is usually a good idea if the webserver is interrupted halfway a writing
// operation. Also to be used when software is upgraded
// Normally, value 0 is a good default and should not be changed.
#if !defined _SPIFFS_FORMAT
#define _SPIFFS_FORMAT 1
#endif

// Allows configuration through WifiManager AP setup. Must be 0 or 1
#if !defined _WIFIMANAGER
#define _WIFIMANAGER 0
#endif

// Debug message will be put on Serial is this one is set.
// If set to 0, no printing to USB devices is done.
// Set to 1 it will print all user level messages (with correct debug set)
// If set to 2 it will also print interrupt messages (not recommended)
#if !defined _DUSB
#define _DUSB 2
#endif

// Define the monitor screen. When it is greater than 0 then logging is displayed in
// the special screen at the GUI.
// If _DUSB is also set to 1 then most messages will also be copied to USB devices.
#define _MONITOR 1

// Gather statistics on sensor and Wifi status
// 0= No statistics
// 1= Keep track of messages statistics, number determined by _MAXSTAT
// 2= Option 1 + Keep track of messages received PER each SF (default)
// 3= See Option 2, but with extra channel info (Not used when Hopping is not selected)
#define _STATISTICS 3

// Define the frequency band the gateway will listen on. Valid options are
// EU863_870    Europe
// US902_928    North America
// AU925_928    Australia
// CN470_510    China
// IN865_867    India
// CN779-787    (Not Used!)
// EU433        Europe
// AS923        (Not Used)
// You can find the definitions in "loraModem.h" and frequencies in
// See https://www.thethingsnetwork.org/docs/lorawan/frequency-plans.html
#define EU863_870 1

// Define the CLASS mode of the gateway
// A: Baseline Class
// B: Beacon/Battery Class
// C: Continuous Listen Class
#define _CLASS "A"

// Define whether to use the old Semtech gateway API, which is still supported by TTN,
// but is more lightweight than the new TTN tcp based protocol.
// NOTE: Only one of the two should be defined! TTN Router project has stopped
//
#define _UDPROUTER 1
//#define _TTNROUTER 1

// The spreading factor is the most important parameter to set for a single channel
// gateway. It specifies the speed/datarate in which the gateway and node communicate.
// As the name says, in principle the single channel gateway listens to one channel/frequency
// and to one spreading factor only.
// This parameters contains the default value of SF, the actual version can be set with
// the webserver and it will be stored in SPIFF
// NOTE: The frequency is set in the loraModem.h file and is default 868.100000 MHz.
#define _SPREADING SF9

// Channel Activity Detection
// This function will scan for valid LoRa headers and determine the Spreading
// factor accordingly. If set to 1 we will use this function which means the
// 1-channel gateway will become even more versatile. If set to 0 we will use the
// continuous listen mode.
// Using this function means that we HAVE to use more dio pins on the RFM95/sx1276
// device and also connect enable dio1 to detect this state.
#define _CAD 1

// CRCCHECK
// Defines whether we should check on the CRC of RXDONE messages (see stateMachine.ino)
// This should prevent us from getting a lot os stranges messgages of unknown nodes.
// Note: DIO3 must be connected for this to work (Heltec and later Wemos gateways).
#define _CRCCHECK 1

// Definitions for the admin webserver.
// A_SERVER determines whether or not the admin webpage is included in the sketch.
// Normally, leave it in!
#define A_SERVER 1       // Define local WebServer only if this define is set
#define A_REFRESH 1      // Allow the webserver refresh or not?
#define A_SERVERPORT 80  // Local webserver port (normally 80)
#define A_MAXBUFSIZE 192 // Must be larger than 128, but small enough to work

// Definitions for over the air updates. At the moment we support OTA with IDE
// Make sure that tou have installed Python version 2.7 and have Bonjour in your network.
// Bonjour is included in iTunes (which is free) and OTA is recommended to install
// the firmware on your router witout having to be really close to the gateway and
// connect with USB.
#define A_OTA 1

// We support a few pin-out configurations out-of-the-box: HALLARD, COMPRESULT and TTGO ESP32.
// If you use one of these two, just set the parameter to the right value.
// If your pin definitions are different, update the loraModem.h file to reflect these settings.
//  1: HALLARD
//  2: COMRESULT pin out
//  3: ESP32, Wemos pin out (Not used)
//  4: ESP32, Heltec and TTGO pin out (should work for Heltec, 433 and OLED too).
//  5: Other, define your own in loraModem.h (does not include GPS Code)
#if !defined _PIN_OUT
#define _PIN_OUT 5
#endif

// Single channel gateways if they behave strict should only use one frequency
// channel and one, or in case _CAD all, spreading factors.
// The TTN backend replies on RX1 timeslot for spreading factors SF9-SF12.
// If the 1ch gateway is working in and for nodes that ONLY transmit and receive on the set
// and agreed frequency and spreading factor. make sure to set STRICT to 1.
// In this case, the frequency and spreading factor for downlink messages is adapted by this
// gateway
// NOTE: If your node has only one frequency enabled and one SF, you must set this to 1
//      in order to receive downlink messages. This is the default mode.
// NOTE: In all other cases, value 0 works for most gateways with CAD enabled
#define _STRICT_1CH 1

//
// Also, normally the server will respond with SF12 in the RX2 timeslot.
// For TTN, thr RX2 timeslot is SF9, and we should use that one for TTN
#define _RX2_SF 9

// This section defines whether we use the gateway as a repeater
// For his, we use another output channel as the channel (default==0) we are
// receiving the messages on.
#define _REPEATER 0

// Will we use Mutex or not?
// +SPI is input for SPI, SPO is output for SPI
#define _MUTEX 0

// Define if OLED Display is connected to I2C bus. Note that defining an OLED display does not
// impact performance negatively, certainly if no OLED is connected. Wrong OLED will not show
// sensible results on the OLED display
// OLED==0; No OLED display connected
// OLED==1; 0.9" Oled Screen based on SSD1306
// OLED==2; 1.3" Oled screens for Wemos, 128x64 SH1106
#if !defined OLED
#define OLED 0
#endif

// Define whether we want to manage the gateway over UDP (next to management
// thru webinterface).
// This will allow us to send messages over the UDP connection to manage the gateway
// and its parameters. Sometimes the gateway is not accesible from remote,
// in this case we would allow it to use the SERVER UDP connection to receive
// messages as well.
// NOTE: Be aware that these messages are NOT LoRa and NOT LoRa Gateway spec compliant.
//  However that should not interfere with regular gateway operation but instead offer
//  functions to set/reset certain parameters from remote.
#define _GATEWAYMGT 0

// Do extensive logging
// Use the ESP8266 SPIFS filesystem to do extensive logging.
// We must take care that the filesystem never(!) is full, and for that purpose we
// rather have new records/line of statistics than very old.
// Of course we must store enough records to make the filesystem work
#define _STAT_LOG 1

// Set the Server Settings (IMPORTANT)
#define _LOCUDPPORT 1700 // UDP port of gateway! Often 1700 or 1701 is used for upstream comms

// Timing
#define _MSG_INTERVAL 15   // Reset timer in seconds
#define _PULL_INTERVAL 55  // PULL_DATA messages to server to get downstream in milliseconds
#define _STAT_INTERVAL 120 // Send a 'stat' message to server
#define _NTP_INTERVAL 3600 // How often do we want time NTP synchronization
#define _WWW_INTERVAL 60   // Number of seconds before we refresh the WWW page

// This defines whether or not we would use the gateway as
// as sort of backend decoding system for local sensors which decodes
// 1: _LOCALSERVER is used
// 0: Do not use _LOCALSERVER
#define _LOCALSERVER 1 // See server definitions for decodes

// Gateway Ident definitions. Where is the gateway located?
#define _DESCRIPTION "just another gateway" // Name of the gateway
#define _EMAIL "contact@danielkoek.net"     // Owner
#define _PLATFORM "ESP32"
#define _LAT 52.53293386
#define _LON 6.06787673
#define _ALT 14 // Altitude

// ntp
// Please add daylight saving time to NTP_TIMEZONES when desired
#define NTP_TIMESERVER "nl.pool.ntp.org" // Country and region specific
#define NTP_TIMEZONES 1                  // How far is our Timezone from UTC (excl daylight saving/summer time)
#define SECS_IN_HOUR 3600
#define NTP_INTR 0 // Do NTP processing with interrupts or in loop();

// lora sensor code definitions
// Defines whether the gateway will also report sensor/status value on MQTT
// (such as battery and GPS)
// after all, a gateway can be a node to the system as well. Some sensors like GPS can be
// sent to the backend as a parameter, some (like humidity for example) can only be sent
// as a regular sensor value.
// Set its LoRa address and key below in this file, See spec. para 4.3.2
// NOTE: The node is switched off by default. Switch it on in the GUI
#define _GATEWAYNODE 0

// We can put the gateway in such a mode that it will (only) recognize
// nodes that are put in a list of trusted nodes
// Values:
// 0: Do not use names for trusted Nodes
// 1: Use the nodes as a translation table for hex codes to names (in TLN)
// 2: Same as 1, but is nodes NOT in the nodes list below they are NOT shown
// NOTE: We probably will make this list dynamic!
#define _TRUSTED_NODES 1
#define _TRUSTED_DECODE 1

// ========================================================================
// DO NOT CHANGE BELOW THIS LINE
// Probably do not change items below this line, only if lists or
// configurations on configNode.h are not large enough for example.
// ========================================================================

// Maximum number of Message History statistics records gathered. 20 is a good maximum
// (memory intensive). For ESP32 maybe 30 could be used as well
#define _MAXSTAT 20

// Define the maximum amount of itemas we monitor on the screen
#define _MAXMONITOR 20

// We will log a list of LoRa nodes that was forwarded using this gateway.
// For eacht node we record:
//  - node Number, or known node name
//  - Last seen 'seconds since 1/1/1970'
//  - SF seen (8-bit integer with SF per bit)
// The initial version _NUMMAX stores max this many nodes, please make
// _MAXSEEN==0 when not used
#define _MAXSEEN 20
#define _SEENFILE "/gwayNum.txt"

// Name of he configfile in SPIFFs  filesystem
// In this file we store the configuration and other relevant info that should
// survive a reboot of the gateway
#define CONFIGFILE "/gwayConfig.txt"

// Define the correct radio type that you are using
#define CFG_sx1276_radio
//#define CFG_sx1272_radio

// Serial Port speed
#define _BAUDRATE 115200 // Works for debug messages to serial momitor

// MQTT definitions, these settings should be standard for TTN
// and need no changing
#define _TTNSERVER "router.eu.thethings.network"
#define _TTNPORT 1700 // Standard port for TTN
danielkoek commented 4 years ago
// sensor.h; 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016-2020 Maarten Westenberg version for ESP8266
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many other contributors.
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the MIT License
// which accompanies this distribution, and is available at
// https://opensource.org/licenses/mit-license.php
//
// NO WARRANTY OF ANY KIND IS PROVIDED
//
// Author: Maarten Westenberg (mw12554@hotmail.com)

//
// This file contains a number of compile-time settings and declarations that are'
// specific to the LoRa rfm95, sx1276, sx1272 radio of the gateway.
//
//
// ------------------------------------------------------------------------------------

// It is possible to use the gateway as a normal sensor node also. In this case,
// substitute the node info below.
#if _GATEWAYNODE == 1

// Valid coding for internal sensors are LCODE and RAW.
// Make sure to only select one.
//#define _LCODE 1
#define _RAW 1
#define _CHECK_MIC 1
#define _SENSOR_INTERVAL 300

#define _DEVADDR               \
    {                          \
        0xAA, 0xAA, 0xAA, 0xAA \
    }
#define _APPSKEY                                                                                       \
    {                                                                                                  \
        0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB \
    }
#define _NWKSKEY                                                                                       \
    {                                                                                                  \
        0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC \
    }
#define _SENSOR_INTERVAL 300
// For ESP32 based T_BEAM/TTGO boards these two are normally included
// If included make value 1, else if not, make them 0
#define _GPS 1
#define _BATTERY 1

#endif //_GATEWAYNODE

#if _TRUSTED_NODES >= 1
struct nodex
{
    uint32_t id; // This is the LoRa ID (coded in 4 bytes uint32_t
    char nm[32]; // Name of the node
};

// Add all your named and trusted nodes to this list
nodex nodes[] = {
    {0x260116BD, "lora-34 PIR node"},         // F=0
    {0x26011152, "lora-35 temp+humi node"},   // F=0
    {0x2601148C, "lora-36 test node"},        // F=0
    {0x00000000, "lora-00 well known sensor"} // F=0
};

#endif //_TRUSTED_NODES

// In some cases we like to decode the lora message at the single channel gateway.
// In thisase, we need the NkwSKey and the AppsSKey of the node so that we can decode
// its messages.
// Although this is probably overkill in normal gateway situations, it greatly helps
// in debugging the node messages before they reach the TTN severs.
//
#if _LOCALSERVER == 1
struct codex
{
    uint32_t id;          // This is the device ID (coded in 4 bytes uint32_t
    unsigned char nm[32]; // A name string which is free to choose
    uint8_t nwkKey[16];   // The Network Session Key of 16 bytes
    uint8_t appKey[16];   // The Application Session Key of 16 bytes
};

// Sometimes we want to decode the sensor completely as we do in the TTN server
// This means that for all nodes we want to view the data of, we need to provide
// the AppsSKey and the NwkSKey

// Definition of all nodes that we want to decode locally on the gateway.
//
codex decodes[] = {
    {0xAAAAAAAA, "lora-EE", // F=0
     {0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB},
     {0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC}},
    {0xBBBBBBBB, "lora-FF", // F=0
     {0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB},
     {0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC}},
    {0x00000000, "lora-00", // F=0
     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}};
#endif //_LOCALSERVER

// If you have a second back-end server defined such as Semtech or loriot.io
// your can define _THINGPORT and _THINGSERVER with your own value.
// If not, make sure that you do not define these, which will save CPU time
// Port is UDP port in this program
//
// Default for testing: Switched off
// #define _THINGSERVER "your.extra.server"     // Server URL of the LoRa-udp.js handler
// #define _THINGPORT 1700                      // Port 1700 is old compatibility

// Wifi definitions
// WPA is an array with SSID and password records. Set WPA size to number of entries in array
// When using the WiFiManager, we will overwrite the first entry with the
// accesspoint we last connected to with WifiManager
// NOTE: Structure needs at least one (empty) entry.
//      So WPASIZE must be >= 1
struct wpas
{
    char login[32]; // Maximum Buffer Size (and allocated memory)
    char passw[64];
};

// Please fill in at least ONE valid SSID and password from your own WiFI network
// below. This is needed to get the gateway working
//
wpas wpa[] = {
    {"Boogmakerstraat 45", "danielandclaire"}};

// Define the name of the accesspoint if the gateway is in accesspoint mode (is
// getting WiFi SSID and password using WiFiManager)
#define AP_NAME "ESP32-Gway-Things4U"
#define AP_PASSWD "0297282242"

// For asserting and testing the following defines are used.
//
#if !defined(CFG_noassert)
#define ASSERT(cond) \
    if (!(cond))     \
    gway_failed(__FILE__, __LINE__)
#else
#define ASSERT(cond) /**/
#endif
danielkoek commented 4 years ago

Thanks in advance for helping me out with this, if this doesn't work i give up with a handmade one and will just order a prefab

platenspeler commented 4 years ago

I cannot find anything wrong with it. Can you send the loraModem.h file as well, I like to see your definitions of _PIN_OUT == 5.

danielkoek commented 4 years ago

I am really a big idiot, i changed the pins but not the defines eg:

define SCK 18

define MISO 19

define MOSI 23

define SS 16

define DIO0 26

Is the correct one, but i had the old one from pinout 4, left in place, that obviously doesn't work! thank you so so much for all your help with this! now i can get started with automating my community garden!