Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build with Lora Wifi 32 v2 unsing Platform.io #147

Open
rodrigobutta opened this issue May 7, 2024 · 10 comments
Open

Cannot build with Lora Wifi 32 v2 unsing Platform.io #147

rodrigobutta opened this issue May 7, 2024 · 10 comments

Comments

@rodrigobutta
Copy link

rodrigobutta commented May 7, 2024

Example Factory project: WiFi_LoRa_32_V2_FactoryTest

This error happens in several lib files (not only in my main one)

error: 'HELTEC_BOARD' was not declared in this scope

And if I handpick fix it in heltec libraries (jsut for testing), some other similar ones ocurr too.

platformio.ini

[env:heltec_wifi_lora_32_V2]
platform = espressif32
board = heltec_wifi_lora_32_V2
framework = arduino
lib_deps = 
	heltecautomation/ESP32_LoRaWAN@^2.1.1
	heltecautomation/Heltec ESP32 Dev-Boards@^2.0.1

May be related

For what I see in this Issue it seems that the fix could be already merged a month ago, but I don´t see releases since a week before this fix (Merge on March 27, last release on March 22 )

image

TLDR; this is the project file if needed

image
/*
 * HelTec Automation(TM) WIFI_LoRa_32 factory test code, witch includ
 * follow functions:
 * 
 * - Basic OLED function test;
 * 
 * - Basic serial port test(in baud rate 115200);
 * 
 * - LED blink test;
 * 
 * - WIFI connect and scan test;
 * 
 * - LoRa Ping-Pong test (DIO0 -- GPIO26 interrup check the new incoming messages);
 * 
 * - Timer test and some other Arduino basic functions.
 *
 * by Aaron.Lee from HelTec AutoMation, ChengDu, China
 * 成都惠利特自动化科技有限公司
 * https://heltec.org
 *
 * this project also realess in GitHub:
 * https://github.com/HelTecAutomation/Heltec_ESP32
*/

#include "Arduino.h"
#include "WiFi.h"
#include "images.h"
#include "LoRaWan_APP.h"
#include <Wire.h>  
#include "HT_SSD1306Wire.h"
/********************************* lora  *********************************************/
#define RF_FREQUENCY                                868000000 // Hz

#define TX_OUTPUT_POWER                             10        // dBm

#define LORA_BANDWIDTH                              0         // [0: 125 kHz,
                                                              //  1: 250 kHz,
                                                              //  2: 500 kHz,
                                                              //  3: Reserved]
#define LORA_SPREADING_FACTOR                       7         // [SF7..SF12]
#define LORA_CODINGRATE                             1         // [1: 4/5,
                                                              //  2: 4/6,
                                                              //  3: 4/7,
                                                              //  4: 4/8]
#define LORA_PREAMBLE_LENGTH                        8         // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT                         0         // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON                  false
#define LORA_IQ_INVERSION_ON                        false


#define RX_TIMEOUT_VALUE                            1000
#define BUFFER_SIZE                                 30 // Define the payload size here

char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];

static RadioEvents_t RadioEvents;
void OnTxDone( void );
void OnTxTimeout( void );
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );

typedef enum
{
    LOWPOWER,
    STATE_RX,
    STATE_TX
}States_t;

int16_t txNumber;
int16_t rxNumber;
States_t state;
bool sleepMode = false;
int16_t Rssi,rxSize;

String rssi = "RSSI --";
String packSize = "--";
String packet;
String send_num;
String show_lora = "lora data show";

unsigned int counter = 0;
bool receiveflag = false; // software flag for LoRa receiver, received data makes it true.
long lastSendTime = 0;        // last send time
int interval = 1000;          // interval between sends
uint64_t chipid;
int16_t RssiDetection = 0;


void OnTxDone( void )
{
	Serial.print("TX done......");
	state=STATE_RX;

}

void OnTxTimeout( void )
{
  Radio.Sleep( );
  Serial.print("TX Timeout......");
	state=STATE_TX;
}

void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{
	rxNumber++;
  Rssi=rssi;
  rxSize=size;
  memcpy(rxpacket, payload, size );
  rxpacket[size]='\0';
  Radio.Sleep( );
  Serial.printf("\r\nreceived packet \"%s\" with Rssi %d , length %d\r\n",rxpacket,Rssi,rxSize);
  Serial.println("wait to send next packet");
	receiveflag = true;
  state=STATE_TX;
}


void lora_init(void)
{
  Mcu.begin(HELTEC_BOARD,SLOW_CLK_TPYE);
  txNumber=0;
  Rssi=0;
  rxNumber = 0;
  RadioEvents.TxDone = OnTxDone;
  RadioEvents.TxTimeout = OnTxTimeout;
  RadioEvents.RxDone = OnRxDone;

  Radio.Init( &RadioEvents );
  Radio.SetChannel( RF_FREQUENCY );
  Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
                                 LORA_SPREADING_FACTOR, LORA_CODINGRATE,
                                 LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
                                 true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );

  Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
                                 LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
                                 LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
                                 0, true, 0, 0, LORA_IQ_INVERSION_ON, true );
	state=STATE_TX;
}


/********************************* lora  *********************************************/

SSD1306Wire  factory_display(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY_128_64, RST_OLED); // addr , freq , i2c group , resolution , rst


void logo(){
	factory_display.clear();
	factory_display.drawXbm(0,5,logo_width,logo_height,(const unsigned char *)logo_bits);
	factory_display.display();
}

void WIFISetUp(void)
{
	// Set WiFi to station mode and disconnect from an AP if it was previously connected
	WiFi.disconnect(true);
	delay(100);
	WiFi.mode(WIFI_STA);
	WiFi.setAutoConnect(true);
	WiFi.begin("Your WiFi SSID","Your Password");//fill in "Your WiFi SSID","Your Password"
	delay(100);

	byte count = 0;
	while(WiFi.status() != WL_CONNECTED && count < 10)
	{
		count ++;
		delay(500);
		factory_display.drawString(0, 0, "Connecting...");
		factory_display.display();
	}

	factory_display.clear();
	if(WiFi.status() == WL_CONNECTED)
	{
		factory_display.drawString(0, 0, "Connecting...OK.");
		factory_display.display();
//		delay(500);
	}
	else
	{
		factory_display.clear();
		factory_display.drawString(0, 0, "Connecting...Failed");
		factory_display.display();
		//while(1);
	}
	factory_display.drawString(0, 10, "WIFI Setup done");
	factory_display.display();
	delay(500);
}

void WIFIScan(unsigned int value)
{
	unsigned int i;
    WiFi.mode(WIFI_STA);

	for(i=0;i<value;i++)
	{
		factory_display.drawString(0, 20, "Scan start...");
		factory_display.display();

		int n = WiFi.scanNetworks();
		factory_display.drawString(0, 30, "Scan done");
		factory_display.display();
		delay(500);
		factory_display.clear();

		if (n == 0)
		{
			factory_display.clear();
			factory_display.drawString(0, 0, "no network found");
			factory_display.display();
			//while(1);
		}
		else
		{
			factory_display.drawString(0, 0, (String)n);
			factory_display.drawString(14, 0, "networks found:");
			factory_display.display();
			delay(500);

			for (int i = 0; i < n; ++i) {
			// Print SSID and RSSI for each network found
				factory_display.drawString(0, (i+1)*9,(String)(i + 1));
				factory_display.drawString(6, (i+1)*9, ":");
				factory_display.drawString(12,(i+1)*9, (String)(WiFi.SSID(i)));
				factory_display.drawString(90,(i+1)*9, " (");
				factory_display.drawString(98,(i+1)*9, (String)(WiFi.RSSI(i)));
				factory_display.drawString(114,(i+1)*9, ")");
				//factory_display.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
				delay(10);
			}
		}

		factory_display.display();
		delay(800);
		factory_display.clear();
	}
}

bool resendflag=false;
bool deepsleepflag=false;
bool interrupt_flag = false;
void interrupt_GPIO0()
{
	interrupt_flag = true;
}
void interrupt_handle(void)
{
	if(interrupt_flag)
	{
		interrupt_flag = false;
		if(digitalRead(0)==0)
		{
			if(rxNumber <=2)
			{
				resendflag=true;
			}
			else
			{
				deepsleepflag=true;
			}
		}
	}

}
void VextON(void)
{
  pinMode(Vext,OUTPUT);
  digitalWrite(Vext, LOW);
  
}

void VextOFF(void) //Vext default OFF
{
  pinMode(Vext,OUTPUT);
  digitalWrite(Vext, HIGH);
}
void setup()
{
	Serial.begin(115200);
	VextON();
	delay(100);
	factory_display.init();
	factory_display.clear();
	factory_display.display();
	logo();
	delay(300);
	factory_display.clear();

	WIFISetUp();
	WiFi.disconnect(); //
	WiFi.mode(WIFI_STA);
	delay(100);

	WIFIScan(1);

	chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
	Serial.printf("ESP32ChipID=%04X",(uint16_t)(chipid>>32));//print High 2 bytes
	Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes.

	attachInterrupt(0,interrupt_GPIO0,FALLING);
	lora_init();
	packet ="waiting lora data!";
  factory_display.drawString(0, 10, packet);
  factory_display.display();
  delay(100);
  factory_display.clear();
	pinMode(LED ,OUTPUT);
	digitalWrite(LED, LOW);  
}


void loop()
{
interrupt_handle();
 if(deepsleepflag)
 {
	VextOFF();
	Radio.Sleep();
	SPI.end();
	pinMode(RADIO_DIO_1,ANALOG);
	pinMode(RADIO_NSS,ANALOG);
	pinMode(RADIO_RESET,ANALOG);
	pinMode(RADIO_DIO_0,ANALOG);
	pinMode(LORA_CLK,ANALOG);
	pinMode(LORA_MISO,ANALOG);
	pinMode(LORA_MOSI,ANALOG);
	esp_sleep_enable_timer_wakeup(600*1000*(uint64_t)1000);
	esp_deep_sleep_start();
 }

 if(resendflag)
 {
	state = STATE_TX;
	resendflag = false;
 }

if(receiveflag && (state==LOWPOWER) )
{
	receiveflag = false;
	packet ="R_data:";
	int i = 0;
	while(i < rxSize)
	{
		packet += rxpacket[i];
		i++;
	}
	packSize = "R_Size: ";
	packSize += String(rxSize,DEC);
	packSize += " R_rssi: ";
	packSize += String(Rssi,DEC);
	send_num = "send num: ";
	send_num += String(txNumber,DEC);
	factory_display.drawString(0, 0, show_lora);
  factory_display.drawString(0, 10, packet);
  factory_display.drawString(0, 20, packSize);
  factory_display.drawString(0, 50, send_num);
  factory_display.display();
  delay(10);
  factory_display.clear();

  if((rxNumber%2)==0)
  {
   digitalWrite(LED, HIGH);  
  }
}
switch(state)
  {
    case STATE_TX:
      delay(1000);
      txNumber++;
      sprintf(txpacket,"hello %d,Rssi:%d",txNumber,Rssi);
      Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket));
      Radio.Send( (uint8_t *)txpacket, strlen(txpacket) );
      state=LOWPOWER;
      break;
    case STATE_RX:
      Serial.println("into RX mode");
      Radio.Rx( 0 );
      state=LOWPOWER;
      break;
    case LOWPOWER:
      Radio.IrqProcess( );
      break;
    default:
      break;
  }
}
@romoloman
Copy link

I'm really sorry for heltec, I tried before with a lot of satisfaction their cubecell series product, well documented and working flawlessy, I cannot really understand why they choose to customize the ESP32 IDF and not instead supplying a good library that relies on standard framework. To get the compiler be able to compile an example it took me three hours of work.
Even good hardware if badly documented becomes useless.
Installing the framework was a complete mess, i used a new virtual machine to do not destroy my setup.
The hardware is good but development environment is fool.

@kainzjo1
Copy link

Same issue for me.

@kainzjo1
Copy link

Compiling .pio\build\heltec_wifi_lora_32_V2\lib693\Heltec ESP32 Dev-Boards\driver\board.c.o
In file included from .pio/libdeps/heltec_wifi_lora_32_V2/Heltec ESP32 Dev-Boards/src/LoRaWan_APP.h:9,
from src/main.cpp:28:
.pio/libdeps/heltec_wifi_lora_32_V2/Heltec ESP32 Dev-Boards/src/loramac/LoRaMac.h:137: warning: "LORA_MAC_PRIVATE_SYNCWORD" redefined
#define LORA_MAC_PRIVATE_SYNCWORD 0x12

In file included from .pio/libdeps/heltec_wifi_lora_32_V2/Heltec ESP32 Dev-Boards/src/ESP32_Mcu.h:13,
from .pio/libdeps/heltec_wifi_lora_32_V2/Heltec ESP32 Dev-Boards/src/LoRaWan_APP.h:7,
from src/main.cpp:28:
.pio/libdeps/heltec_wifi_lora_32_V2/Heltec ESP32 Dev-Boards/src/driver/sx126x.h:122: note: this is the location of the previous definition
#define LORA_MAC_PRIVATE_SYNCWORD 0x1424

In file included from .pio/libdeps/heltec_wifi_lora_32_V2/Heltec ESP32 Dev-Boards/src/LoRaWan_APP.h:9,
from src/main.cpp:28:
.pio/libdeps/heltec_wifi_lora_32_V2/Heltec ESP32 Dev-Boards/src/loramac/LoRaMac.h:142: warning: "LORA_MAC_PUBLIC_SYNCWORD" redefined
#define LORA_MAC_PUBLIC_SYNCWORD 0x34

In file included from .pio/libdeps/heltec_wifi_lora_32_V2/Heltec ESP32 Dev-Boards/src/ESP32_Mcu.h:13,
from .pio/libdeps/heltec_wifi_lora_32_V2/Heltec ESP32 Dev-Boards/src/LoRaWan_APP.h:7,
from src/main.cpp:28:
.pio/libdeps/heltec_wifi_lora_32_V2/Heltec ESP32 Dev-Boards/src/driver/sx126x.h:127: note: this is the location of the previous definition
#define LORA_MAC_PUBLIC_SYNCWORD 0x3444

Compiling .pio\build\heltec_wifi_lora_32_V2\lib693\Heltec ESP32 Dev-Boards\driver\delay.c.o

@AWeleczka
Copy link

I came across this Heltec-Aaron-Lee/WiFi_Kit_series#248 (comment) while looking for a solution to the same issue with the factory test example you provided above.

Downgrading to 1.1.5 allowed me to compile and upload the (different) factory test to my v2 board.
Though I'm using the Arduino IDE and not platformio I assume the library versions are the same.

@felipemaion
Copy link

After digging a lot on this issue here is what I've found:
from ESP32_Mcu.h

/* HELTEC_BOARD
*
* ESP32S3 CHIP
* WIFI_LORA_32_V3          30
* WIRELESS_STICK_V3        31
* WIRELESS_STICK_LITE_V3   32
* WIRELESS_SHELL_V3        33
* WIRELESS_TRACKER         34
* WIFI_KIT_32_V3           35
*
* CAPSULE_SENSOR_V3 50
* WIRELESS_PAPER    60
*
*
* ESP32C3 CHIP
* WIRELESS_MINI_SHELL      70
*
*
* ESP32D0 CHIP
*
* WIFI_LORA_32_V2         0
* WIFI_LORA_32            1
* WIRELESS_STICK          2
* WIRELESS_STICK_LITE //WIRELESS_SHELL     3
* WIRELESS_BRIDGE         4
* WIFI_KIT_32             5
*/

And from "https://raw.githubusercontent.com/espressif/arduino-esp32/master/boards.txt":

heltec_wifi_lora_32_V2.build.defines=-D{build.band} -DMCU_ESP32_D0 -DWIFI_LORA_32_V2 -DHELTEC_BOARD=0 -DRADIO_CHIP_SX127X -DSLOW_CLK_TPYE=0 -DLoRaWAN_DEBUG_LEVEL={build.LoRaWanDebugLevel} -DACTIVE_REGION=LORAMAC_{build.band} -DLORAWAN_PREAMBLE_LENGTH={build.LORAWAN_PREAMBLE_LENGTH}  -DLORAWAN_DEVEUI_AUTO={build.LORAWAN_DEVEUI_AUTO}  {build.psram}

So, to make it work, my platformio.ini was like that:

[env:heltec_wifi_lora_32_V2]
platform = espressif32
lib_deps = heltecautomation/Heltec ESP32 Dev-Boards@^2.0.2
board = heltec_wifi_lora_32_V2
framework = arduino
upload_protocol = esptool
build_flags = 
	-D LoRaWAN_DEBUG_LEVEL=3
	-D LORAWAN_PREAMBLE_LENGTH=8
    -DMCU_ESP32_D0
    -D ARDUINO_HELTEC_WIFI_LORA_32_V2
	-D WIFI_LORA_32_V2
	-D HELTEC_WIFI_LORA_32_V2
	-D REGION_US915
	-D LORA_DISPLAY
    -DHELTEC_BOARD=0 
    -DRADIO_CHIP_SX127X 
    -DSLOW_CLK_TPYE=0

And the BUILD was successful.
Cheers.

@eabase
Copy link

eabase commented Nov 26, 2024

@felipemaion
I don't have this file. Where can I find it?
Or where should it be located if I don't have it?

@felipemaion
Copy link

felipemaion commented Nov 26, 2024

@felipemaion I don't have this file. Where can I find it? Or where should it be located if I don't have it?

Hello @eabase,
Are you using Platformio on VSCODE to program your device? Usually the platformio.ini is on the root folder of the project.

On my machine it is located inside <User>/Documents/PlatformIO/<ProjetectName>/platformio.ini
Hope this helps.

@eabase
Copy link

eabase commented Nov 27, 2024

@felipemaion
Hmm, I'm not using PlatformIO, I'm using Arduino-IDE...
I thought platformio was just a filename... so maybe that explains it?

@felipemaion
Copy link

@felipemaion Hmm, I'm not using PlatformIO, I'm using Arduino-IDE... I thought platformio was just a filename... so maybe that explains it?

Yeap, that's explain it all.
To run with Arduino-IDE it is much easier, you just need to install its library.
Try to check this site: Heltec Library

@eabase
Copy link

eabase commented Nov 29, 2024

@felipemaion

To run with Arduino-IDE it is much easier, you just need to install its library.

Yeah, I was using that for a while but with all the Heltec bugs in the examples, AIDE was getting painful to use, as the compilation for a simple LoRa example takes over 2 minutes to complete, while configuration is abstracted away in nightmare. In general the AIDE UX is absolutely horrible, and all support or improvement suggestions are silenced, closed. People say PlatformIO is a way faster, possibly 5x, and I like the simple clear configuration *.ini files.
So I'm going to give that a shot. 👍

  • I have the WiFi LoRa 32 (V3) v3.1, what is the correct Factory Test example code to use?
  • I also noticed that in LoRa_rx_tx example, that the device transmits all over the place, with bout 5x the spectral width of correct lora devices. What's going on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants