Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I used remote.it to connect pi. #1633

Open
ddmakadia1699 opened this issue Feb 28, 2020 · 2 comments
Open

I used remote.it to connect pi. #1633

ddmakadia1699 opened this issue Feb 28, 2020 · 2 comments

Comments

@ddmakadia1699
Copy link

ddmakadia1699 commented Feb 28, 2020

used remote.it to connect my pi remotely. Now I used API to connect using python. But Now I am not able to send command to execute.

Can any one suggest me how to send command to execute which is present in pi.

Authentication

import requests
import json
import paramiko

Authentication

REMOTEIT_DEVELOPER_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
REMOTEIT_USERNAME="xxxxxxxxxxxxxxxxxxxxxxx"
REMOTEIT_PASSWORD="xxxxxxxxxxxxxxxxxxx"

headers = {
"developerkey": REMOTEIT_DEVELOPER_KEY
}
body = {
"password": REMOTEIT_PASSWORD,
"username": REMOTEIT_USERNAME
}

url = "https://api.remot3.it/apv/v27/user/login"

response = requests.post(url, data=json.dumps(body), headers=headers)
response_body = response.json()

print("Status Code: %s" % response.status_code)
print("Raw Response: %s" % response.raw)
print("Body: %s" % response_body)
REMOTEIT_TOKEN = response_body['token']
print(REMOTEIT_TOKEN)

List Device

headers = {
"developerkey": REMOTEIT_DEVELOPER_KEY,
# Created using the login API
"token": REMOTEIT_TOKEN
}

url = "https://api.remot3.it/apv/v27/device/list/all"

response = requests.get(url, headers=headers)
response_body = response.json()

print("Status Code: %s" % response.status_code)
print("Raw Response: %s" % response.raw)
print("Body: %s" % response_body)
print(response_body['devices'][2]['deviceaddress'])

DEVICE_ADDRESS = response_body['devices'][2]['deviceaddress']
MY_PUBLIC_IP = "0.0.0.0"

Connect Device

headers = {
"developerkey": REMOTEIT_DEVELOPER_KEY,
# Created using the login API
"token": REMOTEIT_TOKEN
}
body = {
"deviceaddress": DEVICE_ADDRESS,
"wait":"true",
"hostip": MY_PUBLIC_IP
}

url = "https://api.remot3.it/apv/v27/device/connect"

response = requests.post(url, data=json.dumps(body), headers=headers)
response_body = response.json()

print("Status Code: %s" % response.status_code)
print("Raw Response: %s" % response.raw)
print("Body: %s" % response_body)
print(response_body['connectionid'])
CONNECTION_ID = response_body['connectionid']

"""

Treaminating Connection

headers = {
"developerkey": REMOTEIT_DEVELOPER_KEY,
# Created using the login API
"token": REMOTEIT_TOKEN
}
body = {
"deviceaddress": DEVICE_ADDRESS,
"connectionid": CONNECTION_ID
}

url = "https://api.remot3.it/apv/v27/device/connect/stop"

response = requests.post(url, data=json.dumps(body), headers=headers)
response_body1 = response.json()

print("Status Code: %s" % response.status_code)
print("Raw Response: %s" % response.raw)
print("Body: %s" % response_body1)
"""

ip = response_body['connection']['proxyserver']
port1 = response_body['connection']['proxyport']
print(ip)
print(port1)

#port1 = "38417"
#ip = "192.168.0.164"

user_name = "pi"
passwd = "raspberry"

ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#ssh_client.connect(hostname=ip,username=user_name,password=passwd)
ssh_client.connect(hostname=ip,port=port1,username=user_name,password=passwd)

cmd = "sh date.sh"
stdin,stdout,stderr=ssh_client.exec_command(cmd)
stdout=stdout.readlines()
print(stdout)

Just want to execute cmd = "sh date.sh", which is on pi.

@ivanubi
Copy link

ivanubi commented Feb 29, 2020

You said what you wanted to do, that's okay, but it would be helpful if you point the issue. What's not working?

@ddmakadia1699
Copy link
Author

You said what you wanted to do, that's okay, but it would be helpful if you point the issue. What's not working?

How to execute command ?
Like, we can execute command on terminal, (uname --> output : Linux)
Same I want to execute command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants