Page 1 of 1

Using json commands in combination with an username and password

Posted: Friday 22 June 2018 0:41
by joran
I'm trying to update an uservariable or counter with a json command, but there is a problem I'm getting an error. The goal is reading serial data from an other device trough USB and sending this data to Domoticz. And all of this using one python script.

First things first, I'm using a RaspberryPi 3 with Domoticz version 3.8153. And Raspbian version: 4.14.34-v7.
This is my server.

I'm sending from another Pi same type en Raspian version.
Using this script:

Code: Select all

#!/usr/bin/python

import serial
import urllib2
ser = serial.Serial('/dev/ttyACM0',9600)
read_serial=ser.readline()
serverIP = "10.0.0.8:8080"
deviceId = 126

try:
  urllib2.urlopen("http://" + serverIP + "/json.htm?type=command&param=udevice&idx=" + str(deviceId) + "&svalue=" + str(read_serial), timeout=1)
  print "Data sent!"
except:
  print "Error"
The problem is that I am using a username and password to login on Domoticz so it does not work.
I have tried the suggestion on the wiki.

http://<username:password@>domoticz-ip<:port>/json.htm?api-call
http://<username:password@>domoticz-ip<:port>/json.htm?api-call (username and password encoded using base64)
http://domoticz-ip<:port>/json.htm?username=MkE=&password=OVM=&api-call (username and password encoded using base64)

Not one of these work for me. Most of them give the error 401 Unauthorized. I tried using the curl command and pasting the url in my webbrowser google chrome.

Help would be appreciated. :)

Edit:
I think that I found the problem with the json commands. I made a separate user for sending the json commands, that was the problem. Apparently you have to use the credentials that are in the settings menu under website protection (see picture).
Image

Re: Using json commands in combination with an username and password

Posted: Friday 22 June 2018 4:34
by Dnpwwo
@joran,

Sounds like you should be creating a python plugin for this, have a look at this example (*https://github.com/domoticz/domoticz/bl ... s/RAVEn.py) to see how to read from the serial port and update counters.

Re: Using json commands in combination with an username and password

Posted: Friday 22 June 2018 18:48
by joran
@Dnpwwo

Thank you for the reply, the python plugin will be a good solution. But this will cost me a lot of time to figure out.
I will be doing that but for now I'm looking for a way to control counters an variables with a json command.
There has to be a way to make that work right? I know that people are using more or less the same way of communicating for the ESPeasy futures.
Any idea why it isn't working for me? Or are there more people who have had the same issue?