Using json commands in combination with an username and password Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
joran
Posts: 7
Joined: Friday 22 June 2018 0:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

Using json commands in combination with an username and password

Post 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
Last edited by joran on Saturday 23 June 2018 17:24, edited 1 time in total.
User avatar
Dnpwwo
Posts: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

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

Post 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.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
joran
Posts: 7
Joined: Friday 22 June 2018 0:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

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

Post 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?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests