0

I am working on making POST REST API statements to a thingworx server my source code as is follows and the picture is the response i get back. Can someone explain what i did wrong and what would also be the proper way to do this in a C/C++ environment?

Source Code:

import RPi . GPIO as GPIO
import time
import requests 
import json
from picamera import PICamera

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN)

camera = Picamera()
url = ‘https://academic-educatorsextension.portal.ptc.io’
headers = { ‘Content-Type’: application/json’, appKey’: ‘077c9a51-c690-4d2a-9254-3568cb0ee6bd’}
payload = {‘Detection’: ‘True’}

i=0

while True:

    i+=1
    state = GPIO.input(11)
    if state = == 0:
        print “we’re clear”
        time.sleep(5)
    elif state == 1:
        print “stop Right There!”
        camera.capture(‘/home/pi/PIR/pics/image{0:04d}.jpg’.format(i))
        response = requests.put(url + ‘/Things/Motion sensor_Coldsteel85/*’,headers=headers, json = payload, verify = False)
        time.sleep(5)

Response

1 Answers1

0

Since you are sending data over https, you should sign your request with a self-signed certificate. Refer the below thread on how to do this via python:

Unni Kris
  • 3,081
  • 4
  • 35
  • 57
  • I am still not sure how i would do this regarding the Thingworx server if you have any more information it would be greatly appreciated – Trap Chavez Apr 16 '18 at 14:31
  • Refer this link to create a self-signed certificate : https://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl – Unni Kris Apr 17 '18 at 03:30