Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:43 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : WEB MQTT is eating ram

Author Message
andreas

Senior Member

Joined: 07/12/2020
Location: Germany
Posts: 207
Posted: 11:43am 02 Jun 2023
Copy link to clipboard 
Print this post

Hello,

as I wrote in an earlier posting, WEB MQTT is eating 512 bytes of ram after each use. In the following program the "General" RAM is constantly increasing within the main loop when WEB MQTT commands are used. If I comment out the WEB MQTT part (from ON ERROR until WEB MQTT CLOSE) then the program runs stable and does not increase general ram as shown by the "memory" statement.

The program is measuring a brightness sensor.

' Helligkeitsmessung
Option explicit

SetPin gp28,ain

Dim minbrightness As float = 4.0
Dim maxbrightness As float = 0.0
Dim hell As Integer

Function bright()
 Static h As float = 0.0
 Static n As integer = 0
 n = Min(5, n+1)
 h = h + (Pin(gp28)-h)/n
 If h > maxbrightness Then maxbrightness = h
 If h < minbrightness Then minbrightness = h
 bright = h
End Function

Function scale(brightness)
 Local range As float = 0.0

 range = maxbrightness - minbrightness
 If range <> 0 Then
   scale = 100 - Int((brightness - minbrightness) / (range / 100))
 Else
   scale = 100
 EndIf
End Function

Do
 hell = scale(bright())
 Print "Helligkeit: ";hell;" %"
 On ERROR SKIP 3
 WEB MQTT CONNECT "192.168.178.54",1883,"anon","anon"
 WEB MQTT PUBLISH "brightness",Str$(hell)
 WEB MQTT CLOSE
 Print
 Print
 Memory
 Print
 Print
 Pause 200
Loop


the OPTIONS are:

WebMite MMBasic Version 5.07.07
OPTION SYSTEM I2C GP0,GP1
OPTION LIBRARY_FLASH_SIZE  14000
OPTION COLOURCODE ON
OPTION DISPLAY 50, 100
OPTION WIFI FritzBox, *********************
OPTION TELNET CONSOLE ON
OPTION SDCARD GP5, GP2, GP3, GP4


-andreas
Edited 2023-06-02 21:46 by andreas
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 12:30pm 02 Jun 2023
Copy link to clipboard 
Print this post

Why have you got ON ERROR? It is highly likely that if there is an error then memory will be lost. Please repeat without the error handling and let me know results.
 
andreas

Senior Member

Joined: 07/12/2020
Location: Germany
Posts: 207
Posted: 01:58pm 02 Jun 2023
Copy link to clipboard 
Print this post

  matherp said  Why have you got ON ERROR? It is highly likely that if there is an error then memory will be lost. Please repeat without the error handling and let me know results.


Because sometimes the Connect will not succeed and then the program would just stop running.

I removed the "ON ERROR" and the "General RAM" is still increasing:

Here you see a full run. Look @ the "General RAM" which is increasing by 1K every two turns:

Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  1K ( 0%) General
104K (100%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  1K ( 0%) General
104K (100%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  2K ( 1%) General
103K (99%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  2K ( 1%) General
103K (99%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  3K ( 2%) General
102K (98%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  3K ( 2%) General
102K (98%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  4K ( 3%) General
101K (97%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  4K ( 3%) General
101K (97%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  5K ( 4%) General
100K (96%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  5K ( 4%) General
100K (96%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  6K ( 5%) General
 99K (95%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  6K ( 5%) General
 99K (95%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  7K ( 6%) General
 98K (94%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  7K ( 6%) General
 98K (94%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  8K ( 7%) General
 97K (93%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  8K ( 7%) General
 97K (93%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  9K ( 8%) General
 96K (92%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
  9K ( 8%) General
 96K (92%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
 10K ( 8%) General
 95K (92%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
 10K ( 9%) General
 95K (91%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
 11K ( 9%) General
 94K (91%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
 11K (10%) General
 94K (90%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883


Program:
  1K ( 0%) Program (43 lines)
 79K (100%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 0%) 7 Variables
 12K (10%) General
 93K (90%) Free


Helligkeit:  100 %
Connecting to 192.168.178.54 port 1883
[34] WEB MQTT CONNECT "192.168.178.54",1883,"anon","anon"
Error : Failed to connect
>


-andreas
 
andreas

Senior Member

Joined: 07/12/2020
Location: Germany
Posts: 207
Posted: 03:12pm 02 Jun 2023
Copy link to clipboard 
Print this post

With the latest WebMiteV5.07.08b2 it works and values can be made visible using IoT MQTT panel:)







-andreas
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024