Skip to content

Commit 49fa399

Browse files
cmaglieXayton
andauthored
Improved RPC support
Co-authored-by: Xayton <30591904+Xayton@users.noreply.github.com>
1 parent 71ea067 commit 49fa399

File tree

25 files changed

+4477
-15
lines changed

25 files changed

+4477
-15
lines changed

examples/python-blink/app.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: Python-Blinker 🎮
2+
description: An app showing how to blink an LED using Python.
3+
4+
module-dependencies:
5+
- arduino/mcu
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from arduino.app_bricks.mcu import call, register
2+
import time
3+
4+
#curr_led_state = False
5+
#@register()
6+
#def get_led_state():
7+
# global curr_led_state
8+
# curr_led_state = not curr_led_state
9+
# return curr_led_state
10+
11+
@call()
12+
def set_led(state: bool) -> bool:
13+
...
14+
15+
# Sleep to keep the RPC server alive
16+
print("waiting for requests...")
17+
while True:
18+
try:
19+
set_led(True)
20+
except Exception as e:
21+
pass
22+
time.sleep(1)
23+
try:
24+
set_led(False)
25+
except Exception as e:
26+
pass
27+
time.sleep(1)

examples/python-blink/python/requirements.txt

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Lucio Rossi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=Arduino_RPClite
2+
version=0.0.1
3+
author=Lucio Rossi (eigen-value)
4+
maintainer=Lucio Rossi (eigen-value)
5+
sentence=A MessagePack RPC library for Arduino
6+
paragraph=allows to create a client/server architecture using MessagePack as the serialization format. It follows the MessagePack-RPC protocol specification. It is designed to be lightweight and easy to use, making it suitable for embedded systems and IoT applications.
7+
category=Communication
8+
url=https://www.arduino.cc/
9+
architectures=*
10+
depends=ArxContainer (>=0.6.0), ArxTypeTraits, DebugLog (>=0.8.1)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Created by lucio on 4/8/25.
3+
//
4+
5+
#ifndef ARDUINO_RPCLITE_H
6+
#define ARDUINO_RPCLITE_H
7+
8+
#include "Arduino.h"
9+
10+
//#define HANDLE_RPC_ERRORS
11+
//#define DEBUG
12+
#include "rpc.h"
13+
#include "transport.h"
14+
#include "client.h"
15+
#include "server.h"
16+
#include "wrapper.h"
17+
#include "dispatcher.h"
18+
19+
#include "DummyTransport.h"
20+
#include "SerialTransport.h"
21+
22+
#endif //ARDUINO_RPCLITE_H
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Created by lucio on 4/8/25.
3+
//
4+
5+
#ifndef DUMMYTRANSPORT_H
6+
#define DUMMYTRANSPORT_H
7+
#include "transport.h"
8+
9+
class DummyTransport : public ITransport {
10+
std::vector<uint8_t> inbuf, outbuf;
11+
12+
public:
13+
size_t write(const uint8_t* data, size_t size) override {
14+
outbuf.insert(outbuf.end(), data, data + size);
15+
return size;
16+
}
17+
18+
size_t read(uint8_t* buffer, size_t size) override {
19+
if (inbuf.size() < size) return 0;
20+
std::copy(inbuf.begin(), inbuf.begin() + size, buffer);
21+
inbuf.erase(inbuf.begin(), inbuf.begin() + size);
22+
return size;
23+
}
24+
25+
size_t read_byte(uint8_t& r) override {
26+
uint8_t b[1];
27+
if (read(b, 1) != 1){
28+
return 0;
29+
};
30+
r = b[0];
31+
return 1;
32+
}
33+
34+
void push_data(const std::vector<uint8_t>& data) { inbuf.insert(inbuf.end(), data.begin(), data.end()); }
35+
const std::vector<uint8_t>& get_output() const { return outbuf; }
36+
};
37+
38+
#endif //DUMMYTRANSPORT_H
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
#ifndef HT_SERIAL_MSGPACK_H
3+
#define HT_SERIAL_MSGPACK_H
4+
5+
#include <DebugLog.h>
6+
#ifdef MSGPACK_DEBUGLOG_ENABLE
7+
#include <DebugLogEnable.h>
8+
#else
9+
#include <DebugLogDisable.h>
10+
#endif
11+
12+
#include "MsgPack/Types.h"
13+
#include "MsgPack/Packer.h"
14+
#include "MsgPack/Unpacker.h"
15+
#include "MsgPack/Utility.h"
16+
17+
namespace MsgPack = arduino::msgpack;
18+
19+
#include <DebugLogRestoreState.h>
20+
21+
#endif // ARDUINOMSGPACK_H

0 commit comments

Comments
 (0)