ntfy icon indicating copy to clipboard operation
ntfy copied to clipboard

CLI on Termux (Android) fails to connect

Open goodevilgenius opened this issue 2 years ago • 11 comments

I compiled the cli under Termux (the precompiled binaries didn't work). Compilation worked, but pub/sub doesn't work.

Here's compilation output:

$ make cli-client
mkdir -p server/docs server/site
touch server/docs/index.html server/site/app.html
# This is a target to build the CLI (excluding the server) manually. This should work on Linux/macOS/Windows.
# Use this for development, if you really don't want to install GoReleaser ...
mkdir -p dist/ntfy_client server/docs
CGO_ENABLED=0 go build \
        -o dist/ntfy_client/ntfy \
        -tags noserver \
        -ldflags \
        "-X main.version=v1.27.2 -X main.commit=69d6cdd -X main.date=1656031518"
go: downloading github.com/urfave/cli/v2 v2.10.2
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/gabriel-vasile/mimetype v1.4.0
go: downloading github.com/olebedev/when v0.0.0-20211212231525-59bd4edcf9d6
go: downloading golang.org/x/term v0.0.0-20220526004731-065cf7ba2467
go: downloading golang.org/x/time v0.0.0-20220609170525-579cf78fd858
go: downloading golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664
go: downloading github.com/AlekSi/pointer v1.2.0
go: downloading github.com/pkg/errors v0.9.1
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/BurntSushi/toml v1.1.0
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.2
go: downloading github.com/russross/blackfriday/v2 v2.1.0
go: downloading golang.org/x/net v0.0.0-20220622184535-263ec571b305

Here's output of a pub command:

$ ./dist/ntfy_client/ntfy pub dan000-tests
Post "https://ntfy.sh/dan000-tests": dial tcp: lookup ntfy.sh on [::1]:53: read udp [::1]:59557->[::1]:53: read: connection refused

Similar output for sub command. Adding -d and --trace didn't add any extra output.

curl works fine, however.

goodevilgenius avatar Jun 24 '22 01:06 goodevilgenius

I just compiled ntfy-client on my phone inside Termux, and it worked just fine. This is what I did:

pkg install git
pkg install golang
pkg install make
git clone https://github.com/binwiederhier/ntfy
cd ntfy
make cli-client
./dist/ntfy_client/ntfy pub dan000-tests

What version of golang are you using? I have go1.18.3

wunter8 avatar Jun 29 '22 03:06 wunter8

Looks like this is somehow a limitation of my device, although I'm not really sure how.

I updated go to 1.18.3, and tried everything again. I even deleted all the packages from ~/go/pkg first, and did it all again. Same result.

This was on my tablet: an Amazon Fire.

I switched to my phone, a Samsung Galaxy, and tried there. Worked first time, no problem.

I then tried copying the binary from my phone to my tablet. That binary that worked fine on my phone failed in the same way on my tablet.

It seems weird, since other programs, like curl, work fine.

goodevilgenius avatar Jun 29 '22 15:06 goodevilgenius

Hmm, that does seem strange. Unfortunately, I don't have an Amazon Fire I could test with myself

wunter8 avatar Jun 29 '22 15:06 wunter8

The same for me. I compiled ntfy in Termux on a OnePlus 7 (Android 11). On the device itself I get the same error message as described above.

However, if I copy the binary into Termux on my Galaxy Tab S3 (Android 8), it works flawlessly there.

steff75 avatar Jul 03 '22 13:07 steff75

Dumb question: Why are so many people using the ntfy CLI on a phone? What use case am I missing?

binwiederhier avatar Jul 03 '22 13:07 binwiederhier

Because you can ;-) Actually, I tested it only out of curiosity. Normally I get along with Tasker http requests to publish something.

steff75 avatar Jul 03 '22 14:07 steff75

Why are so many people using the ntfy CLI on a phone?

@binwiederhier I had an idea to automate some stuff on my home computer, by subscribing to a specific topic. I send commands to my computer from my phone. I send them via Tasker, no problem, but I want to be able to get feedback back from my computer to my phone.

So, before I send the notification, I subscribe to a custom channel that I wait for feedback on within Termux. A custom script that runs on my computer will read the command sent through ntfy via Tasker, do something on my computer, and then send a new notification with output from the command. Having subscribed to this notification in Termux, a script is run that writes the output to a file on my phone, and/or creates a new notification.

It looks like this

graph TD;
    phone(Phone)-- send command via Tasker -->ntfy
    ntfy-->comp(Computer)
    comp-- ntfy sub -->com(command)
    com-- send output -->ntfy
    ntfy-- ntfy sub - in Termux -->phone
    phone-- send notification to self -->phone

I haven't actually implemented all of this. I'm not sure I have a definite use case for it yet. It's just an idea I had.

goodevilgenius avatar Jul 05 '22 14:07 goodevilgenius

I feeel like I understand what you are doing there (you want to execute commands on your computer and get output/feedback), and I believe you can do that without the ntfy CLI on the phone.

  • You subscribe to ntfy.sh/result on your phone and MUTE the subscription
  • You subscribe to ntfy.sh/command on your computer (via ntfy CLI, executing somescript.sh when commands come in)
  • You now publish a command to ntfy.sh/command
  • Your computer's ntfy CLI executes somescript.sh and publishes the response to ntfy.sh/result
  • Your phone receives the notification on ntfy.sh/result and broadcasts it as Android intent
  • Tasker/MacroDroid receives the intent and does whatever with it

(Side note: super cool diagram. Didn't know GitHub can do that!)

binwiederhier avatar Jul 05 '22 14:07 binwiederhier

I have something set up similar to what binwiederhier described, and it's working great! I didn't know that messages are still broadcast even if the subscription is muted, though! That's cool

wunter8 avatar Jul 05 '22 15:07 wunter8

(Side note: super cool diagram. Didn't know GitHub can do that!)

I believe this is Mermaid. I didn't know GitHub supported it, but it's really powerful.

lilithium-hydride avatar Jul 15 '22 00:07 lilithium-hydride

It is Mermaid. GitHub has supported it since February.

Although, I really should've used a Sequence Diagram instead of a flowchart.

goodevilgenius avatar Jul 15 '22 14:07 goodevilgenius

Closed due to inactivity. Happy to reopen if people still have issues.

binwiederhier avatar Nov 19 '22 20:11 binwiederhier