B4R Question ESP32 - BT and Wifi together - simple program - no space

petr4ppc

Active Member
Licensed User
Dear friends,

please for advice. I am trying to use on ESP32 wroom both library: BT and Wifi,
but after compilation I see, that I have not free space...
(4 MB Flash)

If I am trying:
1) only BT lib. - everything is OK
2) only WIFI lib. - eveyrthing is OK
3) both libs - BT and Wifi - no space. Project have 111% of space
( I can use +- 1100000byte but my project have +- 1300000 byte. This I see in logs)

This happen if I am using basic code(see below). I am doing some mistake? Or realy this basic code is too big?
I have on the start of my project bigger project then ESP32 memory? (I am using httpjob).

I found this information about memory:
https://www.esp32.com/viewtopic.php?t=168

B4X:
#Region Project Attributes
   #AutoFlushLogs: True
   #CheckArrayBounds: True
   #StackBufferSize: 600
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Private bt As ESP32Bluetooth
    Private astream As AsyncStreams

    Private wifi As ESP8266WiFi
 
'    Private jsontext() As Byte
    Private quotearray() As Byte = """"
    Private LastIndex As Int
 
End Sub


Private Sub AppStart
    Serial1.Initialize(115200)
 
    Log("App ESP32 WROOM 32 Start")

    If bt.Initialize("ESP32", "bt_StateChanged") = False Then
        Log("Failed to start Bluetooth")
        Return
    End If
    astream.Initialize(bt.Stream, "astream_NewData", "astream_Error")
 
    If wifi.Connect("Mywifi") Then
        Log("Connected")
    Else
        Log("Failed to connect to router.")
        Return
    End If
 
    Delay(1000)

    HttpJob.Initialize("Example")
    HttpJob.Download("http://www.something.yyx/aaa.php?id=18")

End Sub

Sub JobDone (Job As JobResult)
    Log("*******************************")
End Sub

Sub GetTextValueFromKey (json() As Byte, Key() As Byte, StartIndex As Int, ResultBuffer() As Byte, MaxLength As UInt)
    Dim bc As ByteConverter
    Dim qkey() As Byte = JoinBytes(Array(quotearray, Key, quotearray))
    Dim i As Int = bc.IndexOf2(json, qkey, StartIndex)
    If i = -1 Then
        bc.ArrayCopy(Array As Byte(), ResultBuffer)
        Return
    End If
    Dim i1 As Int = bc.IndexOf2(json, quotearray, i + qkey.Length + 1)
    Dim i2 As Int = bc.IndexOf2(json, quotearray, i1 + 1)
    bc.ArrayCopy(bc.SubString2(json, i1 + 1, Min(i2, i1 + 1 + MaxLength)), ResultBuffer)
    LastIndex = i2
End Sub

Sub GetNumberValueFromKey (json() As Byte, Key() As Byte, StartIndex As Int) As Double
    Dim bc As ByteConverter
    Dim qkey() As Byte = JoinBytes(Array(quotearray, Key, quotearray))
    Dim i As Int = bc.IndexOf2(json, qkey, StartIndex)
    If i = -1 Then Return 0
    Dim colon As Int = bc.IndexOf2(json, ":", i + qkey.Length)
    Dim i2 As Int = 0
    For Each c As String In Array As String(",", "}", "]")
        i2 = bc.IndexOf2(json, c, colon + 1)
        If i2 <> -1 Then
            Exit
        End If
    Next
    Dim res() As Byte = bc.SubString2(json, colon + 1, i2)
    LastIndex = i2 + 1
    res = bc.Trim(res)
    Dim s As String = bc.StringFromBytes(res)
    Dim value As Double = s
    Return value
End Sub

Sub bt_StateChanged (Connected As Boolean)
    Log("connected: ", Connected)
End Sub

Sub AStream_Error
    Log("error")
End Sub

Sub AStream_NewData (Buffer() As Byte)
    Log("NewData: ", Buffer)
    astream.Write("Echo from ESP32: ")
    astream.Write(Buffer)
    bt.Stream.Flush
End Sub
 
Last edited:

thetahsk

Active Member
Licensed User
Dear friends,

please for advice. I am trying to use on ESP32 wroom both library: BT and Wifi,
but after compilation I see, that I have not free space...
(4 MB Flash)
Well, that's normal because BT and Wifi uses a lot of flash memory.
Change the Partition Scheme e.g. to huge_app in your board configuration.

B4R ...Tools...BoardSelector...PartionScheme->huge_app

https://github.com/espressif/arduino-esp32/tree/master/tools/partitions
https://github.com/espressif/arduino-esp32/blob/master/boards.txt#L10
 

petr4ppc

Active Member
Licensed User
Dear friends,

thank you for your answers and support,

Erel - sure, I am sending files from project
(because project is too large for uploading (after compiling = 18,5MB) I was renamed *.b4r to *.txt and I am sending files from project)
Thetahsk - thank you for tip, I will try it

Best regards
p4ppc
 

Attachments

petr4ppc

Active Member
Licensed User
Dear friends,

it is SOLVED

I can upload project (sent earlier in attachement) after I did steps as wrote THETAHSK

Thank you very much
Best regards
p4ppc
 
Top