initial version
This commit is contained in:
57
bin/2graphite.py
Normal file
57
bin/2graphite.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import sys
|
||||
import serial_asyncio # Ensure this package is installed
|
||||
|
||||
def parse_to_graphite(data):
|
||||
results = []
|
||||
|
||||
lines = data.strip().split('\n')
|
||||
for line in lines:
|
||||
if line.startswith('>>>'):
|
||||
metric_path = line[3:].strip() # Remove the ">>>" prefix and any leading/trailing whitespace
|
||||
results.append(metric_path)
|
||||
return results
|
||||
|
||||
async def send_to_graphite(data, session, api_url):
|
||||
for message in data:
|
||||
#print(f"Sending data to API: {message}") # Debug message for sending data
|
||||
try:
|
||||
# Sending raw metric path directly as plain text
|
||||
headers = {'Content-Type': 'text/plain'}
|
||||
async with session.post(api_url, data=message, headers=headers) as response:
|
||||
if response.status != 200:
|
||||
print(f"Failed to send data: {response.status}", await response.text())
|
||||
except Exception as e:
|
||||
print(f"Error sending data: {e}")
|
||||
|
||||
async def handle_serial(reader, api_url):
|
||||
session = aiohttp.ClientSession()
|
||||
try:
|
||||
while True:
|
||||
line = await reader.readline()
|
||||
if not line:
|
||||
break
|
||||
line = line.decode('utf-8')
|
||||
print(line.strip()) # echo output for received line
|
||||
graphite_data = parse_to_graphite(line)
|
||||
if graphite_data:
|
||||
await send_to_graphite(graphite_data, session, api_url)
|
||||
finally:
|
||||
await session.close()
|
||||
|
||||
async def main():
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage: python script.py <serial_device> <api_url>")
|
||||
sys.exit(1)
|
||||
|
||||
serial_device = sys.argv[1]
|
||||
api_url = sys.argv[2]
|
||||
baud_rate = 115200 # You can modify this as needed
|
||||
|
||||
# Creating the connection to the serial port
|
||||
reader, _ = await serial_asyncio.open_serial_connection(url=serial_device, baudrate=baud_rate)
|
||||
await handle_serial(reader, api_url)
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
BIN
bin/boot_app0.bin
Normal file
BIN
bin/boot_app0.bin
Normal file
Binary file not shown.
BIN
bin/bootloader_qio_80m.bin
Normal file
BIN
bin/bootloader_qio_80m.bin
Normal file
Binary file not shown.
17
bin/build
Executable file
17
bin/build
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
if [ ! -d "Compiled" ] ; then mkdir Compiled ; fi
|
||||
|
||||
if [ "${DRONE_TAG}" ] ; then
|
||||
NAME=${DRONE_TAG}
|
||||
elif [ "${DRONE_BRANCH}" ] ; then
|
||||
NAME=${DRONE_BRANCH}-${DRONE_BUILD_NUMBER}
|
||||
else
|
||||
NAME=`git symbolic-ref --short HEAD`
|
||||
fi
|
||||
|
||||
echo "#define VERSION \"${NAME}\"" >> compile_flags.h
|
||||
arduino-cli compile $LIBS -e -b esp32:esp32:esp32 || exit 1
|
||||
mv build/esp32.esp32.esp32/*.ino.bin Compiled/${NAME}.bin
|
||||
mv build/esp32.esp32.esp32/*.ino.elf Compiled/${NAME}.elf
|
||||
mv build/esp32.esp32.esp32/*.ino.partitions.bin Compiled/${NAME}.partitions.bin
|
||||
bin/flash Compiled/${NAME}.bin
|
17
bin/flash
Executable file
17
bin/flash
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
BASENAME=${1%.bin};
|
||||
|
||||
esptool.py \
|
||||
-b 921600 \
|
||||
--chip esp32 \
|
||||
--before default_reset \
|
||||
--after hard_reset \
|
||||
write_flash \
|
||||
-z \
|
||||
--flash_mode dio \
|
||||
--flash_freq 80m \
|
||||
--flash_size detect \
|
||||
0x10000 $BASENAME.bin \
|
||||
0x8000 $BASENAME.partitions.bin \
|
||||
0xe000 bin/boot_app0.bin \
|
||||
0x1000 bin/bootloader_qio_80m.bin
|
Reference in New Issue
Block a user