Logic Machine Forum
Display Custom Home Screen for Different Users - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Display Custom Home Screen for Different Users (/showthread.php?tid=4171)



Display Custom Home Screen for Different Users - jamesng - 02.08.2022

Hi

We have a number of iPads connected to the same LogicMachine UI.

What's the best way to identify the iPad so that I can use a custom javascript attached to the a home button to display a custom screen for that location.  IE: If the device was in the Kitchen it would display the Kitchen home screen, if it was in the Master Bedroom then it would display the home screen for that location every time the user tapped the home button.

I would ideally like the user to nominate their device's preferred home screen / location - Is there a device identifier which we can access to store against their preferred location to create a lookup table in storage.  And how would I access this identifier to store the value with a lua script, and then read back that value using a javascript linked to a button.

Many thanks in advance

Kind Regards
James


RE: Display Custom Home Screen for Different Users - admin - 03.08.2022

Create ip.lp file and upload to user directory using FTP with apps login:
Code:
<?=ngx.var.remote_addr?>

Add to Custom JS and modify plans object as needed (Client IP -> Plan ID mapping).
Code:
$(function() {
  if ($('body').hasClass('usermode') || $('html').hasClass('touch')) {
    var plans = {
      '192.168.0.2': 10,
      '192.168.0.3': 2,
    };
    
    $.get('/user/ip.lp', function(resp) {
      var ip = $.trim(resp);
      var plan = plans[ ip ];
      
      if (plan) {
        showPlan(plan);
      }
    });
  }
});

For this to work correctly either set each client device to a static IP address or create static DHCP entries on your router.


RE: Display Custom Home Screen for Different Users - jamesng - 03.08.2022

I'm on the Schneider SHAC version of LogicMachine which seems to have FTP access disabled on the latest firmware update. Is there another way to get the IP address?


RE: Display Custom Home Screen for Different Users - admin - 03.08.2022

Via a script:
Code:
io.writefile('/www/user/ip.lp', '<?=ngx.var.remote_addr?>')



RE: Display Custom Home Screen for Different Users - jamesng - 03.08.2022

Thank you, have just implemented the script and this is working really well!

Kind Regards
James


RE: Display Custom Home Screen for Different Users - admin - 04.08.2022

Another option is to use mac address instead of IP. This will only work for local clients (not external via port forward).

Run script once:
Code:
io.writefile('/www/user/mac.lp', [[<?
clientip = ngx.var.remote_addr
lines = io.readfile('/proc/net/arp'):split('\n')

for i = 2, #lines do
  ip, _, _, mac = unpack(lines[ i ]:gsub('%s+', ' '):split(' '))
  if clientip == ip then
    write(mac)
    break
  end
end
?>]])

Add to Custom JS (replace IP check script):
Code:
$(function() {
  if ($('body').hasClass('usermode') || $('html').hasClass('touch')) {
    var plans = {
      'aa:bb:cc:dd:ee:ff': 9,
    };
    
    $.get('/user/mac.lp', function(resp) {
      var mac = $.trim(resp);
      var plan = plans[ mac ];
      
      if (plan) {
        showPlan(plan);
      }
    });
  }
});