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.

Display Custom Home Screen for Different Users
#1
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
Reply
#2
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.
Reply
#3
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?
Reply
#4
Via a script:
Code:
io.writefile('/www/user/ip.lp', '<?=ngx.var.remote_addr?>')
Reply
#5
Thank you, have just implemented the script and this is working really well!

Kind Regards
James
Reply
#6
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);
      }
    });
  }
});
Reply


Forum Jump: