jsiConsolePrint(); usage example? #4728
Replies: 1 comment
-
Posted at 2015-05-27 by Stevie To my knowledge it will only allow a string. Consider using jsiConsolePrintf which is pretty much like the usual printf. Does that help? Posted at 2015-05-28 by d0773d Im AFK at the moment so I will get back to you later today with the results. Posted at 2015-05-28 by d0773d @stevie i'm still getting the same issue, but now I am receiving Full code:
Attachments: Posted at 2015-05-28 by @gfwilliams
In Espruino I added some special format characters for JS variables, see this So you want to do something like:
That'll output a comma-separated list of numbers. If you want to output just the actual character you can use
If you did want to use it, you'd have to do:
(Of course you could also use ... anyway, it's just one of the many reasons that programming embedded devices in C is painful :) Posted at 2015-05-28 by d0773d
output:
The array of hex should be the equivalence of ascii: {"PH":["Result",5.5],"EC":["Result",700],"ResTemp":["Result",137.5]} However I am still not receiving the correct ascii. Posted at 2015-05-28 by @gfwilliams
So it appears to be printing numbers reliably - they're just not the right ones. Is that code really exactly what you have? You're not doing something to the array inbetween? What happens if you change As I said above, trying to print as a string - with Posted at 2015-05-28 by d0773d casting an int doesn't change anything. I'm still receiving the same output This is my complete code of jswrap_crypto.c:
Posted at 2015-05-28 by Stevie Are you sure that above is the correct source code? The one you actually tested? It seems to me that the int and hex output are the same values. So let's concentrate on the hex one, only. In that case it seems as if what you are outputting is
Does that ring a bell? Are you somewhere modifying the in array? Otherwise it would be an extremely odd bug of jsiConsolePrintf. One which adds an increasing number for each call. And which resets itself which you switch from %d to %x... Unlikely... Posted at 2015-05-28 by d0773d @stevie I edited my source code so many times while trying to figure all this out. I attached the complete source code of the library I also thought the same about the +1. I don't think I am editing the array. All I am doing is iterating through the array to output whats in the array(usually hex to the ascii equivalent) and the first character is { which is correct. Attachments: Posted at 2015-05-28 by @gfwilliams Ahh, ok, so you do call Maybe just simplify to this:
and make sure the correct data is output? My guess is AES128_CBC_encrypt_buffer might be fiddling with the data inside Posted at 2015-05-28 by d0773d @gfwilliams yup, AES128_CBC_Encrypt_Buffer is fiddling with the data inside of in, errr. And I wonder why that is.....
And I don't have the slightest idea why AES_128_CBC_encrypt_Buffer is doing that..... Posted at 2015-05-28 by Stevie
Because in line 512 XorWithIv modifies it? Maybe that should be
Posted at 2015-05-28 by @gfwilliams I don't know what it says in the docs, but it could be that in order to save memory they're fiddling with the input data intentionally? I guess it's not a problem, it just screws up your debugging :) Posted at 2015-05-28 by d0773d https://github.com/kokke/tiny-AES128-C is the library I am using. The test.c compiles correctly. I am just trying to implement my own "stuff" to encrypt and decrypt as a test instead of using the test data. I uploaded the test.c file Eventually, I would like to create a AESCBC library into Espruino, but since i'm new to programming in general I seem to be hitting a brick wall :/ Maybe one day I will get this to work. Or maybe someone who is ambitious enough can get this to work ;-) Attachments: Posted at 2015-05-28 by Stevie Well, in any case, the input buffer is in fact modified so jsiConsolePrintf works fine. And looking at the source code of the AES code, I believe modifying the input buffer is not necessary, and as such probably unintended. I would bet on that. But technically it is not a bug unless there is a promise that it does not modify the input buffer. Posted at 2015-05-30 by d0773d @gfwilliams @stevie I finally got this to work :-) I needed to work with the buffer[] array. Now, all I need to figure out is create a random IV and MAC the encrypted data. How do I work with function arguments? I would like to pass in the Key, IV, hashkey and what every data needs to be encrypted. I want to execute Crypto.aescbc(key, iv, hashKey, data); Posted at 2015-05-30 by d0773d ... Posted at 2015-05-30 by @allObjects
@d0773d, I'd like to commend you for the perseverance you demonstrate. I guess I have to for a class to you despite having a past of programming... Posted at 2015-05-30 by @gfwilliams Best bet is to have a look at Actually unpacking something like an array into a C array is a bit more painful though - you'd probably want to see something like this as an example
I haven't actually tested that, but it should work... Posted at 2015-05-31 by d0773d @allObjects Thanks. I couldn't sleep last night until I figured all this out. Plus I am going camping for a week and a half. Which will give me a decent break from my project; allowing me to approach my project again with a clearer mind. @gfwilliams I'm all coded out :/ I have yet to try your example, but when I do, I'm sure I will respond back with more questions ;-) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-05-27 by d0773d
Let's say, for example, I have the following code:
And I want to output that array using:
'''jsiConsolePrint();'''
Does jsIConsolePrint() only allow a string input? Do I need to for each through the array then store each segment of the array to a string?
The reason why I ask is. I tried to use a for each to loop through the array and output each segment of the array to the WebIDE and I expected to see the ascii representation of the hex value. However, I received what looked like all %.
The ascii representation should be:
kÁ¾â.@��é=~�s��®-�W�¬��·o¬E¯�Q0È�F£\ä�åûÁ��
Rïö�$EßO��+A{æl7�
I even tried placing the hex representation of the alphabet into the array; however, I still received all % as the output.
Eventually, my real world code will receive an encrypted JSON string and I would like to output the unencrypted JSON string to the WebIDE console. I have AES128-CBC encryption and decryption working (so I think, I don't want to jinx myself). I'm just having trouble outputting the text to the console.
Beta Was this translation helpful? Give feedback.
All reactions