Send bash commands from Arduino?

Perhaps this cannot be done as seemingly evidenced by my Google searches for the subject line and 99.9 percent of the results assume I'm trying to send commands from the host computer to an Arduino. Hence why I'm asking for guidance.
My weather project is sending serial data using the Adafruit Feather 32u4 and my receiver is successfully getting this data while hooked up via USB to my OS X machine.

I'm using this data to build a char * to build up a command that should run on this OS X machine. Along the lines of:

"curl localhost -D {"wind speed": "7.0" ..."
Why do it this way? My goal is to get this serial data into my Postgresql database running on OS X. I've built a rudimentary web app that accepts POST calls with the data.

But I don't have to do it this way, it's just the way I know of to get data into OS X. What other ways would you suggest?

Some of the posts I've found suggest setting up a Serial interface with the host computer. Their instructions assume going from computer to Arduino but unsure how the Arduino will be aware. Perhaps since the Feather is attached to this computer, there is a way already?

Looking for guidance on how to get data into Postgresql, sam

My weather project is sending serial data using the Adafruit Feather 32u4 and my receiver is successfully getting this data while hooked up via USB to my OS X machine.

I don’t understand your setup yet. Is the Feather connected directly to your OS X machine? What’s your “receiver”?

I’m using this data to build a char * to build up a command that should run on this OS X machine.

What kind of program is doing that? As you mention “char *” it sounds like C or C++. Why not directly connecting to the web service then without using “curl”?

Some of the posts I’ve found suggest setting up a Serial interface with the host computer.

I would have expected that you already did that. Am I right?

Looking for guidance on how to get data into Postgresql

If the database is running on the same machine (you didn’t specify), you could feed the data into it without the detour of using a web service. Just use the postgresql libs within that mystic program you run on the Mac and store the data directly.

The Feather that is transmitting has a Serial connection from a Raspberry Pi.
The Feather that is receiving so far does not have a Serial connection to OS X but it does have a USB connection.

The receiver Feather is taking this data that was transmitted and I'm building a char * command that I hope to push to the OS X computer since it has the capability to access my postgresql db and Net tools like http and curl.

Can I use this USB connection to push a bash command to OS X?

No, the Arduino hooked up to a USB can't make the computer it's hooked to do anything. The best you could do would be to write a program to run on that computer that listens to the Arduino over a Serial line and takes actions based on what the Arduino says to it. The Arduino can just send messages and you can write code to do whatever you want in response to one of those messages. It can't be used to send commands in the sense that you are trying to.

Post a link to that Feather you're using! There are a ton of versions all named Adafruit Feather!

If your Feather has a native USB port (e.g. 32U4 based), it should be able to act as a HID sending keystrokes to the PC (like a keyboard).

Not familiar with Feather though.

If your Feather has a native USB port (e.g. 32U4 based), it should be able to act as a HID sending keystrokes to the PC (like a keyboard).

That's true but that would just type anything to the currently active program he's running on his Mac, which even might be the screensaver. How would you ensure that the keystrokes always hit a terminal window?

pylon:
That's true but that would just type anything to the currently active program he's running on his Mac, which even might be the screensaver. How would you ensure that the keystrokes always hit a terminal window?

You don't actually need a terminal window, what you need is a shell running on the virtual serial port that is connected to the Arduino.
There are several ways to do this.

--- bill

sam452:
The Feather that is transmitting has a Serial connection from a Raspberry Pi.

Why can't you use the Raspberry Pi to make the requests? Or even run the database server on the Pi, for that matter?

If you insist on having the Feather initiate cURL requests on the Mac, one approach could be to have a python script running that takes input from the Arduino over USB (virtual COM, using the "Serial" object). You can then use python to make the HTTP request.

If that doesn't work out, you could use the Keyboard libraries, add a shortcut to launch a terminal, and then type the commands and hit enter. But that's just a bodge. You have no way of knowing if it actually opened a terminal, and if the commands executed successfully.

A third method would be to give the Feather internet access, using SLIP (Serial Line Internet Protocol), but you're probably going to have a hard time getting that working on Mac.

Using an ESP8266 would be much easier than using SLIP, it can just replace the Feather. You can program it like any normal Arduino, and it has WiFi, so it can directly make the requests to the server.

Pieter

The Pi is controlling the sensors. The first phase of this project used to store onboard its Postgresql database. But because this is remote, the Feather can reach beyond the trees and distance that wifi with directional antenna can reach. No need to beat that horse as I’ve spent over a year doing all I could to keep a wifi connection up and the Feather is able to pass data to a server that is more likely to stay up.

Let’s talk about the virtual serial port. Google brought up this link.

It’s unclear what’s to be done from the OS X side.

I wonder if this is any help on the OS X side? https://playground.arduino.cc/Interfacing/LinuxTTY

Thx for considering this, sam

By virtual serial / COM port, I mean the Serial port that is detected by the computer when you plug in an Arduino. (The one you use when using "Serial.print()" and the Serial monitor etc.)
It has nothing to do with SoftwareSerial.

It's just a serial communication line that allows you to send bytes of data from and to the computer. What kind of data you send, and what protocol you use is completely up to you.

Serial Input Basics
Arduino Python Demo

Your setup is not entirely clear to me, how do the Pi and the Feather communicate?

Pieter

pylon:
That's true but that would just type anything to the currently active program he's running on his Mac, which even might be the screensaver. How would you ensure that the keystrokes always hit a terminal window?

One also doesn't type bash commands in a screen saver :wink: And who knows; maybe OP runs a console only Linux system with a single TTY.

sam452:
It's unclear what's to be done from the OS X side.

You write an application :slight_smile: I have never used a MAC and I haven't touched a Linux for several years nor do I have experience with postgres.

The application

reads the serial port
2)
parses the received data
3)
inserts into the database

The language can be your favorite language or one for which you can easily find examples.

You can use AppleScript

This is very helpful. If I can read the tty that the Feather is using I'll write an application to do as sterretje and Grumpy_Mike suggest.
If I can get it past the "Resource busy" response, that's what I'll do, thx, sam

The "resource busy" might be caused by the IDE/serial monitor (or any other terminal program) that is currently using the same serial port.