Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commited by Debasish Goswami #3

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
12a93e2
add gitignore
say-paul Mar 12, 2024
753355c
change pin names
say-paul Mar 12, 2024
60b3e01
gitignore add .vscode
say-paul Mar 12, 2024
f007989
adding server to echo system
say-paul Mar 12, 2024
b794021
modifying 14 code
say-paul Mar 12, 2024
898bea1
ota feature
say-paul Mar 13, 2024
619fc3a
add schematics to extra
say-paul Mar 14, 2024
64884b7
ota implementation and stop motor func
say-paul Mar 14, 2024
792345c
stop motor func
say-paul Mar 14, 2024
6ff03b4
examples 14-updated
say-paul Mar 14, 2024
2283b12
motor action corrections
say-paul Mar 14, 2024
3653075
example-14 websocket and dependencies
say-paul Mar 14, 2024
1dc5716
commited by Debasish Goswami
DebaDr0na Mar 14, 2024
6749ca4
deleted blite.cpp, blite.h from 14th module
DebaDr0na Mar 15, 2024
62b1954
removed my websocket code
DebaDr0na Mar 15, 2024
4011d5f
library.properties and ci update
say-paul Mar 15, 2024
afe81c9
aaded io3 and io4
say-paul Mar 17, 2024
f7d1b9b
example:ultrasonic and some cleanup
say-paul Mar 17, 2024
42c392a
example:line follower and some cleanup
say-paul Mar 17, 2024
da3c9c2
updated the html file with more buttons
DebaDr0na Mar 18, 2024
130fbd2
commited by Debasish Goswami
DebaDr0na Mar 14, 2024
522ac7d
deleted blite.cpp, blite.h from 14th module
DebaDr0na Mar 15, 2024
f7b3907
removed my websocket code
DebaDr0na Mar 15, 2024
9dfbbdd
updated the html file with more buttons
DebaDr0na Mar 18, 2024
dd86cb5
14 example cleanup
say-paul Mar 18, 2024
af1e3ca
add test.h to validate new server
say-paul Mar 18, 2024
de6b929
without the use of smartRenderServer
DebaDr0na Mar 20, 2024
0a98f24
Merge branch 'dev_deba' of https://github.com/buildybee/blite into de…
DebaDr0na Mar 20, 2024
df9e6ed
without using smartServerRender service
DebaDr0na Mar 20, 2024
652946c
web_page string to be passesd by referance
say-paul Mar 21, 2024
d0e1b48
working example of webpage with custom scripts
say-paul Mar 21, 2024
60ae880
control neo led lights using websocket
DebaDr0na Apr 5, 2024
c3076a2
added HTML default buttons in ex14
DebaDr0na Apr 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v1
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/.*
.vscode/**
1 change: 1 addition & 0 deletions blite
Submodule blite added at 8b27af
2 changes: 1 addition & 1 deletion examples/08_distance_measuring/08_distance_measuring.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "blite.h"
#include <blite.h>

//define sound velocity in cm/uS
#define SOUND_VELOCITY 0.034
Expand Down
164 changes: 33 additions & 131 deletions examples/13_rgb_web_control/13_rgb_web_control.ino
Original file line number Diff line number Diff line change
@@ -1,150 +1,52 @@
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <blite.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WebSocketsServer.h>
#include "lighting.h"
#include <Adafruit_NeoPixel.h>

// Webserver Config
const char *ssid = "ZTE_2.4G_6eZrkS";
const char *password = "ijF3kXh4";
ESP8266WebServer server ( 80 );

// Neopixel Config
#define NeoPIN D4
#define NeoPIN 2
#define NUM_LEDS 16

int brightness = 150;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, NeoPIN, NEO_RGB + NEO_KHZ800);


Blite mybot;
ESP8266WebServer wifiRemoteControl(80);
WebSocketsServer webSocket = WebSocketsServer(81); // WebSocket server on port 81
const int led = 13;

void setup ( void ) {

Serial.begin ( 115200 );

// ##############
// NeoPixel start
Serial.println();
strip.setBrightness(brightness);
strip.begin();
strip.show();
delay(50);
Serial.println("NeoPixel started");

// #########
// Webserver
pinMode ( led, OUTPUT );
digitalWrite ( led, 0 );

WiFi.begin ( ssid, password );
Serial.println ( "" );

// Wait for connection
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}

Serial.println ( "" );
Serial.print ( "Connected to " );
Serial.println ( ssid );
Serial.print ( "IP address: " );
Serial.println ( WiFi.localIP() );

if ( MDNS.begin ( "esp8266" ) ) {
Serial.println ( "MDNS responder started" );
}

// what to do with requests
server.on ( "/", handleRoot );
server.onNotFound ( handleNotFound );
server.begin();



Serial.println ( "HTTP server started" );
}

void loop ( void ) {
// waiting fo a client
server.handleClient();
void setup(){
mybot.setup();
Serial.begin(115200);
mybot.smartConnectWiFi();
webSocket.begin();
webSocket.onEvent(webSocketEvent);
wifiRemoteControl.on("/", HTTP_GET, []() {
Serial.println("Web Server: received a web page request");
String html = HTML_LIGHT;
wifiRemoteControl.send(200, "text/html", html);
});
wifiRemoteControl.begin();

}


void handleRoot() {
Serial.println("Client connected");
digitalWrite ( led, 1 );

// data from the colorpicker (e.g. #FF00FF)
String color = server.arg("c");
Serial.println("Color: " + color);
// setting the color to the strip
setNeoColor(color);

// building a website
char temp[5000];
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
char clr [7];
color.toCharArray(clr, 7);
snprintf ( temp, 5000,

"<!DOCTYPE html>\n<html>\n\
<head>\n\
<title>wifi pixel</title>\n\
<style>\
body { background-color: #F08262; font-family: Arial; Color: #fff; }\
h1 {text-align: center;}\
p {text-align: center;}\
form {text-align: center;}\
</style>\n\
<meta name=\"viewport\" content=\"width=device-width, height=device-height, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0\" />\n\
</head>\n\
<body>\n\
<h1>Buildybee</h1>\n\
<p>pick the color!</p>\n\
\n\
<form action=\"\" name=\"pick\" method=\"post\">\n\
<input type=\"color\" name=\"c\" value=\"%02d\" onchange=\"document.forms['pick'].submit();\" />\n\
&nbsp;<span onclick=\"document.forms['pick'].submit();\" style=\"font-size:16pt;\"> </span>\n\
</form>\n\
\n\
</body>\
</html>",

hr, min % 60, sec % 60, clr
);
server.send ( 200, "text/html", temp );
digitalWrite ( led, 0 );
void loop(){
wifiRemoteControl.handleClient();
webSocket.loop();

}

void handleNotFound() {
digitalWrite ( led, 1 );
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += ( server.method() == HTTP_GET ) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";

for ( uint8_t i = 0; i < server.args(); i++ ) {
message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
}

server.send ( 404, "text/plain", message );
digitalWrite ( led, 0 );
void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) {
String command = String((char*)payload);
Serial.print("command: ");
Serial.println(command);
// setting the color to the strip
setNeoColor(command);
}



void setNeoColor(String value){
Serial.print("Setting Neopixel...");
// converting Hex to Int
int number = (int) strtol( &value[1], NULL, 16);

int number = (int) strtol( &value[1], NULL, 16);
// splitting into three parts
int r = number >> 16;
int g = number >> 8 & 0xFF;
Expand All @@ -167,4 +69,4 @@ void setNeoColor(String value){
strip.show();

Serial.println("on.");
}
}
75 changes: 75 additions & 0 deletions examples/13_rgb_web_control/lighting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const char *HTML_LIGHT = R"=====(
<!DOCTYPE html>
<html>
<head>
<title>wifi pixel</title>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
<style>
body { background-color: #F08262; font-family: Arial; Color: #fff; }
h1 {text-align: center;}
p {text-align: center;}
form {text-align: center;}
</style>
<script>
var color = "c";
var ws = null;
function ws_onmessage(e_msg)
{
e_msg = e_msg || window.event; // MessageEvent

//alert("msg : " + e_msg.data);
}
function ws_onopen()
{
document.getElementById("ws_state").innerHTML = "OPEN";
document.getElementById("wc_conn").innerHTML = "Disconnect";
}
function ws_onclose()
{
document.getElementById("ws_state").innerHTML = "CLOSED";
document.getElementById("wc_conn").innerHTML = "Connect";
console.log("socket was closed");
ws.onopen = null;
ws.onclose = null;
ws.onmessage = null;
ws = null;
}
function wc_onclick()
{
if(ws == null)
{
ws = new WebSocket("ws://" + window.location.host + ":81");
document.getElementById("ws_state").innerHTML = "CONNECTING";

ws.onopen = ws_onopen;
ws.onclose = ws_onclose;
ws.onmessage = ws_onmessage;
}
else
ws.close();
}
function wc_color()
{
send_command(document.getElementById("colorPicker").value);
}
function send_command(cmd)
{
if(ws != null)
if(ws.readyState == 1)
ws.send(cmd + "\r\n");
}
</script>
</head>
<body>
<h1>Buildybee</h1>
<p>pick the color!</p>
<p> <input id = "colorPicker" type="color" name="c" value="%02d" onchange="wc_color();" />
&nbsp;<span onclick="wc_color();" style="font-size:16pt;"> </span>
</p>
<p>
WebSocket : <span id="ws_state" style="color:blue">closed</span>
<button id="wc_conn" style="text-align: center; font-size: 24px;" onclick="wc_onclick();">Connect</button><br>
</p>
</body>
</html>
)=====";
97 changes: 85 additions & 12 deletions examples/14_blite_rc_car/14_blite_rc_car.ino
Original file line number Diff line number Diff line change
@@ -1,24 +1,97 @@
#include <blite.h>
#include <ESP8266WebServer.h>
#include <WebSocketsServer.h>
say-paul marked this conversation as resolved.
Show resolved Hide resolved
#include "remote.h"

Blite myBot;
#define CMD_BACKWARD 2
#define CMD_STOP 0
#define CMD_FORWARD 1
#define CMD_LEFT 4
#define CMD_RIGHT 8
#define CMD_PUSH 5
#define CMD_SRVCLCK 6
#define CMD_SRVACLCK 9


Blite mybot;
ESP8266WebServer wifiRemoteControl(80);
WebSocketsServer webSocket = WebSocketsServer(81); // WebSocket server on port 81
void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) {
switch (type) {
case WStype_DISCONNECTED:
Serial.printf("[%u] Disconnected!\n", num);
break;
case WStype_CONNECTED:
{
IPAddress ip = webSocket.remoteIP(num);
Serial.printf("[%u] Connected from %d.%d.%d.%d\n", num, ip[0], ip[1], ip[2], ip[3]);
}
break;
case WStype_TEXT:
//Serial.printf("[%u] Received text: %s\n", num, payload);
String angle = String((char*)payload);
int command = angle.toInt();
Serial.print("command: ");
Serial.println(command);

switch (command) {
case CMD_STOP:
Serial.println("Stop");
mybot.stopMotor();
break;
case CMD_FORWARD:
Serial.println("Move Forward");
mybot.moveForward();
break;
case CMD_BACKWARD:
Serial.println("Move Backward");
mybot.moveBackward();
break;
case CMD_LEFT:
Serial.println("Turn Left");
mybot.turnLeft();
break;
case CMD_RIGHT:
Serial.println("Turn Right");
mybot.turnRight();
break;
case CMD_PUSH:
Serial.println("Push button pressed");
//mybot.push();
break;
case CMD_SRVCLCK:
Serial.println("Turn servo clockwise");
//mybot.turnServoClockwise();
break;
case CMD_SRVACLCK:
Serial.println("Turn servo anti-clockwise");
//mybot.turnServoAntiClockwise();
break;
default:
Serial.println("Unknown command");
}

break;
}
}


void setup(){
myBot.setup();
mybot.setup();
Serial.begin(115200);
myBot.smartConnectWiFi();
mybot.smartConnectWiFi();
webSocket.begin();
webSocket.onEvent(webSocketEvent);
wifiRemoteControl.on("/", HTTP_GET, []() {
Serial.println("Web Server: received a web page request");
String html = REMOTE_HTML_CONTENT;
wifiRemoteControl.send(200, "text/html", html);
});
wifiRemoteControl.begin();
Serial.println("Web Server: received a web page request");
String html = REMOTE_HTML_CONTENT;
wifiRemoteControl.send(200, "text/html", html);
});
wifiRemoteControl.begin();

}
void loop(){
wifiRemoteControl.handleClient();
if (myBot.buttonPressed()){
myBot.blinkLed(2);
}
}
webSocket.loop();

}
Loading
Loading