dredger-iot 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/bin/dredger +264 -0
- data/lib/dredger/iot/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3249f8a115ef3351b820037510c1ef0259ae227eb881d191353ddd20378c7520
|
|
4
|
+
data.tar.gz: 1bbc867919f8ba1faa5640d5b1f39370646b4a41d133dab98da0966fe44c2bdc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10d9397170fa1c21e34a969595c21a48a4605cbceeb6b79c6833930a65bddaac5798d4537c881d0bda30decbb76a5029d35e5924180978c265b61e5a7f739e84
|
|
7
|
+
data.tar.gz: 6d9f92320c43eb23c92aee74cc60cc24bcbb5b44cf5409487047aa2e34b8380011d3a8a508612216edf2e9ff00c7eafda562e4e683c46fd7bb988898f22d0552
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.2] - 2025-10-04
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Developer tools and community infrastructure.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Examples: seed BME280 calibration and sample data for I2C simulation.
|
|
17
|
+
- Examples: allow interval/cycles override via env for fast simulation runs.
|
|
18
|
+
|
|
10
19
|
## [0.1.1] - 2025-10-04
|
|
11
20
|
|
|
12
21
|
### Fixed
|
|
@@ -44,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
44
53
|
- RuboCop configuration and compliance
|
|
45
54
|
- Comprehensive documentation and usage examples
|
|
46
55
|
|
|
47
|
-
[Unreleased]: https://github.com/TheMadBotterINC/dredger-iot/compare/v0.1.
|
|
56
|
+
[Unreleased]: https://github.com/TheMadBotterINC/dredger-iot/compare/v0.1.2...HEAD
|
|
57
|
+
[0.1.2]: https://github.com/TheMadBotterINC/dredger-iot/compare/v0.1.1...v0.1.2
|
|
48
58
|
[0.1.1]: https://github.com/TheMadBotterINC/dredger-iot/compare/v0.1.0...v0.1.1
|
|
49
59
|
[0.1.0]: https://github.com/TheMadBotterINC/dredger-iot/releases/tag/v0.1.0
|
data/bin/dredger
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'dredger/iot'
|
|
6
|
+
require 'optparse'
|
|
7
|
+
require 'json'
|
|
8
|
+
|
|
9
|
+
# Dredger CLI - Quick sensor testing and debugging tool
|
|
10
|
+
class DredgerCLI
|
|
11
|
+
def initialize
|
|
12
|
+
@options = {
|
|
13
|
+
backend: 'auto',
|
|
14
|
+
format: 'text',
|
|
15
|
+
interval: nil
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def run(args)
|
|
20
|
+
parser = build_parser
|
|
21
|
+
parser.parse!(args)
|
|
22
|
+
|
|
23
|
+
command = args.shift
|
|
24
|
+
case command
|
|
25
|
+
when 'list-sensors'
|
|
26
|
+
list_sensors
|
|
27
|
+
when 'read'
|
|
28
|
+
read_sensor(args)
|
|
29
|
+
when 'test-gpio'
|
|
30
|
+
test_gpio(args)
|
|
31
|
+
when 'test-i2c'
|
|
32
|
+
test_i2c
|
|
33
|
+
when 'info'
|
|
34
|
+
show_info
|
|
35
|
+
else
|
|
36
|
+
puts parser
|
|
37
|
+
exit 1
|
|
38
|
+
end
|
|
39
|
+
rescue StandardError => e
|
|
40
|
+
puts "Error: #{e.message}"
|
|
41
|
+
puts e.backtrace if ENV['DEBUG']
|
|
42
|
+
exit 1
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def build_parser
|
|
48
|
+
OptionParser.new do |opts|
|
|
49
|
+
opts.banner = 'Usage: dredger [options] COMMAND [args]'
|
|
50
|
+
opts.separator ''
|
|
51
|
+
opts.separator 'Commands:'
|
|
52
|
+
opts.separator ' list-sensors List available sensor types'
|
|
53
|
+
opts.separator ' read SENSOR [OPTIONS] Read from a sensor'
|
|
54
|
+
opts.separator ' test-gpio PIN Test GPIO pin'
|
|
55
|
+
opts.separator ' test-i2c Scan I2C bus'
|
|
56
|
+
opts.separator ' info Show system information'
|
|
57
|
+
opts.separator ''
|
|
58
|
+
opts.separator 'Options:'
|
|
59
|
+
|
|
60
|
+
opts.on('--backend BACKEND', 'Backend: auto, simulation, hardware') do |b|
|
|
61
|
+
@options[:backend] = b
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
opts.on('--format FORMAT', 'Output format: text, json') do |f|
|
|
65
|
+
@options[:format] = f
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
opts.on('--interval SECONDS', Float, 'Continuous reading interval') do |i|
|
|
69
|
+
@options[:interval] = i
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
opts.on('-h', '--help', 'Show this help') do
|
|
73
|
+
puts opts
|
|
74
|
+
exit
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
opts.on('-v', '--version', 'Show version') do
|
|
78
|
+
puts "dredger-iot #{Dredger::IoT::VERSION}"
|
|
79
|
+
exit
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def list_sensors
|
|
85
|
+
sensors = {
|
|
86
|
+
'dht22' => 'DHT22 - Temperature/Humidity (GPIO)',
|
|
87
|
+
'bme280' => 'BME280 - Temperature/Humidity/Pressure (I2C)',
|
|
88
|
+
'ds18b20' => 'DS18B20 - Waterproof Temperature (1-Wire)',
|
|
89
|
+
'bmp180' => 'BMP180 - Barometric Pressure/Temperature (I2C)',
|
|
90
|
+
'mcp9808' => 'MCP9808 - High-Accuracy Temperature (I2C)'
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
puts 'Available Sensors:'
|
|
94
|
+
puts
|
|
95
|
+
sensors.each do |key, desc|
|
|
96
|
+
puts " #{key.ljust(10)} - #{desc}"
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def read_sensor(args)
|
|
101
|
+
sensor_type = args.shift
|
|
102
|
+
unless sensor_type
|
|
103
|
+
puts 'Error: Sensor type required'
|
|
104
|
+
puts 'Run "dredger list-sensors" to see available sensors'
|
|
105
|
+
exit 1
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
setup_backends
|
|
109
|
+
sensor = create_sensor(sensor_type, args)
|
|
110
|
+
|
|
111
|
+
if @options[:interval]
|
|
112
|
+
read_continuous(sensor)
|
|
113
|
+
else
|
|
114
|
+
read_once(sensor)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def create_sensor(type, args)
|
|
119
|
+
case type
|
|
120
|
+
when 'dht22'
|
|
121
|
+
pin = args.shift || 'P9_12'
|
|
122
|
+
gpio = Dredger::IoT::Bus::Auto.gpio
|
|
123
|
+
provider = Dredger::IoT::Sensors::DHT22Provider.new(gpio_bus: gpio)
|
|
124
|
+
Dredger::IoT::Sensors::DHT22.new(pin_label: pin, provider: provider)
|
|
125
|
+
when 'bme280'
|
|
126
|
+
addr = (args.shift || '0x76').to_i(16)
|
|
127
|
+
i2c = Dredger::IoT::Bus::Auto.i2c
|
|
128
|
+
provider = Dredger::IoT::Sensors::BME280Provider.new(i2c_bus: i2c)
|
|
129
|
+
Dredger::IoT::Sensors::BME280.new(i2c_addr: addr, provider: provider)
|
|
130
|
+
when 'ds18b20'
|
|
131
|
+
provider = Dredger::IoT::Sensors::DS18B20Provider.new
|
|
132
|
+
devices = provider.list_devices
|
|
133
|
+
device_id = args.shift || devices.first
|
|
134
|
+
unless device_id
|
|
135
|
+
puts 'Error: No DS18B20 devices found'
|
|
136
|
+
exit 1
|
|
137
|
+
end
|
|
138
|
+
Dredger::IoT::Sensors::DS18B20.new(device_id: device_id, provider: provider)
|
|
139
|
+
else
|
|
140
|
+
puts "Error: Unknown sensor type '#{type}'"
|
|
141
|
+
exit 1
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def read_once(sensor)
|
|
146
|
+
readings = sensor.readings
|
|
147
|
+
output_readings(readings)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def read_continuous(sensor)
|
|
151
|
+
puts "Reading every #{@options[:interval]} seconds (Ctrl+C to stop)..."
|
|
152
|
+
puts
|
|
153
|
+
|
|
154
|
+
loop do
|
|
155
|
+
readings = sensor.readings
|
|
156
|
+
output_readings(readings)
|
|
157
|
+
puts if @options[:format] == 'text'
|
|
158
|
+
sleep @options[:interval]
|
|
159
|
+
end
|
|
160
|
+
rescue Interrupt
|
|
161
|
+
puts "\nStopped"
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def output_readings(readings)
|
|
165
|
+
case @options[:format]
|
|
166
|
+
when 'json'
|
|
167
|
+
data = readings.map do |r|
|
|
168
|
+
{
|
|
169
|
+
sensor_type: r.sensor_type,
|
|
170
|
+
value: r.value,
|
|
171
|
+
unit: r.unit,
|
|
172
|
+
timestamp: r.timestamp.iso8601
|
|
173
|
+
}
|
|
174
|
+
end
|
|
175
|
+
puts JSON.pretty_generate(data)
|
|
176
|
+
else
|
|
177
|
+
timestamp = Time.now.strftime('%Y-%m-%d %H:%M:%S')
|
|
178
|
+
puts "[#{timestamp}]"
|
|
179
|
+
readings.each do |r|
|
|
180
|
+
puts " #{r.sensor_type}: #{r.value} #{r.unit}"
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def test_gpio(args)
|
|
186
|
+
pin = args.shift || 'P9_12'
|
|
187
|
+
setup_backends
|
|
188
|
+
gpio = Dredger::IoT::Bus::Auto.gpio
|
|
189
|
+
|
|
190
|
+
puts "Testing GPIO pin #{pin}..."
|
|
191
|
+
gpio.set_direction(pin, :out)
|
|
192
|
+
|
|
193
|
+
3.times do |i|
|
|
194
|
+
puts " Cycle #{i + 1}: HIGH"
|
|
195
|
+
gpio.write(pin, 1)
|
|
196
|
+
sleep 0.5
|
|
197
|
+
|
|
198
|
+
puts " Cycle #{i + 1}: LOW"
|
|
199
|
+
gpio.write(pin, 0)
|
|
200
|
+
sleep 0.5
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
puts 'GPIO test complete'
|
|
204
|
+
ensure
|
|
205
|
+
gpio&.close
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def test_i2c
|
|
209
|
+
setup_backends
|
|
210
|
+
i2c = Dredger::IoT::Bus::Auto.i2c
|
|
211
|
+
|
|
212
|
+
puts 'Scanning I2C bus...'
|
|
213
|
+
puts 'Note: This only works with hardware backend'
|
|
214
|
+
puts
|
|
215
|
+
|
|
216
|
+
# Common I2C addresses
|
|
217
|
+
addresses = [0x18, 0x76, 0x77]
|
|
218
|
+
addresses.each do |addr|
|
|
219
|
+
print " 0x#{addr.to_s(16).upcase}: "
|
|
220
|
+
begin
|
|
221
|
+
i2c.read(addr, 1)
|
|
222
|
+
puts 'FOUND'
|
|
223
|
+
rescue StandardError
|
|
224
|
+
puts '--'
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
ensure
|
|
228
|
+
i2c&.close
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def show_info
|
|
232
|
+
puts "Dredger-IoT v#{Dredger::IoT::VERSION}"
|
|
233
|
+
puts "Ruby #{RUBY_VERSION}"
|
|
234
|
+
puts
|
|
235
|
+
puts 'Backends:'
|
|
236
|
+
puts " GPIO: #{gpio_backend_info}"
|
|
237
|
+
puts " I2C: #{i2c_backend_info}"
|
|
238
|
+
puts
|
|
239
|
+
puts 'Environment:'
|
|
240
|
+
puts " DREDGER_IOT_GPIO_BACKEND: #{ENV['DREDGER_IOT_GPIO_BACKEND'] || '(not set)'}"
|
|
241
|
+
puts " DREDGER_IOT_I2C_BACKEND: #{ENV['DREDGER_IOT_I2C_BACKEND'] || '(not set)'}"
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def setup_backends
|
|
245
|
+
case @options[:backend]
|
|
246
|
+
when 'simulation'
|
|
247
|
+
ENV['DREDGER_IOT_GPIO_BACKEND'] = 'simulation'
|
|
248
|
+
ENV['DREDGER_IOT_I2C_BACKEND'] = 'simulation'
|
|
249
|
+
when 'hardware'
|
|
250
|
+
ENV['DREDGER_IOT_GPIO_BACKEND'] = 'libgpiod'
|
|
251
|
+
ENV['DREDGER_IOT_I2C_BACKEND'] = 'linux'
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def gpio_backend_info
|
|
256
|
+
File.exist?('/dev/gpiochip0') ? 'libgpiod (detected)' : 'simulation (no hardware)'
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def i2c_backend_info
|
|
260
|
+
File.exist?('/dev/i2c-1') ? 'linux (detected)' : 'simulation (no hardware)'
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
DredgerCLI.new.run(ARGV) if $PROGRAM_NAME == __FILE__
|
data/lib/dredger/iot/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dredger-iot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- The Mad Botter INC
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
@@ -30,13 +30,15 @@ description: |
|
|
|
30
30
|
scheduling utilities for periodic polling and exponential backoff.
|
|
31
31
|
email:
|
|
32
32
|
- opensource@themadbotter.com
|
|
33
|
-
executables:
|
|
33
|
+
executables:
|
|
34
|
+
- dredger
|
|
34
35
|
extensions: []
|
|
35
36
|
extra_rdoc_files: []
|
|
36
37
|
files:
|
|
37
38
|
- CHANGELOG.md
|
|
38
39
|
- LICENSE.txt
|
|
39
40
|
- README.md
|
|
41
|
+
- bin/dredger
|
|
40
42
|
- lib/dredger/iot.rb
|
|
41
43
|
- lib/dredger/iot/bus.rb
|
|
42
44
|
- lib/dredger/iot/bus/auto.rb
|
|
@@ -86,7 +88,7 @@ post_install_message: "\n══════════════════
|
|
|
86
88
|
\ \\___________________// | \n |_____________________________|
|
|
87
89
|
\ \n ~~~ \\ // ~~~ \n
|
|
88
90
|
\ \\_______________// \n═══════════════════════════════════════════════════════════════════\n
|
|
89
|
-
\ Hardware Integration for Embedded Linux v0.1.
|
|
91
|
+
\ Hardware Integration for Embedded Linux v0.1.2\n═══════════════════════════════════════════════════════════════════\n\n\U0001F389
|
|
90
92
|
Thanks for installing!\n\n\U0001F4DA Hardware Setup (kernel modules & permissions):\n
|
|
91
93
|
\ https://github.com/TheMadBotterINC/dredger-iot#hardware-setup\n\n\U0001F680 Quick
|
|
92
94
|
Start:\n require 'dredger/iot'\n gpio = Dredger::IoT::Bus::Auto.gpio\n i2c
|