This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Lm rebooting after mosaic change
#1
hello guys i have  a new problem with my lm each time i try save a change at  widget in mosaic the lm rebot .
does that happend to anyone before
Reply
#2
Do you use custom images?
------------------------------
Ctrl+F5
Reply
#3
(27.01.2025, 10:08)Daniel Wrote: Do you use custom images?

i have general custom image backround and custom icons on some widget
Reply
#4
This is your problem, Mosaic has a design issue and it is limited to few MBs of custom images.  The limit is around 8-9MB but each time you use even same custom image it is still counted as new and added to the total. Run this script once, it will move all custom images to LM images and replace yours with url.  The issue with such solution is that you will not see images from cloud.  This will fix your project and if you still want to use custome images also in cloud then make the size as small as possible.

Code:
require('json')
require('encdec')

mosaickey = 'mosaic30:config:0'

config = storage.exec('get', mosaickey)
-- config = io.readfile('mosaic-backup.json')
config = json.pdecode(config)

icons = {}

relpath = '../../../../scada/resources/icons/'
abspath = '/www/scada/resources/icons/'

function fixicon(tbl)
  local file = tbl.file

  if type(file) ~= 'string' then
    return
  end

  if file:sub(1, 10) ~= 'data:image' then
    return true
  end

  local hash = encdec.md5(file)

  if not icons[ hash ] then
    local poss = file:find('/')
    local pose = file:find(';')
    local posd = file:find(',')

    local ext = file:sub(poss + 1, pose - 1)
    local filename = hash .. '.' .. ext

    local data = encdec.base64dec(file:sub(posd + 1))

    io.writefile(abspath .. filename, data)

    icons[ hash ] = relpath .. filename
  end

  tbl.file = icons[ hash ]
  return true
end

function fixstruct(tbl)
  for key, val in pairs(tbl) do
    if type(val) == 'table' then
      if not fixicon(val) then
        fixstruct(val)
      end
    end
  end
end

fixstruct(config.floors)
fixstruct(config.imported_widgets)

config.custom_icons = icons

config = json.encode(config)
storage.exec('set', mosaickey, config)
------------------------------
Ctrl+F5
Reply
#5
(27.01.2025, 10:19)Daniel Wrote: This is your problem, Mosaic has a design issue and it is limited to few MBs of custom images.  The limit is around 8-9MB but each time you use even same custom image it is still counted as new and added to the total. Run this script once, it will move all custom images to LM images and replace yours with url.  The issue with such solution is that you will not see images from cloud.  This will fix your project and if you still want to use custome images also in cloud then make the size as small as possible.

Code:
require('json')
require('encdec')

mosaickey = 'mosaic30:config:0'

config = storage.exec('get', mosaickey)
-- config = io.readfile('mosaic-backup.json')
config = json.pdecode(config)

icons = {}

relpath = '../../../../scada/resources/icons/'
abspath = '/www/scada/resources/icons/'

function fixicon(tbl)
  local file = tbl.file

  if type(file) ~= 'string' then
    return
  end

  if file:sub(1, 10) ~= 'data:image' then
    return true
  end

  local hash = encdec.md5(file)

  if not icons[ hash ] then
    local poss = file:find('/')
    local pose = file:find(';')
    local posd = file:find(',')

    local ext = file:sub(poss + 1, pose - 1)
    local filename = hash .. '.' .. ext

    local data = encdec.base64dec(file:sub(posd + 1))

    io.writefile(abspath .. filename, data)

    icons[ hash ] = relpath .. filename
  end

  tbl.file = icons[ hash ]
  return true
end

function fixstruct(tbl)
  for key, val in pairs(tbl) do
    if type(val) == 'table' then
      if not fixicon(val) then
        fixstruct(val)
      end
    end
  end
end

fixstruct(config.floors)
fixstruct(config.imported_widgets)

config.custom_icons = icons

config = json.encode(config)
storage.exec('set', mosaickey, config)

is there any way at least to the cloud to be viseble the deafult icons ??
Reply
#6
Default icons will stay, only custom icons.
------------------------------
Ctrl+F5
Reply
#7
(30.01.2025, 13:59)Daniel Wrote: Default icons will stay, only custom icons.
sorry i dint explain well, i meant to display  the defualt icons to the widgets that i have custom icons
Reply
#8
I'm not sure if I fully understand you. A widget/element can have one icon. It cannot be one locally and another in cloud.
------------------------------
Ctrl+F5
Reply
#9
(30.01.2025, 14:41)Daniel Wrote: I'm not sure if I fully understand you. A widget/element can have one icon. It cannot be one locally and another in cloud.

You understund well... thank you very much
Reply


Forum Jump: