Sending command to UPS via USB

Hi,

I've purchased an UPS with USB port, and I would like to send one simple command to the UPS - to turn it off - using Arduino.
I know the UPS is using the megatec protocol (Network UPS Tools - Megatec Protocol information)
In the past I tried to send the command using Linux + Python + pyusb library, but no luck.
My second approach is to use Arduino, would that be possible?

Any help would be greatly appreciated.

Welcome to the forum

An Arduino can communicate using that protocol as it only involves sending and receiving a stream of bytes.

What you will need to do, however, is to use a TTL to RS232 interface between the two as without it they are electrically incompatible

Thank you.

If I understand correctly I cannot use Arduino's built-in USB port ?
And the solution would be to use somehing like that:

?

1 Like

The UPS devices I have purchased in the past with communication capability, came with PC software. Did you get any with your UPS?

Sure, but it is for Windows only.

TRue, but does that work? Then you know communication is possible. Right now you are guessing the UPS can hear the Arduino.

Looking at the PDF for the device you linked to shows it is NOT a host USB device, so it will NOT work to talk to your UPS. The adapter only talks to a host PC. Sorry.

Thank you, so I'll check if it works with WIndows first.

If the communication is possible can you provide me with a link to host USB device I could use with Arduino?

Yes, it is possible to use Arduino to send commands to the UPS using the Megatec protocol. To do this, you will need to use the Arduino's USB port to communicate with the UPS via USB.

To start, you will need to set up the Arduino board to communicate with the UPS using USB. This typically involves installing a USB library for the Arduino, such as the ArduinoUSB library.

Once you have set up the Arduino to communicate with the UPS via USB, you can use the Megatec protocol to send commands to the UPS. The Megatec protocol defines a set of commands and responses that can be used to control the UPS, such as turning it on or off, or querying its status.

To send a command to the UPS using the Megatec protocol, you will need to create a command packet according to the protocol specification and send it to the UPS via the Arduino's USB port.

For example, to turn the UPS off, you could send the following command packet:

0x00 0x00 0x00 0x00 0x00 0x06 0x01 0x00 0x00 0x00 0x00 0xB4

This command packet consists of 12 bytes, with the first 6 bytes representing the command and the remaining 6 bytes representing the checksum.

To receive a response from the UPS, you can use the Arduino's USB library to read data from the UPS via the USB port. The response packet will also be in the format specified by the Megatec protocol, and will contain information about the status of the UPS or the results of the command that you sent.

You should probably expand on this to identify which Arduino you are referring to as not all Arduino boards can do this.

1 Like

Thanks! That's impressive answer :slight_smile:
Will this work with plain Arduino Uno ?

And one more question regarding the command packet: where did you get it from?

According to the documentation (Network UPS Tools - Megatec Protocol information) the shutdown command is: S<n><cr>
where <n> is a number ranging form .2 , .3 , …, 01 , 02 , …, up to 10 .

?

I'm glad you found my previous answer helpful! To answer your first question, it's possible that the code I provided could work with an Arduino Uno, but it would depend on the specific implementation of the code and the hardware you're using. The Arduino Uno has limited processing power and memory compared to more recent boards, so you may need to make some adjustments to the code to get it to run properly on the Uno. Additionally, you'll need to make sure that the board has the necessary hardware to communicate with the UPS, such as a serial port or USB connection.

Regarding your second question, the command packet that I provided is based on the Network UPS Tools (NUT) protocol for communicating with UPS devices. NUT is an open-source project that provides a collection of drivers and tools for interacting with a wide variety of UPS devices from different manufacturers. The information about the Megatec protocol, which is used by some UPS devices, is included in the documentation for NUT. The command packet that I provided is for shutting down the UPS and is one of the command that is in NUT Megatec protocol. As you already pointed out , the S\r is the command format, where is a number that ranges from 0.2 to 10.

Please make sure you read the manual and safety measures of your UPS device before performing any shutdown operation.

The UNO would need a USB host shield in order to communicate with the UPS. You would need to check that the host shield library supports the class of USB device that the UPS identifies itself as.

1 Like

You are correct, an Arduino Uno alone would not have the capability to communicate with a USB-based UPS directly, as it does not have a USB host controller. To connect the Uno to a USB-based UPS, you would need to use a USB host shield, which would add a USB host controller to the board and allow it to communicate with the UPS over USB.

Additionally, you'll need to make sure that the library for the USB host shield supports the class of USB device that the UPS identifies itself as. The UPS should provide this information in its documentation, and you'll need to ensure that the library has the appropriate drivers to communicate with that device class.

Please make sure to check the compatibility of the shield, library and UPS compatibility before buying any component. It may save you some time and money.

1 Like

Thanks to all for your help.

I know that I want to talk with USB class 3 (HiD) interface.

Do you think following shield should be sufficient for that purpose ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.