Node-Red on a Phone

I have to hand ALL the credit to Dave at the Node-Red Google Groups for this – and you might want to pop any questions in that direction because I know even less about running Android at the command prompt than I do Debian!

Running Node-Red on your Android phone or tablet!! Yes you CAN. it turns out that it is dead easy. Using a terminal program (App store) such as Termux.

So basically install Termux as you would any other app.. and run it – you get the usual black terminal screen. I did this just now on my HTC ONE-M8 – might work on yours – might not.

apt update
apt upgrade
apt install coreutils nano nodejs
npm install -g --unsafe-perm node-red
node-red

That’s it -  you’re up and running.

Well, so that is Node-Red running – of course if you close the terminal you stop Node-Red so the first thing to find out is how to press control-C in that terminal!!! Any ideas anyone?

Once I got back in – instead of starting Node-red I did the following..

cd .node-red

npm install node-red-dashboard

npm install node-red-contrib-admin

npm install node-red-contrib-bigtimer

cd

node-red

Once you run node-red – you can go into the browser on the phone and run 127.0.0.1:1880 and lo and behold- node-red  - probably more usefully would be to go to the phone’s WIFI setup and find out what the IP address is – and run Node-Red in a browser on your PC and that same port number. 

Now why on EARTH would you want to do this. Well, if you could get node-red running as a service on an old tablet – along with MQTT (not sure about that one) all as services – you have a home control server base – with several hours of reliable battery backup (you’d have to run a task to stop the thing turning off I guess.

Well, something for the weekend! As answers (hopefully) emerge for the following – also running my phone with SCP from the PC would be good… I’ve no idea what the user is or the password!!!! I’ll update this.

And the first update – control characters on that terminal… here.

Meanwhile – MQTT Broker Pro which will soon have it’s own basic authentication and which already comes up on phone boot – works a treat – here are the two of them running together as seen on my PC browser.

Node Red on a Phone

Be aware – that the MQTT server does not work if you use “localhost” – you need to use “127.0.0.1” or if you want to access the MQTT server externally – the IP address of the phone. And yes I’ve tested accessing the MQTT broker externally – which is another good reason for it to have a user name and password.

All good stuff.

Facebooktwittergoogle_pluspinterestlinkedin

37 thoughts on “Node-Red on a Phone

    1. HAH - nothing like reading the manual is there - volume down and the "c" key does that - there's a whole boatload of controls when you hold the volume down button. One small step for man.... thank you.

  1. think if they code a way to access the smartphone sensors from node-red... in a bit you have gps, gprs, bt, wifi, gyro, etc... a bunch of possibilities open up...

    1. Well indeed - but first things first - it would be necessary somehow for this to run as a service from power up - without having to have that terminal running.... not sure how to do that without rooting the phone/tablet which in some cases is nigh-on impossible.

    2. This works OK and sends MQTT messages - "Sensor Node Pro" for £1.22 (the free version probably works OK).
      As an experiment its fine, just set the MQTT broker to "localhost" in the app.
      Also to see the messages in your phone node-red, set up to listen on
      "sensornode/livestream/#"
      N.B. you have to tick the sensors you want to read from - Also, another section helpfully enables you to see what sensors you have on your phone

  2. Pete, If you're experimenting with Android, be sure to get VYSOR ( http://www.vysor.io/ )
    Its a really cool combination of an Android app (download from play) and a Google Chrome app (download from within Chrome). Once installed, you just
    - Connect your Android via usb (for Wireless, you need the pro version)
    - Run the WIN 10 app and it opens a window in Win10 where you can view/control your android device from a win10 machine.
    cheers
    Pete

    1. Thanks for that Pete - I like others took Vysor off because of various issues one of which was part of the display missing off one end - and no sign of anything being done about it - of course - things might have changed.

  3. If you want MQTT on your phone, this Android App works OK (costs £1.40)
    "MQTT Broker Pro" by Centamori.
    N.B. I have it set up to work on boot up on my Samsung Galaxy J5.
    Great for messing about on the move!

    1. Ok, spill the beans - how did you get it to boot up into MQTT - and did you need to root the phone - more info the merrier.... if I could get both MQTT and Node-Red to boot up on my un-rooted tablets and phones (some of which CAN'T be rooted) I'd be, well, even happier.

    2. You may like this - I just spoke to Ivan and he's putting basic username and password security into the project - and - it will likely be in there at the end of next week.

      This is getting better by the minute - Tablet on the wall - running Node-Red Dashboard - which talks to Node-Red, which talks to MQTT, which talks to ESP gadgets...... saves having a Pi with a nasty box! And possibly more powerful depending on the phone/tablet??

      Still to resolve getting Node-Red to come up on boot - and that could do with username and pass - hoping they are the same setup as they are normally.

    3. I'v e written off to the designed of the MQTT Broker Pro - if i leave the phone to go to sleep -Node-Red keeps running just fine - tested for hours but eventually MQTT stops - the instant I touch the phone to bring it back to life, MQTT comes back on. Not expected behaviour - let's hope he sorts that.

      Need to figure out how to get SQLITE running now 🙂

  4. Before I fork out a hard-earned £1.40 🙂 It is called "PRO" which indicates it has pro features - but I can't see in the ad if it supports username and password.. and pushing it further - last will and testament? I've asked the author but someone here might now.

    1. The free one probably works fine - There are no real extras on the pro version as far as I can tell. Both are basic MQTT clients.
      I forked out for the pro to help motivate the author - and also to get updates without having to look. YMMV

        1. OK - 2 Android apps have been discussed - hopefully this makes it clearer 🙂

          - "MQTT Broker" (no free version)
          Does not have MQTT username and password options

          - "Sensor Node Pro” (Free version is "Sensor Node Free")
          THIS IS NOT A BROKER!!!!!!
          Does not have MQTT username and password options
          Author says this....
          "Sensor Node make use of all your phone's amazing sensors and stream them to your PC in real time. A typical sensor node like this cost you hundreds of dollars outside. Sensor Node is available for you for free! Or use it as a wireless IMU. You can use it for your project in school or research! I"

          1. heh he - look what you've started.
            From the usual read of your excellent blog this morning, I now have Node Red, an MQTT broker and sensor MQTT messages being sent ALL ON MY PHONE!!
            lol - what to do with it 🙂

  5. I've now setup up a task in tasker to execute node-red when I speak into the phone "OK Google set up node red". I guess it could be set up so the tasker task is executed on boot?

    N.B. this is what I did
    1) APPS
    - Download Tasker (if not already done so - N.B. you will need the last 3 AutoApps - "Input", "Shortcut" and "Voice")
    - Download "Termux" and "Termux Widget"
    2) SETUP
    - Execute Termux and run the following 3 steps
    a) - run mkdir -p ~/.shortcuts
    b) - run cd .shortcuts
    c) - run nano (and create a text file called NR with one line containing the text node-red)
    - Create a "widget" on your screen with "Termux Widget" to access the script created above
    - Create a "tasker task" to access this "widget" (N.B. you will need to have "Shortcut" from tasker "AutoApps")
    - Use the "tasker task" in a "tasker profile" - create with event->plugin->Autovoice->Recognized

    I think this task could be set up so that it is executed on boot?, but it seems more fun to see it get setup via "OK Google set up node red"

    1. Pretty much what I had in mind -tasker is a must have (I use it to allow my Sangung gear watch to send MQTT messages)...

      It should be set to load on boot - but you've done most of the work there - I'll have a look tomorrow... the only reservation I have is what if node-red crashes for any reason - not being a proper task it won't restart - but let's cross that bridge at the time - once we get passwords set up for MQTT and Node-Red - this is looking like a go-er....

      Thanks for that.

  6. Pete, interesting discussion here. I have looked at this but with the Android phone acting as the router as well.

    I did some basic power consumption measurements of my Galaxy S5 running as a router - it draws about 400mA with one device connected and minimal traffic from a few ESPs.

    That's a little lower than an Pi and an A5-V11 so its a good choice for me given I can get real time, GPS position and a host of other data from the phone. Now all I need to sort out is an instance of SQL Lite and all will be good!

  7. WELL, that was easy.

    apt install sqlite3 - all I need to do now is test it...

    Mind you - WINSCP access to this REALLY would make life easier. Vysor DOES work but it's not ideal for editing sqlite files etc....

    And of course right now - as the terminal is powering Node-Red as against it running in the background - you can't (at least I think you can't) get access to the terminal while it is running!!!

    NOPE - I knew it was going too smoothly - npm install sqlite3 fails. Awwwwww.

  8. I do hope this momentum is going to continue..

    Got SSH (sshpro) but can't see the .node-red directory - presumably wrong user..

    Got a SQLITE manager - can now create tables and add entries - but can't get SQLLITE node up on Node-Red.

    So - some good - some bad...

  9. Hi Pete, I'm not up to date with modern UNIX versions, but it the good old days you could leave processes running after logging out by using the nohup command and an ampersand at the end like this:

    nohup node-red &

    Might be worth a try!

  10. I've got a question and you might be able to help me...

    problem:

    I would like to have my devices belong to different MQTT topics. This could be done on the ESP8266 its self.. i.e. subscribe to different topics... or I'm thinking that NODERED could be used to group them all and send messages to the right ESPs if that topic is sent to...

    so..

    i have a light in the downstairs living room

    subscribed to "tvlights/+/set"
    I would like any messages to
    home/+/set
    home/downstairs/+/set
    home/downstairs/livingroom/+/set
    home/downstairs/lights/+/set

    to be sent to this ESP... I'm sure nodered can do this.. but I'm struggling to find a 'simple' way to do it! I'm sure this is me just being an idiot... but I'm already started on the alternative which is a massive overhaul of my ESP8266 code to support multiple topic subscriptions...

    any advice appreciated.

    1. I've done this a COMPLETELY different way - something you may care to consider...

      You are asking for a LOT of work there and by subscribing to lots of stuff, putting more load on the ESP.

      What I did was simple to have two subscriptions per device. The device has a unique name. Let's call our stereotype device "fred".

      So fred subscribes to:

      fred/toesp
      toesp

      That way, Node-Red can send messages to fred - which fred can then process via the payload - for example:

      {temperature?}
      {out5=1}
      {seeed:"Hello there"}

      OR Node-Red can simply send to "toesp" to send a message to all devices - for example...

      topic: toesp
      payload: {otaupdate}

      which immediately forces all devices to go off and get an ota update.

      All details in the project home control 2016 and related .DOC file etc.... (see right menu).

      1. What you've described is basically what i have now. only i want more control than that... i want to be able to turn my whole home of with a single message to home/enable/set off! or turn of downstairs... or just the lights... I thought i might be able to code node red easily using this, but I'm not sure i can.

        I have to disagree about the load on the esp with lots of subscriptions. I've had a look at the code and the ESP does not store anything about what it is subscribed to. all subscribe does is craft a packet to send to the server. the sever then sends it back messages that it has subscribed to. its quite neat as there is no load on the esp at all, its all server side. the esp would not be receiving any packets that were not directly meant for it using the topic wildcards i posted above, which should keep the load to a minimum.

        I guess i've answered my question though... i'll recode the ESP to have multiple subscriptions 🙂

        Thanks for the prompt reply.

Leave a Reply

Your email address will not be published. Required fields are marked *