vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Raspberry to ThingWorx

Thu Jun 15, 2017 5:17 am

Hi,
I am trying to send data from raspberry to thinworx but not getting connected. Please check the code below. Please help.

Code: Select all

import requests
import sys
import json
import time
import random
import subprocess


from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

thing = 'RaspberryPi'
url = 'http://192.168.1.25:8443/Thingworx'
appKey = '3923465c-7983-408c-bb88-9c7d407a61e7'
headers = { 'Content-Type': 'application/json', 'appKey': appKey }

while True:



  HostName = subprocess.check_output("hostname", shell=True)

  TotMem =  subprocess.check_output("free -m | awk '/Mem:/ { print $2 }'", shell=True)

  UsedMem =  subprocess.check_output("free -m | awk '/Mem:/ { print $3 }'", shell=True)


  print 'Hostname: ' + HostName
  print 'Total Memory: ' + TotMem
  print 'Used Memory: ' + UsedMem


  payload = { 'Total_Memory': TotMem, 'Used_Memory': UsedMem, 'Host_Name': HostName }

  response = requests.put(url + '/Things/RaspberryPi/Properties/*', headers=headers, json=payload, verify=False)


  time.sleep(1)
  print '========================='


Return to “Beginners”