NodeMCU custom built firmware http.get fails with a code of -1 - lua

I recently got a NodeMCU toolchain working with https://github.com/slaff/esp8266.dev.box, but when I try to do a http.get, it immediately fails with the code -1, even though with the firmware from https://nodemcu-build.com/ it works fine. The heap space is approximately the same for both firmwares, and with both the custom built firmware and the cloud built one it works with a different URL.
The URL it is not working with is private, but overall it links to a google sheet and gets a CSV file. It still fails even when the CSV file is a single '0', and succeeds with a URL that links to a .txt file with around 20 characters.
Example url it doesn't work on:
https://docs.google.com/spreadsheets/d//pub?output=csv&gid=0&single=true&gridlines=false&chrome=false
My user_modules.h from when I build:
http://pastebin.com/1LbxmS2B
My user_config.h:
http://pastebin.com/qBixhqyC
My Lua code (runs after I've successfully connected to wifi):
http.get(url, nil, function(code, data)
print(code, data)
end)
Is there something that I am doing wrong when I build the firmware? Any help is greatly appreciated.

Your user_config.h doesn't enable SSL-support (line 67), it's off by default.

Related

cordova-plugin-file: files not accessible after app update (iOS)

I am experiencing a funny problem: I am developing an ionic app, using cordova-plugin-file to store images. The resulting paths (URIs in form file:///...) are stored in a SQLite DB along with more information. When I install the app and use it, all works perfect. But if I update (or reinstall) the app, the old images are not found anymore, while newly added images work perfect.
I first suspected that the image files were being deleted on update, but I checked the content of the directory and the files are still there. (FYI: I am using file.dataDirectory/scans/ to place my files).
Then I thought that maybe I could go around the problem loading into img src a base64 blob loaded with cordova.file.readAsUrl(), but cordova.file does not find the file as well (I insist, the files are there, I checked with XCode).
So I checked further with cordova.file and it only finds files that are added after last app install, but the older files are still present in the directory.
Here my code:
private getImgSrcFromDocument(doc: Document): any {
const uri = doc.fileName;
const src = this.webView.convertFileSrc(uri);
const sanitized = this.sanitizer.bypassSecurityTrustUrl(src);
console.log({uri, src, sanitized});
return sanitized;
}
<img class="document_thumbnail" [src]="getImgSrcFromDocument(doc)">
I have already checked this, but is not my case.
By the way, the same code works perfect on Android.
Any idea what could be the problem?
Thanks in advance!
I found the reason why and the solution (very obvious when you know the problem):
Reason
On every new install, iOS renames the data directory for the app. The directory path has this form:
file:///var/mobile/Containers/Data/Application/ABC0000-1234-99DD-00FA-E835FEA/Library/NoCloud/
The hash in the middle is renewed on every install, so the stored full paths in DB are not valid anymore.
Solution
If you still can do it (no deploy yet, no real users), store only the relative path and complete it every time with this.file.dataDirectory (or wherever you wanted to store your files).
If you already have real users and want your update to 'find the files', just ignore the first part of the stored path and build it like before:
const ValidUri = this.file.dataDirectory + // The injected cordova-plugin-file
'relativeSubDirectories/' + // If you store your files in some subdirectory
this.document.storedFullPath.substr( // Take from fullPath only the filename
this.document.storedFullPath.lastIndexOf('/') + 1
);
Where storedFullPath is the string file:///var/mobile/....
After that, you still have to do the webView conversion and the sanitizing, like in the question above.
Hope this helps someone.

Laravel 5 Intervention make base64 blob from POST API unable to init from given binary data

I'm sorry, it may be a couple issues and not sure how to phrase the question properly. OK, tried a number of solutions over 2 days to no avail...thank you in advance for your help!
A photo is sent from an iPad app using POST API in the format of base64 (no meta data, just the base64 blob). I'm trying to simply decode and save locally.
I'm testing using Postman:
...com/api/register?first_name=John&photo=/9j/4AAQSkZJRgABAQAAAQAB...[base 64 image of about 400kb]
In Laravel, I am using Intervention
$jpg_url = "image-".time().".jpg";
$path = "/public/".$jpg_url;
$base=base64_decode($customer['photo']);
Image::make($base)->save($path);
and getting an "Unable to init from given binary data" error.
Here's what I don't quite understand and would appreciate a TIL5 explanation:
- When I save the POST from iPad directly into the DB with the following:
$photo = $customer->photo = $customer['photo']
The blob in mysql looks good, I can manually copy and paste it to a web decoder fine.
However, when I use postman, $photo has "+" in the base64 changed into spaces and the image doesn't render
Is this a datatype issue? I'm receiving a long blob that is trying to be converted into string? What is the best practice of receiving images from a mobile app?

Use local json file with Cordova/ionic/Angular. Works in browser, but not on device?

I'm attempting to use a JSON object living in a data.json file to be the dataset for a quick prototype I'm working on. This lives in a my_project/www/data/ directory. I have an Angular service that goes and grabs the data within this file using $http, does some stuff to it, and then it's used throughout my app.
I'm using Cordova and Ionic. When using ionic serve on my computer, everything looks perfect in the browser. However, when using ionic view (http://view.ionic.io/) and opening the app on my iPad, I see a:
{"data":null,"status":0,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"../data/items.json","headers":{"Accept":"application/json,test/plain,*/*}},"statusText":""}
for a response. I would think that if it were a relative URL issue, that it would also not work in the browser, but that is not the case.
Here's what I'm doing:
config.xml has this line:
<access origin="*" subdomains="true"/>
My service that preforms the simple request is doing:
return $http.get("../data/data.json").then(function (response) {
return response.data;
});
And finally, in my controller, I ask for the service to preform the request:
myService.goGetData().then(onComplete, onError);
In my browser, onComplete() is invoked and on the iPad, onError() is invoked.
Any guidance?
On your local developer machine you're actually running a webserver when you run ionic serve. So a path like ../../data.json will work because it is totally valid in the context of the webserver that has complete filesystem access.
If, however, you try to do the same thing on your device, you're probably going to run into an issue because the device has security policies in place that don't allow ajax to traverse up outside of the root. It is not a dynamic webserver so it can't load files up the tree. Instead you'd use something like the cordova file plugin to grab the file contents from the filesystem. If you prefer, you can use ngCordova to make interacting with the plugin a bit less painful.
I am 99% sure this is what is happening but you can test my theory by pointing your $http call to some dummy .json data hosted on a publicly available server to see if it works. Here is some dummy json data.
Just gonna leave this here because I had the same problem as the original question author. Simply removing any starting slashes from the json file path in the $http.get function solved this problem for me, now loading the json data works both in the browser emulator and on my android device. The root of the $http call url seems to always be the index.html folder no matter where your controller or service is located. So use a path relative from that folder and it should work. like $http.get("data/data.json")
So this is an example json file. save it as data.json
[
{
"Name" : "Sabba",
"City" : "London",
"Country" : "UK"
},
{
"Name" : "Tom",
"City" : "NY",
"Country" : "USA"
}
]
And this this is what a example controller looks like
var app = angular.module('myApp', ['ionic']);
app.controller('ExhibitionTabCtrl', ['$scope', '$http', function($scope,$http) {
$http.get("your/path/from/index/data.json")
.success(function (response)
{
$scope.names = response;
});
}]);
Then in your template make sure you are you are referencing your controller.
<ion-content class="padding" ng-controller="ExhibitionTabCtrl">
You should then be able to use the a expression to get the data
{{ names }}
Hope this helps :)
I was also looking for this and found this question, since there is no real answer to the problem I kept my search on the Internet and found this answer at the Ionic Forum from ozexpert:
var url = "";
if(ionic.Platform.isAndroid()){
url = "/android_asset/www/";
}
I've used it to load a 3D model and its textures.
update: ionic 2 beta (version date 10 Aug 2016)
You must add prefix to local url like this: prefix + 'your/local/resource'.
prefix by platform:
ios = '../www/'
android = '../www/'
browser = ''
we can create an urlResolver provider to do this job.
notice: only change url in *.ts code to access local resource, don's do this with remote url or in html code.
Have fun and good luck with beta version.
An Starter Ioner
It is possible to access local resources using $http.get.
If the json file is located in www/js/data.json. You can access using
js/data.json
Do not use ../js/data.json. Using that only works in the local browser. Use js/data.json will work on both local browser and iOS device for Cordova.

open office crashes after some time giving garbled font in converted PDF

We are converting word to pdf using the openoffice(3.4.1 version) in java with JODConverter.
below is the code used.
OpenOfficeConnection connection =
new SocketOpenOfficeConnection(2100);
try
{
connection.connect();
DocumentConverter converter =
new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
connection.disconnect();
return "Sucess " + DestinationPath + DestinationFileName;
}
catch (Exception localException1) {
}
The problem is that after random no of days the converted PDF contains the garbled fonts.
like # # ! $ $ " % &
The only solution we have so far is to restart the server. System guys are saying the the problem is with Open Office.
We are using open office to convert the document since it converts the doc files exactly including all the formatting and table structure.
what could be the solution to this.
So OpenOffice can be a little temperamental when running on a server, especially as it isn't multi-threaded and you end up having to run a pool of OpenOffice processes - see How can I use OpenOffice in server mode as a multithreaded service?.
Added to that often the rendering is off when converting to PDF - see https://forum.openoffice.org/en/forum/viewtopic.php?f=7&t=68865 which is why you may want to consider using a conversion service to automate the conversion tasks for you ?
For complete transparency I work for Zamzar (an online file conversion service), we have recently released a developer API - https://developers.zamzar.com/ that allows you to convert between a multitude of file types, specifically applicable to you here in that we support both doc and docx to pdf with little or not loss in the way the PDF is rendered. It maybe worth a look to see if this is a better alternative to trying to run your own solution through OpenOffice on a server.

PhoneGap's navigator.fileMgr always undefined

I'm building iOS app with PhoneGap, need to write and read text file to the device.
I followed the steps found here: http://docs.phonegap.com/en/2.0.0/guide_getting-started_ios_index.md.html#Getting%20Started%20with%20iOS
Everything works fine, except I cannot use any of the API (I tried file and notification). I am calling:
alert(navigator.fileMgr) but it's always undefined.
I am calling that in the deviceready callback function.
I think I missed some important steps, could anyone have experience in this give me some link/guide/help?
Thanks in advance!
I'm not sure where you are getting your info but navigator.fileMgr does not exist anymore and hasn't for a long time. We've implemented the W3C File API:
http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#File
To get the root path of the file system you would do:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {
console.log("File system root = " + fileSys.root.fullPath);
}, function() {
console.log("Could not get file system");
});
Examples of how to read/write files are also available on the docs site.

Resources