You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
headers = {
"developerkey": REMOTEIT_DEVELOPER_KEY,
# Created using the login API
"token": REMOTEIT_TOKEN
}
body = {
"deviceaddress": DEVICE_ADDRESS,
"wait":"true",
"hostip": MY_PUBLIC_IP
}
headers = {
"developerkey": REMOTEIT_DEVELOPER_KEY,
# Created using the login API
"token": REMOTEIT_TOKEN
}
body = {
"deviceaddress": DEVICE_ADDRESS,
"connectionid": CONNECTION_ID
}
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.
The text was updated successfully, but these errors were encountered: