Access Raspberry Pi to read data.

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Sat Apr 02, 2011 4:06 pm

Access Raspberry Pi to read data.

Post by revRider » Wed May 01, 2019 5:13 pm

I'm attempting to use process or shell to access a Raspberry Pi.

First I need to pass UN & PW, then issue the terminal command to start processing data, then read the data stream. So far I can't even log in. So instead of wasting days trying to figure it out I am hoping someone will help.

Code: Select all

   put fld "fldipurl" into IPURL
   put fld "fldusername" into PiUserName
   Put fld "fldpassword" into PiPassword
   put empty into fld"fldData"
   
   put "ssh " && PiUserName & "@" &IPURL && return & "" into tCommand
   put tCommand into fld "fldData"
   put shell (tCommand) 
   put the result after fld "fldData"
   get shell("password:")
   wait for 5 seconds
   put PiPassword & return &"" into tCommand
   put tCommand after fld "fldData"
   put shell (tCommand) 
   put the result after fld "fldData"
   wait 3 seconds
   put "sudo rtl_433 -M utc -F json -G" && return & "" into tCommand
   put tCommand after fld "fldData"
   get shell (tCommand) 
   put the result after fld "fldData"
   
   get shell(tCommand)
   put tCommand after fld "fldData"
(code is more or less what I have been trying, parts have been added and removed)
Seems it would be simple, Pass the "ssh pi@raspberrypi.local" wait for ":" after password, then send password. Wait a few seconds then issue my command, then read results..

Know someone has done this..

Thanks for any help or hints.
~David

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6677
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Access Raspberry Pi to read data.

Post by FourthWorld » Wed May 01, 2019 7:02 pm

The Linux expect command can be used for that.
http://www.admin-magazine.com/Articles/ ... ct-Scripts

But I don't recommend it unless no alternative exists.
https://www.ibm.com/developerworks/comm ... 10?lang=en

It may be simpler to add your shell call to sudoers, specifying the privilege escalation there. This can be a good solution if you're calling it from a limited set of client machines using shared SSH keys, and if the range of things you want to do on the Pi is limited.

If you may want to add other capabilities down the road, or access those capabilities from machines where it may not be practical to share SSH keys, you might consider an HTTP-based API to trigger that. These days it seems most IoT work is done with HTTP, and given its request-reply nature it seems a good fit for this problem.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Sat Apr 02, 2011 4:06 pm

Re: Access Raspberry Pi to read data.

Post by revRider » Thu May 02, 2019 1:44 am

NEWBE!

Pretty good at using Livecode to execute AppleScript and Microsoft ShellScripts.. And I've been using Raspberry Pi's for a few years.. But that was over my head.. <lol>

Thanks

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 310
Joined: Tue Apr 10, 2012 9:18 am

Re: Access Raspberry Pi to read data.

Post by ghettocottage » Thu May 02, 2019 4:55 am

using ssh keys for password-less login might make things easier. Can you do that?

if you had ssh keys set up on your pi and your work machine, you could maybe just write a bash script that does everything you want and trigger that script from livecode.

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Sat Apr 02, 2011 4:06 pm

Re: Access Raspberry Pi to read data.

Post by revRider » Thu May 02, 2019 5:48 pm

Had considered setting up a password-less raspberry pi.. But unsure if that would get me closer to reading streaming data coming from pi..

Raspberry Pi isn't as straightforward as Apple scripting. IMO.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6677
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Access Raspberry Pi to read data.

Post by FourthWorld » Thu May 02, 2019 6:10 pm

Is the Pi's networking restricted to the local network, or open to the Internet?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Sat Apr 02, 2011 4:06 pm

Re: Access Raspberry Pi to read data.

Post by revRider » Thu May 02, 2019 9:30 pm

The goal is to collect data from a raspberry pi, on a local network, by another computer on network, that will parse the data to be displayed on a web page.

Weather data, door switch status, light sensors, and motion sensors.. (monitored by the Raspberry Pi).

Just normal everyday stuff.. <smile>

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6677
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Access Raspberry Pi to read data.

Post by FourthWorld » Thu May 02, 2019 10:09 pm

The web page is also available only locally?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 310
Joined: Tue Apr 10, 2012 9:18 am

Re: Access Raspberry Pi to read data.

Post by ghettocottage » Thu May 02, 2019 11:51 pm

..another question: how is the data gathered on the pi? Is it stored/updated in a text-file or database, or do you request it each time you need it?

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Sat Apr 02, 2011 4:06 pm

Re: Access Raspberry Pi to read data.

Post by revRider » Fri May 03, 2019 9:28 pm

Using a couple of Acu-Rite 5-in-1 weather stations to post data on Weather Underground.. Would like to also display the data on our own website using a raspberry pi running WeeWx and RTL-433. RTL-433 and a usb SDR receiver captures the data sent from weather station.. The data is just parsed locally on Pi and displayed in a data stream.. This is done though a terminal SSH connection. Issue a command "rtl_433 -M utc -F json -G" (more or less)... .. I'd like to connect to the pi from a Livecode program that'll log into the pi, issue the rtl-433 command and start capture of the data it receives.. The parse and display on web page..

I can issue the ssh and start the login, but password is an issue.. I tried to do a password-less setup, but hosed the PI..

tried to attach photo, but size limits (tried three different sizes).

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 310
Joined: Tue Apr 10, 2012 9:18 am

Re: Access Raspberry Pi to read data.

Post by ghettocottage » Fri May 03, 2019 10:02 pm

Using ssh keys is going to make things much easier.

If you can generate a pair of keys on your work computer, you can then just place the contents of the .pub key into a file on the pi called authorized_keys
It should live in the .ssh folder of whatever user you have set up on the pi, like:

/home/PiUserName/.ssh/authorized_keys

you should then be able to login from your work computer. You might have to adjust the permissions of that folder like this:

chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys

SparkOut
Posts: 1948
Joined: Sun Sep 23, 2007 4:58 pm

Re: Access Raspberry Pi to read data.

Post by SparkOut » Fri May 03, 2019 10:20 pm

You may alternatively/additionally find that using "open process" is a possible solution.
You could potentially then "write <the commands you need to send> to process tThePiConsole" (pseudo)
When I get a chance (maybe 2027) I will have a test here and see if I can get any results to pass on. But don't hold your breath, I'm badly under the cosh.

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Sat Apr 02, 2011 4:06 pm

Re: Access Raspberry Pi to read data.

Post by revRider » Sat May 04, 2019 7:41 pm

Ok.. rebuilt the Raspberry PI and got RTL-433 working again...

Logged in manually as pi/raspberry.. Then issued command sudo rtl_433 -G with the resulting data. The data I wish to capture, parse and then share over the network. Can do everything, except log into Pi to issue the commands..

~David

Code: Select all

pi@weatherpi:~ $ sudo rtl_433 -G
rtl_433 version 18.12-204-gb1b62f2 branch master at 201905030920 inputs file rtl_tcp RTL-SDR
Trying conf file at "rtl_433.conf"...
Trying conf file at "/root/.config/rtl_433/rtl_433.conf"...
Trying conf file at "/usr/local/etc/rtl_433/rtl_433.conf"...
Trying conf file at "/etc/rtl_433/rtl_433.conf"...

	Consider using "-M newmodel" to transition to new model keys. This will become the default someday.
	A table of changes and discussion is at https://github.com/merbanan/rtl_433/pull/986.

Registered 119 out of 125 device decoding protocols [ 1-4 6-8 10-17 19-26 29-64 67-125 ]
Detached kernel driver
Found Rafael Micro R820T tuner
Exact sample rate is: 250000.000414 Hz
[R82XX] PLL not locked!
Sample rate set to 250000 S/s.
Tuner gain set to Auto.
Tuned to 433.920MHz.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
time      : 2019-05-04 13:35:15
model     : Acurite tower sensor                   id        : 2766
sensor_id : 0x0ace       channel   : A             Temperature: 21.0 C       Humidity  : 50            battery_low: 0
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
time      : 2019-05-04 13:35:15
model     : Acurite tower sensor                   id        : 2766
sensor_id : 0x0ace       channel   : A             Temperature: 21.0 C       Humidity  : 50            battery_low: 0
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
time      : 2019-05-04 13:35:15
model     : Acurite tower sensor                   id        : 2766
sensor_id : 0x0ace       channel   : A             Temperature: 21.0 C       Humidity  : 50            battery_low: 0
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
time      : 2019-05-04 13:35:17
model     : Acurite 5n1 sensor                     sensor_id : 3818          channel   : A             sequence_num: 0
battery   : OK           message_type: 49          wind_speed: 0.0 km/h      wind_dir_deg: 225.0       Rainfall Accumulation: 5.88 in
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
time      : 2019-05-04 13:35:17
model     : Acurite 5n1 sensor                     sensor_id : 3818          channel   : A             sequence_num: 1
battery   : OK           message_type: 49          wind_speed: 0.0 km/h      wind_dir_deg: 225.0       Rainfall Accumulation: 5.88 in
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
time      : 2019-05-04 13:35:17
model     : Acurite 5n1 sensor                     sensor_id : 3818          channel   : A             sequence_num: 2
battery   : OK           message_type: 49          wind_speed: 0.0 km/h      wind_dir_deg: 225.0       Rainfall Accumulation: 5.88 in
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
time      : 2019-05-04 13:35:19
model     : Acurite Lightning 6045M                id        : 253
channel   : A            temperature: 68.3 F       humidity  : 47            strike_count: 42          storm_distance: 7
active_mode: 1           rfi_detect: 0             unk_status1: 1            battery   : OK            data_exception: 0
raw_message: c0fd6fafd187aa4724
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 310
Joined: Tue Apr 10, 2012 9:18 am

Re: Access Raspberry Pi to read data.

Post by ghettocottage » Sat May 04, 2019 10:28 pm

What OS is the webserver running that will display the data?

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Sat Apr 02, 2011 4:06 pm

Re: Access Raspberry Pi to read data.

Post by revRider » Sun May 05, 2019 1:40 am

To start it'll be on our own Mac Server, Running Apache, PHP and LiveCode Server.

Hopefully the end result/code will be executable on anything LiveCode Apps (computer) run on.

Fill In: Raspberry Pi IP or hostname of PI running RTL-433,
Fill in: Username for SSH Login:
Fill In: password to PI

(Can't the above to work as a script to log in and start data capture)

Will store output in folder where program is located.. SO in the web folder. From there php will be able to read the data.

Basic idea at this point..

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”