Skip to content

Commit

Permalink
don't hardcode the api ip/host
Browse files Browse the repository at this point in the history
  • Loading branch information
dmowcomber committed Apr 3, 2021
1 parent ffbc367 commit 2962a39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ dcc-go -address=3 -device=/dev/ttyACM0
```
docker-compose up -d
```
After making changes or pulling latest you'll need to rebuild and restart the service:
```
docker-compose build
docker-compose kill
docker-compose rm -f
docker-compose up -d
```

### docker
```
Expand Down
12 changes: 7 additions & 5 deletions ui/web/assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var functionsCount = 28;
var speed=0;
var address=3;
var directionForward=true;
var hostname = window.location.hostname;
console.log('api host: ' + hostname);

function addFunctionRows(document) {
for (let i = 1; i<=functionsCount; i=i+4) {
Expand Down Expand Up @@ -112,7 +114,7 @@ $(document).ready(function(){

if (curr == 'power') {
$.ajax({
url: 'http://10.0.1.121:8080/power',
url: 'http://' + hostname + ':8080/power',
success: function(data){
console.log(JSON.stringify(data));
var json = JSON.parse(data)
Expand All @@ -133,7 +135,7 @@ $(document).ready(function(){
$("#stop").addClass('active');
$("#speed-input-box").val('0');
$.ajax({
url: 'http://10.0.1.121:8080/'+address+'/stop',
url: 'http://' + hostname + ':8080/'+address+'/stop',
success: function(data){
console.log(JSON.stringify(data));
},
Expand All @@ -155,7 +157,7 @@ $(document).ready(function(){
} else if (curr.match(digitRegex)) {
console.log(curr + " is a number");
$.ajax({
url: 'http://10.0.1.121:8080/'+address+'/function?function=' + curr,
url: 'http://' + hostname + ':8080/'+address+'/function?function=' + curr,
success: function(data){
console.log(JSON.stringify(data));
var json = JSON.parse(data)
Expand Down Expand Up @@ -193,7 +195,7 @@ function updateSpeedRequest() {
}

$.ajax({
url: 'http://10.0.1.121:8080/'+address+'/speed?forward=' + directionForward + '&speed=' + speed,
url: 'http://' + hostname + ':8080/'+address+'/speed?forward=' + directionForward + '&speed=' + speed,
success: function(data){
console.log(JSON.stringify(data));
},
Expand All @@ -205,7 +207,7 @@ function updateSpeedRequest() {

function refreshState() {
$.ajax({
url: 'http://10.0.1.121:8080/state',
url: 'http://' + hostname + ':8080/state',
success: function(data){
var json = JSON.parse(data);

Expand Down

0 comments on commit 2962a39

Please sign in to comment.