Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uni_ete_hepialight_mqtt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jonas.stirnema
uni_ete_hepialight_mqtt
Commits
c3b8acfb
Commit
c3b8acfb
authored
1 year ago
by
abivarma.kandiah
Browse files
Options
Downloads
Patches
Plain Diff
ESP can send both text and image to wanted matrix
parent
1c34ee94
No related branches found
No related tags found
1 merge request
!2
Merge ESP code to master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mqtt_esp32/mqtt_esp32.ino
+66
-36
66 additions, 36 deletions
src/mqtt_esp32/mqtt_esp32.ino
with
66 additions
and
36 deletions
src/mqtt_esp32/mqtt_esp32.ino
+
66
−
36
View file @
c3b8acfb
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#define MATRIX_SIZE 10 // 10x10
#define MATRIX_SIZE 10 // 10x10
#define IMG_DATA_SIZE MATRIX_SIZE * MATRIX_SIZE * 3 //DATA SIZE FOR ONE MATRIX = RGB * MATRIX_SIZE
#define IMG_DATA_SIZE MATRIX_SIZE * MATRIX_SIZE * 3 //DATA SIZE FOR ONE MATRIX = RGB * MATRIX_SIZE
#define IS_TEXT
1
#define IS_TEXT
0
// WiFi
// WiFi
const
char
*
ssid
=
"uni-ete2"
;
// Enter your WiFi name
const
char
*
ssid
=
"uni-ete2"
;
// Enter your WiFi name
...
@@ -13,7 +13,8 @@ const char *password = "uni-ete2-esp32"; // Enter WiFi password
...
@@ -13,7 +13,8 @@ const char *password = "uni-ete2-esp32"; // Enter WiFi password
// MQTT Broker
// MQTT Broker
const
char
*
mqtt_broker
=
"192.168.1.103"
;
const
char
*
mqtt_broker
=
"192.168.1.103"
;
const
char
*
topic_send
=
"fromesp"
;
const
char
*
topic_send
=
"fromesp"
;
const
char
*
topic_rcv
=
"toesp"
;
const
char
*
topic_img
=
"toesp/image"
;
const
char
*
topic_txt
=
"toesp/text"
;
const
int
mqtt_port
=
1883
;
const
int
mqtt_port
=
1883
;
WiFiClient
espClient
;
WiFiClient
espClient
;
...
@@ -64,7 +65,13 @@ void setup()
...
@@ -64,7 +65,13 @@ void setup()
// Publish and subscribe
// Publish and subscribe
client
.
publish
(
topic_send
,
"Hi, I'm ESP32 ^^"
);
client
.
publish
(
topic_send
,
"Hi, I'm ESP32 ^^"
);
client
.
subscribe
(
topic_rcv
);
client
.
subscribe
(
topic_img
);
client
.
subscribe
(
topic_txt
);
}
int
d2_to_flat
(
uint8_t
x
,
uint8_t
y
,
uint32_t
pitch
)
{
return
(
x
*
pitch
)
+
y
;
}
}
uint8_t
*
mqtt_packet_to_raw
(
uint8_t
*
packet
,
unsigned
int
*
length
)
uint8_t
*
mqtt_packet_to_raw
(
uint8_t
*
packet
,
unsigned
int
*
length
)
...
@@ -97,35 +104,59 @@ void send_data_to_matrix(uint8_t idx, uint8_t idy, uint8_t* data, uint32_t lengt
...
@@ -97,35 +104,59 @@ void send_data_to_matrix(uint8_t idx, uint8_t idy, uint8_t* data, uint32_t lengt
uint8_t
send_len
=
13
;
uint8_t
send_len
=
13
;
// SEND RGB DATA
// RGB DATA PROCESS
for
(
int
i
=
0
;
i
<
length
;
i
+=
3
)
// HARDCODED
for
(
int
x
=
(
cluster_size_y
-
1
-
idy
)
*
10
;
x
<
(
cluster_size_y
-
idy
)
*
10
;
x
+=
1
)
{
{
// Serial.print((char)data[i]);
for
(
int
y
=
idx
*
30
;
y
<
(
idx
+
1
)
*
30
;
y
+=
3
)
// Serial.print((char)data[i+1]);
{
// Serial.print((char)data[i+2]);
// Serial.println()
int
i
=
d2_to_flat
(
x
,
y
,
30
*
cluster_size_y
);
// COMPUTE COLOR IN 16 BITS
uint8_t
r
=
data
[
i
]
&
0x1F
;
// COMPUTE COLOR IN 16 BITS
uint8_t
g
=
data
[
i
+
1
]
&
0x3F
;
uint8_t
r
=
data
[
i
]
&
0x1F
;
uint8_t
b
=
data
[
i
+
2
]
&
0x1F
;
uint8_t
g
=
data
[
i
+
1
]
&
0x3F
;
uint16_t
rgb
=
r
<<
11
|
g
<<
5
|
b
;
uint8_t
b
=
data
[
i
+
2
]
&
0x1F
;
// Serial.print(rgb);
uint16_t
rgb
=
r
<<
11
|
g
<<
5
|
b
;
// Serial.print(' ');
// SPLIT ON 8 BITS
// SPLIT ON 8 BITS
uint8_t
rgb_0
=
rgb
>>
8
;
uint8_t
rgb_0
=
rgb
>>
8
;
uint8_t
rgb_1
=
rgb
&
0xFF
;
uint8_t
rgb_1
=
rgb
&
0xFF
;
//Serial.println(rgb_0);
// SEND RGB
// Serial.print(' ');
raw_data
[
send_len
++
]
=
rgb_0
;
//Serial.println(rgb_1);
raw_data
[
send_len
++
]
=
rgb_1
;
}
// SEND RGB
//SerialPort.print((char) rgb_0);
//SerialPort.print((char) rgb_1);
//send_len += 2;
raw_data
[
send_len
++
]
=
rgb_0
;
raw_data
[
send_len
++
]
=
rgb_1
;
}
}
// for(int i = 0; i < length; i+=3)
// {
// // Serial.print((char)data[i]);
// // Serial.print((char)data[i+1]);
// // Serial.print((char)data[i+2]);
// // COMPUTE COLOR IN 16 BITS
// uint8_t r = data[i] & 0x1F;
// uint8_t g = data[i+1] & 0x3F;
// uint8_t b = data[i+2] & 0x1F ;
// uint16_t rgb = r << 11 | g << 5 | b;
// // Serial.print(rgb);
// // Serial.print(' ');
// // SPLIT ON 8 BITS
// uint8_t rgb_0 = rgb >> 8;
// uint8_t rgb_1 = rgb & 0xFF;
// //Serial.println(rgb_0);
// // Serial.print(' ');
// //Serial.println(rgb_1);
// // SEND RGB
// //SerialPort.print((char) rgb_0);
// //SerialPort.print((char) rgb_1);
// //send_len += 2;
// raw_data[send_len++] = rgb_0;
// raw_data[send_len++] = rgb_1;
// }
// // SEND MATRIX ID
// // SEND MATRIX ID
// Serial.println(idx);
// Serial.println(idx);
// Serial.println(idy);
// Serial.println(idy);
...
@@ -172,7 +203,7 @@ void callback(char *topic, byte *payload, unsigned int length)
...
@@ -172,7 +203,7 @@ void callback(char *topic, byte *payload, unsigned int length)
// SerialPort.print((char)202);
// SerialPort.print((char)202);
// SerialPort.print((char)0xaa);
// SerialPort.print((char)0xaa);
if
(
IS_TEXT
)
if
(
strcmp
(
topic
,
topic_txt
)
==
0
)
{
{
char
data
[
100
];
char
data
[
100
];
char
header
[]
=
"PT;1,0;MOVING;16711680;0.1;"
;
char
header
[]
=
"PT;1,0;MOVING;16711680;0.1;"
;
...
@@ -211,17 +242,16 @@ void callback(char *topic, byte *payload, unsigned int length)
...
@@ -211,17 +242,16 @@ void callback(char *topic, byte *payload, unsigned int length)
}
}
// SEND UART PACKET FOR EACH MATRIX
// SEND UART PACKET FOR EACH MATRIX
for
(
int
x
=
0
;
x
<
cluster_size_x
;
x
++
)
for
(
int
x
_mat
=
0
;
x
_mat
<
cluster_size_x
;
x
_mat
++
)
{
{
for
(
int
y
=
cluster_size_y
-
1
;
y
>=
0
;
y
--
)
for
(
int
y
_mat
=
cluster_size_y
-
1
;
y
_mat
>=
0
;
y
_mat
--
)
{
{
//Serial.println("FOR LOOP");
//Serial.println("FOR LOOP");
// SEND UART PACKET
// SEND UART PACKET
send_data_to_matrix
(
x
,
y
,
raw_data
,
IMG_DATA_SIZE
);
send_data_to_matrix
(
x
_mat
,
y_mat
,
raw_data
,
IMG_DATA_SIZE
);
// MOVE FORWARD IN DATA
// MOVE FORWARD IN DATA
raw_data
+=
IMG_DATA_SIZE
;
//
raw_data += IMG_DATA_SIZE;
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment