Help with simple local application

I’m trying to make a simple script that connects to my Lovense Remote on the same lan and then start vibrating the connected toy.

I tried this with the app and the correct IP and 20010 and I tried with the dongle in in a computer using 127-0-0-1.lovense.club an port 30010.

I’m just getting errors and I have not been able to get any response from the Lovense Remote app.

I also tried simple HTTP POST requests like https://127-0-0-1.lovense.club:30010/GetToys from Postman, but it’s not getting a response.

The script I’m trying with now is this:

// Define the IP address and port of the Lovense device
const lovenseIP = ‘192.168.1.94’;
const lovensePort = 30010; // Default port for Lovense Local API

// Define the endpoint and parameters for the command
const endpoint = ‘/GetToys’;

// Construct the full URL
const url = http://${lovenseIP}:${lovensePort}${endpoint};

// Send the HTTP GET request to the Lovense device
fetch(url, {
method: ‘POST’
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ’ + response.statusText);
}
return response.text(); // Change to text to handle non-JSON responses
})
.then(data => {
console.log(‘Success:’, data);
})
.catch(error => {
console.error(‘There was a problem with the fetch operation:’, error);
});

Could someone help me form a simple script that starts vibration on a toy?

1 Like

It seems you misinterpreted API described in https://developer.lovense.com/docs/standard-solutions/standard-api.html#by-local-application

The URL of request should be "http://192.168.1.94:20010/command" (or alternatively "https://192.168.1.94:30010/command" if you want to use SSL, but in such case it might fail on SSL certificate validation, so try without SSL first), and the body should contain JSON of your request ‘{ “command”: “GetToys” }’

I am not JavaScript guy, I only tested it in bash with curl - and following worked for me just fine:

curl -X POST -H 'Content-Type: application/json' -H 'X-platform: TestApp' -d '{ "command": "GetToys" }' http://192.168.1.94:20010/command

Perhaps the corresponding JS fetch function should look like (just guessing without trying it):

fetch("http://192.168.1.94:20010/command", {
  method: "POST",
  body: JSON.stringify({
    command: "GetToys"
  }),
  headers: {
    "Content-type": "application/json",
    "X-platform": "TestApp"
  }
});
1 Like

Thanks for the reply.

I messed around with a quite a bit and the problem seems to be connection to the app via the IP:PORT.

I tried your curl command and got:
curl: (7) Failed to connect to 192.168.1.24 port 20010 after 2498 ms: Couldn't connect to server

I can ping the IP, but when I do nmap -p 20010 192.168.1.24 with the app open I get:

nmap -p 20010 192.168.1.24
Starting Nmap 7.95 ( https://nmap.org ) at 2024-07-20 17:49 Rom, sommertid
Nmap scan report for xxx-Galaxy-S10 (192.168.1.24)
Host is up (0.023s latency).

PORT      STATE  SERVICE
20010/tcp closed unknown
MAC Address: xx:xx:xx:xx:xx:xx(Unknown)

Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds

Firewall is off.

What could be stopping my request from getting through?

1 Like

I had no idea (that’s why no answer from me for long time), just now I got one: Check your WiFi settings. If you have so called “isolation” enabled (depending on your WiFi router/AP it might be called “AP isolation” or “client isolation” or similar), then wireless clients cannot make direct connection to each other (they can only make connection to outside internet). Sometimes this is enforced on “guest-WiFi” (if you have that enabled) and maybe you don’t even see such isolation option in router settings, in such case try to use primary wireless instead of guest one.
It’s just an idea, I do not know what your network environment is. As long as the Lovense Remote application in my phone is in Game Mode, it is listening on those 2 ports (one plain and one SSL), so I believe issue is somewhere in your networking.

By default the IP blocks ping probes, try this instead:
nmap -Pn 20010 192.168.1.24