how can I make it to split arduino data with raspberry pi 3b + and send them to thingspeak

0

I want to send data from 3 sensors to Thingspeak using RPi3B + and arduino for ADC conversion using Phyton, how can I get Phyton to divide or concatenate each data in a separate Field so that thingspeak can graph them to me. Thanks

import serial
import time
import sys
import RPi.GPIO as GPIO
import os
import time
import http.client, urllib

from time import sleep

arduino = serial.Serial("/dev/ttyACM0", baudrate=9600, timeout=3.0)

while True:
    val = arduino.readline()
    print(val)
    if val:
      print('CO: {0:0.1f} ppm CO2; {1:0.1f} ppm'.format(val[2], val[3]))
      params = urllib.parse.urlencode({'field3': val[2],'field4': val[3], 
'key':'IQDXSILZL6RI8ONP'})
  headers = {"Content-typZZe": "application/x-www-form-urlencoded","Accept": "text/plain"}
  conn = http.client.HTTPConnection("api.thingspeak.com:80")
  try:
   conn.request("POST", "/update", params, headers)
   response = conn.getresponse()
   print(response.status, response.reason)
   data = response.read()
   conn.close()
  except:
   print("connection failed")
  sleep(2)
else:
  print('Failed to get result !'); 

arduino.close()
    
asked by alexis valderrama 18.10.2018 в 04:54
source

0 answers