I am not able to write / access files in SPIFFS in ESP8266 - esp8266

I am trying to store text file into SPIFFS memory. I get an error whenever I try to format or to write file into SPIFFS.
Here is the code to format the SPIFFS.
#include<FS.h>
void setup() {
Serial.begin(9600);
SPIFFS.begin();
delay(1000);
Serial.println("Beggining format");
if(SPIFFS.format()){
Serial.println("Format complete");
}
else{
Serial.println("unable to Format");
}
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
I did search online in other forums regarding this error. I came accross this github discussion regarding the error. https://github.com/esp8266/Arduino/issues/4061 I did run the code suggested in this link to obtain the device ID.
Firmware: Chip Id: 000E01E5
Core version: 2_7_0
SDK version:2.2.2-dev(38a443e)
Boot version: 5
Boot mode: 1
Flash chip information: Flash chip Id: 00146085 (for example: Id=001640E0 Manuf=E0, Device=4016 (swap bytes))
Sketch thinks Flash RAM is size: 1.00 MB
Actual size based on chip Id: 1.00 MB Flash
frequency: 40.00 MHz
Flash write mode: DIO
File system (SPIFFS):
Total KB: 4176892.00 KB
Used KB: 4176892.00 KB Block size: 8192
Page size: 256
Maximum open files: 5 Maximum path length: 32
SPIFFS directory {/} :
CPU frequency: 80 MHz
###############file open failed
In the output I see that:
File system (SPIFFS):
Total KB: 4176892.00 KB
Used KB: 4176892.00 KB
I don't understand this. Can someone help me understand this? So that I can upload file to SPIFFS?

Related

Reading physical memory with /dev/mem

I am trying to figure out how to directly read any location in physical memory on a Power9 processor using /dev/mem. The following is the code that I have used to that end.
FILE* fp;
int _fdmem;
int *map = NULL;
const char memDevice[] = "/dev/mem";
_fdmem = open( "/dev/mem", O_RDWR | O_SYNC );
if (_fdmem < 0){
printf("Failed to open the /dev/mem !\n");
return 0;
}
else{
printf("open /dev/mem successfully !\n");
}
map= (int *)(mmap(NULL,1,PROT_READ|PROT_WRITE,MAP_PRIVATE,_fdmem,0));
fp=fopen("./memm2out.txt","w");
for (int i=0; i<131073;i++)
{
fprintf(fp, "%x",*(map+i));
}
When I run the code I get the following output.
open /dev/mem successfully !
Segmentation fault
Using GDB, this is where the segfault occurs
Program received signal SIGSEGV, Segmentation fault.
0x0000000100000a2c in main () at memmapper2.c:34
34 fprintf(fp, "%x",*(map+i));
When I use 131072 as the value for i there is no segfault, which makes me believe there is some kind of boundary to reading after 64 kB. The file is run with root permissions. The processor I'm using is running Linux kernel version 4.18. What may be restricting my access?
Edit: When the second mmap parameter is set to any value greater than 65536, mmap fails to open and gives the error message ": OPERATION NOT PERMITTED". Now, it's my understanding that what's happening here is that mmap maps the file pointer for /dev/mem to a specific location in virtual memory from which you can invoke the functionality of /dev/mem to read physical memory. Am I mistaken in this understanding?

WP8.1 HttpClient Stream got only 65536 bytes data

I am trying write a real-time flv stream demuxer on windows-runtime, for win8.1 and wp8.1's MediaElement.
I've already finish the demux code, flv files can be correctly demuxed into h264 and aac tag-datas.
When I was trying to play network files and streams, I got a very strange network problem:
The same code,
run under win8.1, all good, whatever files or network streams (proves demux code is ok);
run under wp8.1 (real phone or emulator), files are good, network streams are bad - no matter how I read bytes from HttpClient Stream, the target server only gives me 65536 bytes data, and then the connection is choked, no any response and error, and even no timeout, it's just choking the thread.
Code for opening the stream:
var uri = new Uri("http://hdl.xxx.com/live/yyyy")
//uri is dymatic
var client = new HttpClient();
var stream = await client.GetStreamAsync(uri);
openStream(stream)
Code for reading the data:
public static byte[] ReadBlocks(this Stream stream, int count)
{
byte[] buffer = new byte[count];
int offset = 0;
int length;
while (offset < count)
{
//a loop statement to guarantee I can get *count* bytes
Debug.WriteLine("read " + (count - offset));
//a debug message show how many bytes do I need
length = stream.Read(buffer, offset, count - offset);
if (length == 0)
{
throw new EndOfStreamException();
}
Debug.WriteLine("got " + length);
//a debug message show how many bytes I got
offset += length;
}
return buffer;
}
For example, when I need to rea 1024 bytes from the flv stream, I run stream.ReadBlocks(1024) under wp8.1, the debug tells me like:
read 1024
got 768
read 256
and then nothing happend any more. I wrote an extra counter, the counter shows once server send a total of 65536 bytes, next Read method of stream will always be choked.
I'm sure the uri is available. I can download some stream data as a flv file by using pc web browser, and this downloaded flv file can be played under wp8.1 as well.
It looks like this problem only happens under wp8.1, android and ios are not affected.
So is it my code's problem or actually the server is not set up properly?
From last three weeks, I've tried every http method that can open a stream, but still got choked at 65536 bytes.
Could someone help me, please?
I just solved the same problem - do NOT use System.Net.HttpClient, but Windows.Web.Http.HttpClient
The one in System.Net uses header Connection: Close by default, which causes the stream to close, reading only 65 kB. It also contains a bug which prevents you to override the header to Keep-Alive (it throws some nonesense exception)

Cordova requestFileSystem: wrong calculated free disk space on iOS?

I have some issue on iOS trying to allocate more than 140 Mbytes with File plugin 1.0.1.
I have 10 giga free on device but a QUOTA_EXCEEDED_ERR was thrown
Here is the code:
var requestBytes = 150 * 1024 * 1024;
window.requestFileSystem(LocalFileSystem.PERSISTENT, requestBytes, function(fs) {
// success callback
}, function (e) {
// error callback
});
I see that the free space calulated in requestFileSystem method of CDVFile.m results always about 144 Mbytes.
Any idea? How is the free space calculated? Are there some limits for iOS apps?
Note that on android I haven't any issues.
It was a bug.
I opened an issue that is already merged on master branch
https://issues.apache.org/jira/browse/CB-6872

Limitation of IP_ADD_SOURCE_MEMBERSHIP on a Windows 2008 Server

I want to build an application which wants to recive data from several multicast groups (up to 1.000!) Is this possible with the setsockopt function (IP_ADD_SOURCE_MEMBERSHIP)? Or is there a system limit?
Is there another way to do it? Or do I have to use more than one socket?
Thanks!
I've found something on this Microsoft site: INFO: Header and Library Requirement When Set/Get Socket Options at the IPPROTO_IP Level
There exists a define
#define IP_MAX_MEMBERSHIPS 20 /* per socket; must fit in one mbuf */
The mbuf struct has a maximum size of 108 bytes.
TCP/IP Illustrated: Vol. 2: The Implementation

Azure guaranteed memory

We're currently preparing our Azure role (standard Web Role) for an expected massive load, and we need to know how much memory the current setup consumes. To accomplish this, we're using load tests while measuring the consumed memory with GC.GetTotalMemory.
The page http://technet.microsoft.com/en-us/cloud/gg663909.aspx lists the Compute Instance Guaranteed Memory for each instance size (for example, 0.768 GB for the Extra-Small Instance and 3.5 GB for the Medium Instance).
Are the values of GC.GetTotalMemory comparable to the values in these list? In other words, if GC.GetTotalMemory is staying significantly below the listed limit, can we be sure that there won't be any sudden perfomance loss due to memory swapping?
If we hit the limit, is our assumption correct that there will be some memory swapping (writing memory content to the virtual harddisk), or will there be more severe implications like repeated App Pool recycling?
(the last question comes up because most shared hosters will recycle your App Pool if you hit some memory limit, but frankly we don't expect anything like this from Windows Azure)
This method will only give you the currently allocated bytes by your process. The 0.768 GB includes the memory availble to the operating system, and there can be virtual memory as well.
system.gc.gettotalmemory
To get the total system memory you can use:
Add a Reference to System.Management.
private static void DisplayTotalRam()
{
string Query = "SELECT MaxCapacity FROM Win32_PhysicalMemoryArray";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(Query);
foreach (ManagementObject WniPART in searcher.Get())
{
UInt32 SizeinKB = Convert.ToUInt32(WniPART.Properties["MaxCapacity"].Value);
UInt32 SizeinMB = SizeinKB / 1024;
UInt32 SizeinGB = SizeinMB / 1024;
Console.WriteLine("Size in KB: {0}, Size in MB: {1}, Size in GB: {2}", SizeinKB, SizeinMB, SizeinGB);
}
}
Source for code
To answer your last question, Windows Azure will stay out of the way, and paging will happen like on any Windows server.
Whether IIS recycles your app pool probably depends on your IIS settings, but those are under your control. (You can, for example, run appcmd in a startup task if you want to change a default.)

Resources