2016-08-26 1 views
0

이것은 잠재적으로 어리석은 질문 일 수 있지만 성공하지 못한 채로 2 주 동안 작업했습니다. 나는 전화로 EVOThings 응용 프로그램에 블루투스를 통해 연결하는 Arduino101을 사용하고 있습니다. 응용 프로그램은 Heroku에서 호스팅되는 Flask 서버에서 트위터 정보를 요청하며 블루투스 연결을 통해 Arduino에 대한 응답을 릴레이합니다. 그러나 응답이 성공적으로 진행 되더라도 클라이언트 측에서 응답을 구문 분석하여 추가 처리를 수행하고 Arduino101로 전송하는 데 문제가 있습니다. 아래는 코드의 일부입니다 : 요청을 할 수있는 기능을 추가하여 BLE와 전화 응용 프로그램에 Arduino101를 연결하여 AJAX를하고 저장하기위한 EVOThing 예를 수정했습니다 내가했던JS 스크립트를 사용하여 EVOThing 응용 프로그램의 요청 응답을 저장하는 방법

<script> 
 
\t // Application object. 
 
\t var app = {} 
 
\t // Connected device. 
 
\t app.device = null; 
 
\t app.msg = ''; 
 
\t 
 
\t //Get the message. 
 
\t app.getMsg = function() 
 
\t { \t 
 
\t \t $.ajax({ type: "GET", 
 
\t \t \t contentType: "application/json; charset=utf-8", 
 
\t \t \t url: 'http://peony-curie.herokuapp.com/getPushNotifications', 
 
\t \t \t async: false, 
 
\t \t \t dataType: "json", 
 
\t \t \t //navigator.notification.alert("hello", function() {}); 
 
\t \t \t success : function(text) 
 
\t \t \t { 
 
\t \t \t \t // navigator.notification.alert("hello", function() {}); 
 
\t \t \t \t var res = JSON.stringify(text.data); 
 
\t \t \t \t // navigator.notification.alert("hello", function() {}); 
 
\t \t \t \t //document.getElementById("try").innerHTML=res; 
 
\t \t \t \t var message = ''; 
 
\t \t \t \t for(i = 0; i < res.length; i++){ 
 
\t \t \t \t \t message += res[i]; 
 
\t \t \t \t } 
 
\t \t \t \t app.msg += message; 
 
\t \t \t \t //navigator.notification.alert("hello", function() {}); 
 
\t \t \t \t 
 
\t \t \t } 
 
\t \t }); 
 
\t } 
 
\t // Turn on LED red. 
 
\t app.ledRed = function() 
 
\t { 
 
\t \t app.device && app.device.writeDataArray(new Uint8Array([1]), '19b10001-e8f2-537e-4f6c-d104768a1214'); 
 
\t } 
 
\t 
 
\t // Turn on LED green 
 
\t app.ledGreen = function() 
 
\t { 
 
\t \t navigator.notification.alert(app.msg, function() {}); 
 
\t \t app.device && app.device.writeDataArray(new Uint8Array([2]), '19b10001-e8f2-537e-4f6c-d104768a1214'); \t 
 
\t } 
 
\t \t // Turn on LED blue 
 
\t app.ledBlue = function() 
 
\t { 
 
\t \t app.device && app.device.writeDataArray(new Uint8Array([3]), '19b10001-e8f2-537e-4f6c-d104768a1214'); 
 
\t } 
 
\t \t // Turn on LED yellow 
 
\t app.ledYellow = function() 
 
\t { 
 
\t \t app.device && app.device.writeDataArray(new Uint8Array([4]), '19b10001-e8f2-537e-4f6c-d104768a1214'); 
 
\t } 
 
\t \t // Turn on LED cyan 
 
\t app.ledCyan = function() 
 
\t { 
 
\t \t app.device && app.device.writeDataArray(new Uint8Array([5]), '19b10001-e8f2-537e-4f6c-d104768a1214'); 
 
\t } 
 
\t \t // Turn on LED purple 
 
\t app.ledPurple = function() 
 
\t { 
 
\t \t app.device && app.device.writeDataArray(new Uint8Array([6]), '19b10001-e8f2-537e-4f6c-d104768a1214'); 
 
\t } 
 
\t \t // Turn on LED white 
 
\t app.ledWhite = function() 
 
\t { 
 
\t \t app.device && app.device.writeDataArray(new Uint8Array([7]), '19b10001-e8f2-537e-4f6c-d104768a1214'); 
 
\t } 
 
\t 
 
\t // Turn off LED. 
 
\t app.ledOff = function() 
 
\t { 
 
\t \t app.device && app.device.writeDataArray(new Uint8Array([0]), '19b10001-e8f2-537e-4f6c-d104768a1214'); 
 
\t } 
 
\t app.showMessage = function(info) 
 
\t { 
 
\t \t document.getElementById('info').innerHTML = info 
 
\t }; 
 
\t // Called when BLE and other native functions are available. 
 
\t app.onDeviceReady = function() 
 
\t { 
 
\t \t app.showMessage('Touch the connect button to begin.'); 
 
\t }; 
 
\t app.connect = function() 
 
\t { 
 
\t \t evothings.arduinoble.close(); 
 
\t \t app.showMessage('Connecting...'); 
 
\t \t evothings.arduinoble.connect(
 
\t \t \t 'ARDUINO 101-3E4E', // Advertised name of BLE device. 
 
\t \t \t function(device) 
 
\t \t \t { 
 
\t \t \t \t app.device = device; 
 
\t \t \t \t app.showMessage('Connected! Touch buttons to turn LED on/off.'); 
 
\t \t \t }, 
 
\t \t \t function(errorCode) 
 
\t \t \t { 
 
\t \t \t \t app.showMessage('Connect error: ' + errorCode + '.'); 
 
\t \t \t }); 
 
\t }; 
 
\t document.addEventListener(
 
\t \t 'deviceready', 
 
\t \t function() { evothings.scriptsLoaded(app.onDeviceReady) }, 
 
\t \t false); 
 
\t </script>

그것은 글로벌 변수에서, 그 다음 Arduino에 보낼 계획입니다. 그러나 msg는 변수에 저장되지 않습니다. 사실, AJAX 게시물의 성공 코드 블록을 디버깅하는 경고 함수를 사용하더라도 아무 것도 얻지 못합니다. 서버 측에서 응답을 받고 다음과 같이 OK 200 코드를 반환합니다. Heroku Logs from server side

어떤 이유로 서버에서 오는 msg는 app.msg 변수에 저장되지 않습니다. 이 설정이 작동하지 않는 이유에 대한 도움은 크게 감사하겠습니다.

답변

0

뷰어에서 https/http 보안 문제가 발생했을 수 있습니다. 개발중인 앱이 뷰어 내부의 코드보기 웹 뷰에서 https를 통해로드되기 때문에 https가 아닌 리소스를 요청할 수 없습니다. https://evothings.com/evothings-secured-now-serving-over-https/

희망하는 데 도움이 :

그러나, 여기에 설명 된 당신을 통해 펀치하자 어쨌든 HTTP 요청을 수행 뷰어에서 번들 플러그인은있다!

관련 문제